WAVEWATCH III
beta 0.0.1
w3meminfo.F90
Go to the documentation of this file.
1
module
mallocinfo_m
2
!/
3
!/ +-----------------------------------+
4
!/ | WAVEWATCH III NOAA/NCEP |
5
!/ | |
6
!/ | Aron Roland (BGS IT&E GmbH) |
7
!/ | Mathieu Dutour-Sikiric (IRB) |
8
!/ | |
9
!/ | FORTRAN 90 |
10
!/ | Last update : 01-June-2018 |
11
!/ +-----------------------------------+
12
!/
13
!/ 01-June-2018 : Origination. ( version 6.04 )
14
!/
15
! 1. Purpose : Init pdlib part
16
! 2. Method :
17
! 3. Parameters :
18
!
19
! Parameter list
20
! ----------------------------------------------------------------
21
! ----------------------------------------------------------------
22
!
23
! 4. Subroutines used :
24
!
25
! Name Type Module Description
26
! ----------------------------------------------------------------
27
! STRACE Subr. W3SERVMD Subroutine tracing.
28
! ----------------------------------------------------------------
29
!
30
! 5. Called by :
31
!
32
! Name Type Module Description
33
! ----------------------------------------------------------------
34
! ----------------------------------------------------------------
35
!
36
! 6. Error messages :
37
! 7. Remarks
38
! 8. Structure :
39
! 9. Switches :
40
!
41
! !/S Enable subroutine tracing.
42
!
43
! 10. Source code :
44
!
45
!/ ------------------------------------------------------------------- /
46
!
47
use
:: iso_c_binding
48
implicit none
49
!/
50
!/ ------------------------------------------------------------------- /
51
!/ Parameter list
52
!/
53
!/ ------------------------------------------------------------------- /
54
!/ Local PARAMETERs
55
!/
56
!/
57
!/ ------------------------------------------------------------------- /
58
!/
60
type
,
bind(c)
:: MallInfo_t
62
integer(c_int)
:: arena
64
integer(c_int)
:: ordblks
66
integer(c_int)
:: smblks
68
integer(c_int)
:: hblks
70
integer(c_int)
:: hblkhd
72
integer(c_int)
:: usmblks
74
integer(c_int)
:: fsmblks
76
integer(c_int)
:: uordblks
78
integer(c_int)
:: fordblks
80
integer(c_int)
:: keepcost
81
end type
mallinfo_t
82
83
interface
84
function
mallinfo
()
bind(c, name="mallinfo")
result
(data)
85
use
:: iso_c_binding
86
implicit none
87
88
type
,
bind(c)
::
mallinfo_t
89
integer(c_int)
:: arena
90
integer(c_int)
:: ordblks
91
integer(c_int)
:: smblks
92
integer(c_int)
:: hblks
93
integer(c_int)
:: hblkhd
94
integer(c_int)
:: usmblks
95
integer(c_int)
:: fsmblks
96
integer(c_int)
:: uordblks
97
integer(c_int)
:: fordblks
98
integer(c_int)
:: keepcost
99
end type
mallinfo_t
100
type
(
mallinfo_t
) :: data
101
end function
mallinfo
102
end interface
103
104
contains
105
106
subroutine
getmallocinfo
(malinfo)
107
!/
108
!/ +-----------------------------------+
109
!/ | WAVEWATCH III NOAA/NCEP |
110
!/ | |
111
!/ | Aron Roland (BGS IT&E GmbH) |
112
!/ | THomas Huxhorn (BGS IT&E GmbH |
113
!/ | |
114
!/ | FORTRAN 90 |
115
!/ | Last update : 01-June-2018 |
116
!/ +-----------------------------------+
117
!/
118
!/ 01-June-2018 : Origination. ( version 6.04 )
119
!/
120
! 1. Purpose : Init pdlib part
121
! 2. Method :
122
! 3. Parameters :
123
!
124
! Parameter list
125
! ----------------------------------------------------------------
126
! ----------------------------------------------------------------
127
!
128
! 4. Subroutines used :
129
!
130
! Name Type Module Description
131
! ----------------------------------------------------------------
132
! STRACE Subr. W3SERVMD Subroutine tracing.
133
! ----------------------------------------------------------------
134
!
135
! 5. Called by :
136
!
137
! Name Type Module Description
138
! ----------------------------------------------------------------
139
! ----------------------------------------------------------------
140
!
141
! 6. Error messages :
142
! 7. Remarks
143
! 8. Structure :
144
! 9. Switches :
145
!
146
! !/S Enable subroutine tracing.
147
!
148
! 10. Source code :
149
!
150
!/ ------------------------------------------------------------------- /
151
#ifdef W3_S
152
USE
w3servmd
,
ONLY
:
strace
153
#endif
154
!
155
implicit none
156
!/
157
!/ ------------------------------------------------------------------- /
158
!/ Parameter list
159
!/
160
!/ ------------------------------------------------------------------- /
161
!/ Local PARAMETERs
162
!/
163
#ifdef W3_S
164
INTEGER
,
SAVE
:: IENT = 0
165
#endif
166
!/
167
!/ ------------------------------------------------------------------- /
168
!/
169
#ifdef W3_S
170
CALL
strace
(ient,
'W3XXXX'
)
171
#endif
172
type
(
mallinfo_t
),
intent(out)
:: malinfo
173
malinfo =
mallinfo
()
174
end subroutine
getmallocinfo
175
176
subroutine
printmallinfo
(ihdnl,malinfo)
177
!/
178
!/ +-----------------------------------+
179
!/ | WAVEWATCH III NOAA/NCEP |
180
!/ | |
181
!/ | Aron Roland (BGS IT&E GmbH) |
182
!/ | Mathieu Dutour-Sikiric (IRB) |
183
!/ | |
184
!/ | FORTRAN 90 |
185
!/ | Last update : 01-June-2018 |
186
!/ +-----------------------------------+
187
!/
188
!/ 01-June-2018 : Origination. ( version 6.04 )
189
!/
190
! 1. Purpose : Init pdlib part
191
! 2. Method :
192
! 3. Parameters :
193
!
194
! Parameter list
195
! ----------------------------------------------------------------
196
! ----------------------------------------------------------------
197
!
198
! 4. Subroutines used :
199
!
200
! Name Type Module Description
201
! ----------------------------------------------------------------
202
! STRACE Subr. W3SERVMD Subroutine tracing.
203
! ----------------------------------------------------------------
204
!
205
! 5. Called by :
206
!
207
! Name Type Module Description
208
! ----------------------------------------------------------------
209
! ----------------------------------------------------------------
210
!
211
! 6. Error messages :
212
! 7. Remarks
213
! 8. Structure :
214
! 9. Switches :
215
!
216
! !/S Enable subroutine tracing.
217
!
218
! 10. Source code :
219
!
220
!/ ------------------------------------------------------------------- /
221
#ifdef W3_S
222
USE
w3servmd
,
ONLY
:
strace
223
#endif
224
!
225
!/
226
!/ ------------------------------------------------------------------- /
227
!/ Parameter list
228
!/
229
!/ ------------------------------------------------------------------- /
230
!/ Local PARAMETERs
231
!/
232
#ifdef W3_S
233
INTEGER
,
SAVE
:: IENT = 0
234
#endif
235
!/
236
!/ ------------------------------------------------------------------- /
237
!/
238
#ifdef W3_S
239
CALL
strace
(ient,
'W3XXXX'
)
240
#endif
241
real
:: ib2m
242
integer(8)
:: vmsize, vmRSS
243
integer
,
intent(in)
:: ihdnl
244
type
(
mallinfo_t
),
intent(in)
:: malinfo
245
246
247
if
(ihdnl .lt. 1) stop
'ihndl not set'
248
ib2m=1./real(1024**2)
249
vmsize =
getvmsize
()
250
vmrss =
getvmrss
()
251
!write(*,'(A72,2F20.10)') "Total size of memory allocated with sbrk by malloc in mbyte. ", malinfo%arena*ib2m
252
!write(*,'(A72,2F20.10)') "Total size of memory allocated with mmap, in mbytes. ", malinfo%hblkhd*ib2m
253
!write(*,'(A72,2F20.10)') "Total size of memory occupied by chunks handed out by malloc.", malinfo%uordblks*ib2m
254
!write(*,'(A72,I10)') "Total number of chunks allocated with mmap. ", malinfo%hblks
255
!write(*,'(A72,I10)') "Number of chunks not in use. ", malinfo%ordblks
256
!write(*,'(A72,2F20.10)') "Total size of memory occupied by free (not in use) chunks. ", malinfo%fordblks*ib2m
257
!write(*,'(A72,2F20.10)') "Size of the top-most releasable chunk borders end of the heap", malinfo%keepcost*ib2m
258
write
(ihdnl,
'(A72,2F20.10)'
)
"VM size in proc "
, vmsize/1024.
259
write
(ihdnl,
'(A72,2F20.10)'
)
"RSS size in prof "
, vmrss/1024.
260
call
flush(ihdnl)
261
end subroutine
printmallinfo
262
263
!VmPeak: Peak virtual memory usage
264
!VmSize: Current virtual memory usage
265
!VmLck: Current mlocked memory
266
!VmHWM: Peak resident set size
267
!VmRSS: Resident set size
268
!VmData: Size of "data" segment
269
!VmStk: Size of stack
270
!VmExe: Size of "text" segment
271
!VmLib: Shared library usage
272
!VmPTE: Pagetable entries size
273
!VmSwap: Swap space used
274
275
function
getvmsize
()
result
(vmsize)
276
!/
277
!/ +-----------------------------------+
278
!/ | WAVEWATCH III NOAA/NCEP |
279
!/ | |
280
!/ | Aron Roland (BGS IT&E GmbH) |
281
!/ | Mathieu Dutour-Sikiric (IRB) |
282
!/ | |
283
!/ | FORTRAN 90 |
284
!/ | Last update : 01-June-2018 |
285
!/ +-----------------------------------+
286
!/
287
!/ 01-June-2018 : Origination. ( version 6.04 )
288
!/
289
! 1. Purpose : Init pdlib part
290
! 2. Method :
291
! 3. Parameters :
292
!
293
! Parameter list
294
! ----------------------------------------------------------------
295
! ----------------------------------------------------------------
296
!
297
! 4. Subroutines used :
298
!
299
! Name Type Module Description
300
! ----------------------------------------------------------------
301
! STRACE Subr. W3SERVMD Subroutine tracing.
302
! ----------------------------------------------------------------
303
!
304
! 5. Called by :
305
!
306
! Name Type Module Description
307
! ----------------------------------------------------------------
308
! ----------------------------------------------------------------
309
!
310
! 6. Error messages :
311
! 7. Remarks
312
! 8. Structure :
313
! 9. Switches :
314
!
315
! !/S Enable subroutine tracing.
316
!
317
! 10. Source code :
318
!
319
!/ ------------------------------------------------------------------- /
320
#ifdef W3_S
321
USE
w3servmd
,
ONLY
:
strace
322
#endif
323
!
324
!/
325
!/ ------------------------------------------------------------------- /
326
!/ Parameter list
327
!/
328
!/ ------------------------------------------------------------------- /
329
!/ Local PARAMETERs
330
!/
331
#ifdef W3_S
332
INTEGER
,
SAVE
:: ient = 0
333
#endif
334
!/
335
!/ ------------------------------------------------------------------- /
336
!/
337
#ifdef W3_S
338
CALL
strace
(ient,
'W3XXXX'
)
339
#endif
340
integer(8)
:: vmsize
341
character(len=80)
:: stat_key, stat_value
342
!
343
vmsize = 0
344
open
(unit=1000,
file
=
"/proc/self/status"
, status=
'old'
, err=99)
345
do
while
(.true.)
346
read
(unit=1000, fmt=*, err=88) stat_key, stat_value
347
if
(stat_key ==
'VmSize:'
)
then
348
read
(stat_value, *) vmsize
349
exit
350
end if
351
end do
352
88
close
(unit=1000)
353
if
(vmsize == 0)
goto
99
354
return
355
!
356
99 print *,
'ERROR: procfs not mounted or not compatible'
357
vmsize = -1
358
end function
getvmsize
359
360
function
getvmrss
()
result
(vmRSS)
361
!/
362
!/ +-----------------------------------+
363
!/ | WAVEWATCH III NOAA/NCEP |
364
!/ | |
365
!/ | Aron Roland (BGS IT&E GmbH) |
366
!/ | Mathieu Dutour-Sikiric (IRB) |
367
!/ | |
368
!/ | FORTRAN 90 |
369
!/ | Last update : 01-June-2018 |
370
!/ +-----------------------------------+
371
!/
372
!/ 01-June-2018 : Origination. ( version 6.04 )
373
!/
374
! 1. Purpose : Init pdlib part
375
! 2. Method :
376
! 3. Parameters :
377
!
378
! Parameter list
379
! ----------------------------------------------------------------
380
! ----------------------------------------------------------------
381
!
382
! 4. Subroutines used :
383
!
384
! Name Type Module Description
385
! ----------------------------------------------------------------
386
! STRACE Subr. W3SERVMD Subroutine tracing.
387
! ----------------------------------------------------------------
388
!
389
! 5. Called by :
390
!
391
! Name Type Module Description
392
! ----------------------------------------------------------------
393
! ----------------------------------------------------------------
394
!
395
! 6. Error messages :
396
! 7. Remarks
397
! 8. Structure :
398
! 9. Switches :
399
!
400
! !/S Enable subroutine tracing.
401
!
402
! 10. Source code :
403
!
404
!/ ------------------------------------------------------------------- /
405
#ifdef W3_S
406
USE
w3servmd
,
ONLY
:
strace
407
#endif
408
!
409
!/
410
!/ ------------------------------------------------------------------- /
411
!/ Parameter list
412
!/
413
!/ ------------------------------------------------------------------- /
414
!/ Local PARAMETERs
415
!/
416
#ifdef W3_S
417
INTEGER
,
SAVE
:: ient = 0
418
#endif
419
!/
420
!/ ------------------------------------------------------------------- /
421
!/
422
#ifdef W3_S
423
CALL
strace
(ient,
'W3XXXX'
)
424
#endif
425
integer(8)
:: vmrss
426
character(len=80)
:: stat_key, stat_value
427
!
428
vmrss = 0
429
open
(unit=1000,
file
=
"/proc/self/status"
, status=
'old'
, err=99)
430
do
while
(.true.)
431
read
(unit=1000, fmt=*, err=88) stat_key, stat_value
432
if
(stat_key ==
'VmRSS:'
)
then
433
read
(stat_value, *) vmrss
434
exit
435
end if
436
end do
437
88
close
(unit=1000)
438
if
(vmrss == 0)
goto
99
439
return
440
!
441
99 print *,
'ERROR: procfs not mounted or not compatible'
442
vmrss = -1
443
end function
getvmrss
444
445
end module
mallocinfo_m
446
447
!program test
448
! use MallocInfo_m
449
! implicit none
450
! type(MallInfo_t) :: mallinfos(10000)
451
! integer :: i, nInfos
452
! integer, allocatable :: data(:)
453
!
454
! allocate(data(0))
455
! nInfos = 0
456
! do i=1, 10
457
! write(*,*) "Iteration",i
458
! deallocate(data)
459
! allocate(data(i*100000))
460
! nInfos = nInfos+1
461
! call getMallocInfo(mallinfos(nInfos))
462
! call printMallInfo(IAPROC,mallInfos(nInfos))
463
! call sleep(1)
464
! end do
465
466
! do i=10, 1, -1
467
! write(*,*) "Iteration",i
468
! deallocate(data)
469
! allocate(data(i*100000))
470
! nInfos = nInfos+1
471
! call getMallocInfo(mallinfos(nInfos))
472
! call printMallInfo(IAPROC,mallInfos(nInfos))
473
! call sleep(1)
474
! end do
475
476
! write(*,*) "Total size of memory allocated with sbrk. min, mean, max", minval(mallinfos(1:nInfos)%arena), sum(mallinfos(1:nInfos)%arena)/nInfos, maxval(mallinfos(1:nInfos)%arena)
477
!end program
mallocinfo_m::getvmrss
integer(8) function getvmrss()
Definition:
w3meminfo.F90:361
mallocinfo_m::printmallinfo
subroutine printmallinfo(ihdnl, malinfo)
Definition:
w3meminfo.F90:177
mallocinfo_m::getmallocinfo
subroutine getmallocinfo(malinfo)
Definition:
w3meminfo.F90:107
mallocinfo_m
Definition:
w3meminfo.F90:1
mallocinfo_m::getvmsize
integer(8) function getvmsize()
Definition:
w3meminfo.F90:276
mallocinfo_m::mallinfo
Definition:
w3meminfo.F90:84
w3servmd
Definition:
w3servmd.F90:3
file
file(STRINGS ${CMAKE_BINARY_DIR}/switch switch_strings) separate_arguments(switches UNIX_COMMAND $
Definition:
CMakeLists.txt:3
w3servmd::strace
subroutine strace(IENT, SNAME)
Definition:
w3servmd.F90:148
mallocinfo_m::mallinfo_t
This structure type is used to return information about the dynamic memory allocator.
Definition:
w3meminfo.F90:60
model
src
w3meminfo.F90
Generated by
1.8.17