読者です 読者をやめる 読者になる 読者になる

fugagaの備忘録

しがないプログラマの備忘録。好きなモノ:機械学習、Linux、vim、C/C++、Scala、php、CakePHP、python

メモリ使用量の計測 (valgrind)

Linuxでプログラムのメモリ使用量(時間-メモリ使用量のグラフ、最大値、、、)を計測するには、valgrindコマンドが便利。
インストールされていない場合、CentOSの場合は

yum install valgrind

でインストールする。

使い方は、lsのメモリ使用量を計測する場合、

valgrind --tool=massif --stacks=yes --trace-children=yes ls

とすると、

==17703== Massif, a heap profiler
==17703== Copyright (C) 2003-2012, and GNU GPL'd, by Nicholas Nethercote
==17703== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==17703== Command: ls
==17703==
a  b  c  d
==17703==

と表示され、結果として、massif.out.17703が生成されるので、

ms_print massif.out.17703

とすると、メモリ使用量の詳細情報が表示される。

--------------------------------------------------------------------------------
Command:            ls
Massif arguments:   --stacks=yes
ms_print arguments: massif.out.17703
--------------------------------------------------------------------------------


    KB
57.19^                                                               #
     |                                                               #
     |                                                               #
     |                                                               #
     |                                                               #
     |                                                               #
     |                                                               #
     |                                                               #
     |                                                               #  :
     |                                                               #  :
     |                                                               #  :
     |                                                               # ::
     |                                                              @#::::@:::
     |                                                              @#::::@:::
     |                                                              @#::::@:::
     |                                                              @#::::@:::
     |                                                              @#::::@:::
     |                                                              @#::::@:::
     |                                                              @#::::@:::
     |    :@@:::@                                             :@@@@:@#::::@:::
   0 +----------------------------------------------------------------------->ki
     0                                                                   395.0

Number of snapshots: 84
 Detailed snapshots: [5, 8, 22, 26, 39, 44, 49, 51, 53, 55, 59, 60, 61, 62, 63, 64, 65, 66 (peak), 76]

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
  0              0                0                0             0            0
  1          2,909              664                0             0          664
  2          9,939            2,520                0             0        2,520
  3         16,135            2,608                0             0        2,608
  4         25,180            3,088                0             0        3,088
  5         32,747            3,424                0             0        3,424
00.00% (0B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
  6         39,874            3,792                0             0        3,792
  7         47,599            4,352                0             0        4,352
  8         56,803            5,352                0             0        5,352
00.00% (0B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
  9         64,699            1,032                0             0        1,032
 10         70,159              872                0             0          872
 11         77,890            1,032                0             0        1,032
 12         85,991            1,320                0             0        1,320
 13         93,908              936                0             0          936
 14        101,624            1,592                0             0        1,592
 15        110,423            1,528                0             0        1,528
 16        116,349            1,584                0             0        1,584
 17        122,274              936                0             0          936
 18        128,820            1,528                0             0        1,528
 19        137,714            1,528                0             0        1,528
 20        144,014            1,272                0             0        1,272
 21        148,464            1,528                0             0        1,528
 22        154,794            1,272                0             0        1,272
00.00% (0B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 23        164,696            1,528                0             0        1,528
 24        170,702            1,272                0             0        1,272
 25        176,513            1,272                0             0        1,272
 26        183,681            1,584                0             0        1,584
00.00% (0B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 27        189,356            1,528                0             0        1,528
 28        195,348            1,528                0             0        1,528
 29        200,788            1,528                0             0        1,528
 30        209,397            1,528                0             0        1,528
 31        215,303            1,272                0             0        1,272
 32        220,712            1,528                0             0        1,528
 33        226,240              936                0             0          936
 34        234,499            1,528                0             0        1,528
 35        243,971              936                0             0          936
 36        250,188            1,320                0             0        1,320
 37        255,627            1,280                0             0        1,280
 38        261,164              936                0             0          936
 39        269,409              768                0             0          768
00.00% (0B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 40        275,262            1,528                0             0        1,528
 41        280,678            1,120                0             0        1,120
 42        286,452              344                0             0          344
 43        291,920            1,128                0             0        1,128
 44        297,397            1,712              568            16        1,128
33.18% (568B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->33.18% (568B) 0x3A08A67149: __fopen_internal (in /lib64/libc-2.12.so)
  ->33.18% (568B) 0x3A0A20CD2B: ??? (in /lib64/libselinux.so.1)
    ->33.18% (568B) 0x3A0A215CB4: ??? (in /lib64/libselinux.so.1)
      ->33.18% (568B) 0x3A0A204FA1: ??? (in /lib64/libselinux.so.1)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 45        302,823            1,184              688            32          464
 46        308,223               32                0             0           32
 47        313,808            1,032                0             0        1,032
 48        319,755            4,192            2,676            84        1,432
 49        325,254            4,920            3,592           240        1,088
73.01% (3,592B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->69.11% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->69.11% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->69.11% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->69.11% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->69.11% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->69.11% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->02.44% (120B) 0x3A08A2A3D7: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
| ->02.44% (120B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|   ->02.44% (120B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|     ->02.44% (120B) 0x4084AD: ??? (in /bin/ls)
|       ->02.44% (120B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->01.46% (72B) 0x3A08A81040: strdup (in /lib64/libc-2.12.so)
| ->01.22% (60B) 0x3A08A29266: setlocale (in /lib64/libc-2.12.so)
| | ->01.22% (60B) 0x4084AD: ??? (in /bin/ls)
| |   ->01.22% (60B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.24% (12B) in 1+ places, all below ms_print's threshold (01.00%)
|
->00.00% (0B) in 1+ places, all below ms_print's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 50        328,295            4,936            3,628           276        1,032
 51        330,744            5,416            3,652           300        1,464
67.43% (3,652B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->62.78% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->62.78% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->62.78% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->62.78% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->62.78% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->62.78% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->02.44% (132B) 0x3A08A81040: strdup (in /lib64/libc-2.12.so)
| ->02.22% (120B) 0x3A08A29266: setlocale (in /lib64/libc-2.12.so)
| | ->02.22% (120B) 0x4084AD: ??? (in /bin/ls)
| |   ->02.22% (120B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.22% (12B) in 1+ places, all below ms_print's threshold (01.00%)
|
->02.22% (120B) 0x3A08A2A3D7: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
| ->02.22% (120B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|   ->02.22% (120B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|     ->02.22% (120B) 0x4084AD: ??? (in /bin/ls)
|       ->02.22% (120B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->00.00% (0B) in 1+ places, all below ms_print's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 52        333,677            5,296            3,688           336        1,272
 53        334,455            5,640            3,688           336        1,616
65.39% (3,688B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->60.28% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->60.28% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->60.28% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->60.28% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->60.28% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->60.28% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->02.77% (156B) 0x3A08A81040: strdup (in /lib64/libc-2.12.so)
| ->02.55% (144B) 0x3A08A29266: setlocale (in /lib64/libc-2.12.so)
| | ->02.55% (144B) 0x4084AD: ??? (in /bin/ls)
| |   ->02.55% (144B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.21% (12B) in 1+ places, all below ms_print's threshold (01.00%)
|
->02.13% (120B) 0x3A08A2A3D7: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
| ->02.13% (120B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|   ->02.13% (120B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|     ->02.13% (120B) 0x4084AD: ??? (in /bin/ls)
|       ->02.13% (120B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->00.21% (12B) in 1+ places, all below ms_print's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 54        337,415            5,376            3,732           372        1,272
 55        337,965            5,720            3,732           372        1,616
65.24% (3,732B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->59.44% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->59.44% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->59.44% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->59.44% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->59.44% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->59.44% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->02.90% (166B) 0x3A08A81040: strdup (in /lib64/libc-2.12.so)
| ->02.52% (144B) 0x3A08A29266: setlocale (in /lib64/libc-2.12.so)
| | ->02.52% (144B) 0x4084AD: ??? (in /bin/ls)
| |   ->02.52% (144B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.38% (22B) in 1+ places, all below ms_print's threshold (01.00%)
|
->02.10% (120B) 0x3A08A2A3D7: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
| ->02.10% (120B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|   ->02.10% (120B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|     ->02.10% (120B) 0x4084AD: ??? (in /bin/ls)
|       ->02.10% (120B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->00.80% (46B) in 1+ places, all below ms_print's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 56        340,913            5,376            3,732           372        1,272
 57        343,825            5,432            3,732           372        1,328
 58        346,775            5,408            3,732           372        1,304
 59        348,801            5,800            3,732           372        1,696
64.34% (3,732B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->58.62% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->58.62% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->58.62% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->58.62% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->58.62% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->58.62% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->02.86% (166B) 0x3A08A81040: strdup (in /lib64/libc-2.12.so)
| ->02.48% (144B) 0x3A08A29266: setlocale (in /lib64/libc-2.12.so)
| | ->02.48% (144B) 0x4084AD: ??? (in /bin/ls)
| |   ->02.48% (144B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.38% (22B) in 1+ places, all below ms_print's threshold (01.00%)
|
->02.07% (120B) 0x3A08A2A3D7: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
| ->02.07% (120B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|   ->02.07% (120B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|     ->02.07% (120B) 0x4084AD: ??? (in /bin/ls)
|       ->02.07% (120B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->00.79% (46B) in 1+ places, all below ms_print's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 60        350,833           24,080           23,044           412          624
95.70% (23,044B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->80.20% (19,312B) 0x4116B7: ??? (in /bin/ls)
| ->79.73% (19,200B) 0x408955: ??? (in /bin/ls)
| | ->79.73% (19,200B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.47% (112B) in 1+ places, all below ms_print's threshold (01.00%)
|
->14.12% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->14.12% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->14.12% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->14.12% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->14.12% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->14.12% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->01.38% (332B) in 7 places, all below massif's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 61        351,206           24,864           23,076           420        1,368
92.81% (23,076B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->77.80% (19,344B) 0x4116B7: ??? (in /bin/ls)
| ->77.22% (19,200B) 0x408955: ??? (in /bin/ls)
| | ->77.22% (19,200B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.58% (144B) in 1+ places, all below ms_print's threshold (01.00%)
|
->13.67% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->13.67% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->13.67% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->13.67% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->13.67% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->13.67% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->01.34% (332B) in 7 places, all below massif's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 62        352,115           25,176           23,076           420        1,680
91.66% (23,076B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->76.84% (19,344B) 0x4116B7: ??? (in /bin/ls)
| ->76.26% (19,200B) 0x408955: ??? (in /bin/ls)
| | ->76.26% (19,200B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.57% (144B) in 1+ places, all below ms_print's threshold (01.00%)
|
->13.50% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->13.50% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->13.50% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->13.50% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->13.50% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->13.50% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->01.32% (332B) in 7 places, all below massif's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 63        352,840           25,736           23,078           442        2,216
89.67% (23,078B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->75.17% (19,346B) 0x4116B7: ??? (in /bin/ls)
| ->74.60% (19,200B) 0x408955: ??? (in /bin/ls)
| | ->74.60% (19,200B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.57% (146B) in 1+ places, all below ms_print's threshold (01.00%)
|
->13.21% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->13.21% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->13.21% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->13.21% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->13.21% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->13.21% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->01.29% (332B) in 7 places, all below massif's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 64        353,681           26,048           23,078           442        2,528
88.60% (23,078B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->74.27% (19,346B) 0x4116B7: ??? (in /bin/ls)
| ->73.71% (19,200B) 0x408955: ??? (in /bin/ls)
| | ->73.71% (19,200B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.56% (146B) in 1+ places, all below ms_print's threshold (01.00%)
|
->13.05% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->13.05% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->13.05% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->13.05% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->13.05% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->13.05% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->01.27% (332B) in 7 places, all below massif's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 65        354,073           57,912           55,886           458        1,568
96.50% (55,886B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->56.65% (32,808B) 0x3A08AA87CF: __alloc_dir (in /lib64/libc-2.12.so)
| ->56.65% (32,808B) 0x407DD2: ??? (in /bin/ls)
|   ->56.65% (32,808B) 0x4089DB: ??? (in /bin/ls)
|     ->56.65% (32,808B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->33.41% (19,346B) 0x4116B7: ??? (in /bin/ls)
| ->33.15% (19,200B) 0x408955: ??? (in /bin/ls)
| | ->33.15% (19,200B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.25% (146B) in 1+ places, all below ms_print's threshold (01.00%)
|
->05.87% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->05.87% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->05.87% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->05.87% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->05.87% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->05.87% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->00.57% (332B) in 1+ places, all below ms_print's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 66        354,410           58,560           55,886           458        2,216
95.43% (55,886B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->56.02% (32,808B) 0x3A08AA87CF: __alloc_dir (in /lib64/libc-2.12.so)
| ->56.02% (32,808B) 0x407DD2: ??? (in /bin/ls)
|   ->56.02% (32,808B) 0x4089DB: ??? (in /bin/ls)
|     ->56.02% (32,808B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->33.04% (19,346B) 0x4116B7: ??? (in /bin/ls)
| ->32.79% (19,200B) 0x408955: ??? (in /bin/ls)
| | ->32.79% (19,200B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.25% (146B) in 1+ places, all below ms_print's threshold (01.00%)
|
->05.81% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->05.81% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->05.81% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->05.81% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->05.81% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->05.81% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->00.57% (332B) in 1+ places, all below ms_print's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 67        357,361           58,368           55,894           546        1,928
 68        360,283           25,664           23,182           538        1,944
 69        363,320           25,440           23,182           538        1,720
 70        366,264           25,920           23,182           538        2,200
 71        369,208           26,576           23,662           554        2,360
 72        372,166           35,800           23,662           554       11,584
 73        375,098           25,808           23,662           554        1,592
 74        378,061           25,424           23,628           524        1,272
 75        381,023           25,520           23,628           524        1,368
 76        383,957           25,152           23,628           524        1,000
93.94% (23,628B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->78.34% (19,704B) 0x4116B7: ??? (in /bin/ls)
| ->76.34% (19,200B) 0x408955: ??? (in /bin/ls)
| | ->76.34% (19,200B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->01.15% (288B) 0x40764A: ??? (in /bin/ls)
| | ->01.15% (288B) 0x407AE3: ??? (in /bin/ls)
| |   ->01.15% (288B) 0x408250: ??? (in /bin/ls)
| |     ->01.15% (288B) 0x4089DB: ??? (in /bin/ls)
| |       ->01.15% (288B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
| |
| ->00.86% (216B) in 1+ places, all below ms_print's threshold (01.00%)
|
->13.52% (3,400B) 0x3A08A29DF5: _nl_intern_locale_data (in /lib64/libc-2.12.so)
| ->13.52% (3,400B) 0x3A08A2A44B: _nl_load_locale_from_archive (in /lib64/libc-2.12.so)
|   ->13.52% (3,400B) 0x3A08A29939: _nl_find_locale (in /lib64/libc-2.12.so)
|     ->13.52% (3,400B) 0x3A08A29114: setlocale (in /lib64/libc-2.12.so)
|       ->13.52% (3,400B) 0x4084AD: ??? (in /bin/ls)
|         ->13.52% (3,400B) 0x3A08A1ECDB: (below main) (in /lib64/libc-2.12.so)
|
->02.08% (524B) in 9 places, all below massif's threshold (01.00%)

--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
 77        386,900           25,800           23,628           524        1,648
 78        389,810           25,768           23,628           524        1,616
 79        392,721           24,944           23,628           524          792
 80        395,716           25,800           23,628           524        1,648
 81        398,625           25,768           23,628           524        1,616
 82        401,537           24,544           23,460           356          728
 83        404,450           20,728           19,896           152          680

以上より、lsコマンドのメモリ使用量の最大値は、55.12KBであることがわかる。



ちなみに、

useful-heap(B):プログラムが要求したバイト数。
extra-heap(B) :プログラムが要求したものを超えて割り当てられたバイト数。


また、timeコマンドで、メモリ使用量の最大値を計測する方法が、いろいろなブログで紹介されているが、うまくいっていないようなので、valgrindコマンドのほうが、たぶん確実。試しにmallocでテストしたら確保した分だけ計測できることを確認できた。

http://d.hatena.ne.jp/N_Nao/20111226/1324926173