zz from :

http://blog.dccmx.com/2011/01/valgrind-massif/

让程序飞 之 内存工具:valgrind –tool=massif & massif-visualizer

Posted on 一月 6th, 2011 by dccmx

之前提到过内存泄漏问题,我们有memcheck工具来检查。很爽。但是有时候memcheck工具查了没泄漏,程序一跑,内存还是狂飙。这又是什么问题。。。

其实memcheck检查的内存泄漏只是狭义的内存泄漏,或者说是严格的内存泄漏,也就是说,在程序运行的生命周期内,这部分内存你是彻底释放不了了,即,你失去了这些地址。

其实还有第二种类型的内存泄漏,就是,长期闲置的内存堆积。这部分内存虽然你还保存了地址,想要释放的时候还是能释放。关键就是你忘了释放。。。杯具啊。这种问题memcheck就不给力了。这就引出了第二个内存工具valgrind –tool=massif。

先来看一个程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <vector>
using namespace std;
vector<int *> va, vb;
void fa() {
  int *p = new int[100];
  va.push_back(p);
}
void fb() {
  int *p = new int[100];
  vb.push_back(p);
}
int main() {
  for (int i=0; i<100000; i++) {
    fa();
    fb();
  }
  return 0;
}

程序里,我们拼命申请内存,然后放起来,不用。显然,这种程序跑起来内存肯定一路狂飙,直到内存耗尽而亡。。。

面对这种程序,我们需要一个工具来找出我们分配的内存都用到哪里了。massif就是这个工具。二话不说,先编译之:

1
g++ –o test –g test.cpp

交给massif运行之:

1
valgrind --tool=massif ./test

什么都没输出?不是的,看看当前目录,多了massif.out.****的文件吧,那才是massif真正的输出。vi打开。乱码!!!人类看不懂。其实这个输出还要经过一道工序加工我们人类才能看懂:

1
ms_print massif.out.*** >massif.log

打开log看看:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
--------------------------------------------------------------------------------
Command:            ./mem1
Massif arguments:   (none)
ms_print arguments: massif.out.20770
--------------------------------------------------------------------------------
    MB
79.82^                                                                       #
     |                                                                     ::#
     |                                                                 ::@:::#
     |                                                              :::::@:::#
     |                                                          :::@:::::@:::#
     |                                                       ::::::@:::::@:::#
     |                                                    :::@:::::@:::::@:::#
     |                                                 @:::::@:::::@:::::@:::#
     |                                             ::::@:::::@:::::@:::::@:::#
     |                                          :@:::::@:::::@:::::@:::::@:::#
     |                                       ::::@:::::@:::::@:::::@:::::@:::#
     |                                   ::::::::@:::::@:::::@:::::@:::::@:::#
     |                               ::::::::::::@:::::@:::::@:::::@:::::@:::#
     |                             ::::::::::::::@:::::@:::::@:::::@:::::@:::#
     |                         ::@:::::::::::::::@:::::@:::::@:::::@:::::@:::#
     |                     ::::::@:::::::::::::::@:::::@:::::@:::::@:::::@:::#
     |                  :::::::::@:::::::::::::::@:::::@:::::@:::::@:::::@:::#
     |               @:::::::::::@:::::::::::::::@:::::@:::::@:::::@:::::@:::#
     |            :::@:::::::::::@:::::::::::::::@:::::@:::::@:::::@:::::@:::#
     |        :::::::@:::::::::::@:::::::::::::::@:::::@:::::@:::::@:::::@:::#
   0 +----------------------------------------------------------------------->Mi
     0                                                                   20.69
Number of snapshots: 98
Detailed snapshots: [13, 28, 51, 59, 69, 79, 89, 97 (peak)]
--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
  0              0                0                0             0            0
  1      1,463,114              408              400             8            0
  2      1,800,331        1,285,344        1,260,768        24,576            0
  3      2,133,198        2,657,576        2,606,736        50,840            0
  4      2,348,502        3,525,648        3,459,072        66,576            0
  5      2,624,527        4,680,696        4,591,472        89,224            0
  6      2,967,727        6,116,856        5,999,472       117,384            0
  7      3,206,290        7,057,808        6,924,544       133,264            0
  8      3,416,890        7,939,088        7,788,544       150,544            0
  9      3,666,980        8,985,608        8,814,544       171,064            0
10      3,912,680       10,013,768        9,822,544       191,224            0
11      4,158,380       11,041,928       10,830,544       211,384            0
12      4,404,080       12,070,088       11,838,544       231,544            0
13      4,649,780       13,098,248       12,846,544       251,704            0
98.08% (12,846,544B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->48.04% (6,292,400B) 0x400A14: fa() (mem1.cpp:8)
| ->48.04% (6,292,400B) 0x400A6A: main (mem1.cpp:20)
|
->48.04% (6,292,000B) 0x400A3D: fb() (mem1.cpp:13)
| ->48.04% (6,292,000B) 0x400A6F: main (mem1.cpp:21)
|
->02.00% (262,144B) 0x40142F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (new_allocator.h:89)
  ->02.00% (262,144B) 0x40121B: std::_Vector_base<int*, std::allocator<int*> >::_M_allocate(unsigned long) (stl_vector.h:140)
    ->02.00% (262,144B) 0x400DC5: std::vector<int*, std::allocator<int*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int**, std::vector<int*, std::allocator<int*> > >, int* const&) (vector.tcc:322)
      ->02.00% (262,144B) 0x400BC4: std::vector<int*, std::allocator<int*> >::push_back(int* const&) (stl_vector.h:741)
        ->01.00% (131,072B) 0x400A29: fa() (mem1.cpp:9)
        | ->01.00% (131,072B) 0x400A6A: main (mem1.cpp:20)
        |
        ->01.00% (131,072B) 0x400A52: fb() (mem1.cpp:14)
          ->01.00% (131,072B) 0x400A6F: main (mem1.cpp:21)
--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
14      5,019,101       14,537,472       14,262,688       274,784            0
15      5,339,391       15,877,752       15,576,688       301,064            0
16      5,549,991       16,759,032       16,440,688       318,344            0
17      5,760,591       17,640,312       17,304,688       335,624            0
18      5,971,191       18,521,592       18,168,688       352,904            0
19      6,181,791       19,402,872       19,032,688       370,184            0
20      6,392,391       20,284,152       19,896,688       387,464            0
21      6,602,991       21,165,432       20,760,688       404,744            0
22      6,813,591       22,046,712       21,624,688       422,024            0
23      7,024,191       22,927,992       22,488,688       439,304            0
24      7,234,791       23,809,272       23,352,688       456,584            0
25      7,445,391       24,690,552       24,216,688       473,864            0
26      7,655,991       25,571,832       25,080,688       491,144            0
27      7,964,871       26,864,376       26,347,888       516,488            0
28      8,147,289       27,787,696       27,263,376       524,320            0
98.11% (27,263,376B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->47.17% (13,107,600B) 0x400A14: fa() (mem1.cpp:8)
| ->47.17% (13,107,600B) 0x400A6A: main (mem1.cpp:20)
|
->47.17% (13,107,200B) 0x400A3D: fb() (mem1.cpp:13)
| ->47.17% (13,107,200B) 0x400A6F: main (mem1.cpp:21)
|
->03.77% (1,048,576B) 0x40142F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (new_allocator.h:89)
  ->03.77% (1,048,576B) 0x40121B: std::_Vector_base<int*, std::allocator<int*> >::_M_allocate(unsigned long) (stl_vector.h:140)
    ->03.77% (1,048,576B) 0x400DC5: std::vector<int*, std::allocator<int*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int**, std::vector<int*, std::allocator<int*> > >, int* const&) (vector.tcc:322)
      ->03.77% (1,048,576B) 0x400BC4: std::vector<int*, std::allocator<int*> >::push_back(int* const&) (stl_vector.h:741)
        ->02.83% (786,432B) 0x400A29: fa() (mem1.cpp:9)
        | ->02.83% (786,432B) 0x400A6A: main (mem1.cpp:20)
        |
        ->00.94% (262,144B) in 1+ places, all below ms_print's threshold (01.00%)
--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
29      8,442,148       28,657,544       28,116,176       541,368            0
30      8,835,268       30,302,600       29,728,976       573,624            0
31      9,228,388       31,947,656       31,341,776       605,880            0
32      9,424,948       32,770,184       32,148,176       622,008            0
33      9,621,508       33,592,712       32,954,576       638,136            0
34      9,818,068       34,415,240       33,760,976       654,264            0
35     10,014,628       35,237,768       34,567,376       670,392            0
36     10,211,188       36,060,296       35,373,776       686,520            0
37     10,407,748       36,882,824       36,180,176       702,648            0
38     10,604,308       37,705,352       36,986,576       718,776            0
39     10,800,868       38,527,880       37,792,976       734,904            0
40     10,997,428       39,350,408       38,599,376       751,032            0
41     11,193,988       40,172,936       39,405,776       767,160            0
42     11,390,548       40,995,464       40,212,176       783,288            0
43     11,587,108       41,817,992       41,018,576       799,416            0
44     11,783,668       42,640,520       41,824,976       815,544            0
45     11,980,228       43,463,048       42,631,376       831,672            0
46     12,176,788       44,285,576       43,437,776       847,800            0
47     12,373,348       45,108,104       44,244,176       863,928            0
48     12,569,908       45,930,632       45,050,576       880,056            0
49     12,864,748       47,164,424       46,260,176       904,248            0
50     13,047,168       47,927,792       47,008,576       919,216            0
51     13,229,593       48,691,160       47,756,976       934,184            0
98.08% (47,756,976B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->47.96% (23,354,400B) 0x400A14: fa() (mem1.cpp:8)
| ->47.96% (23,354,400B) 0x400A6A: main (mem1.cpp:20)
|
->47.96% (23,354,000B) 0x400A3D: fb() (mem1.cpp:13)
| ->47.96% (23,354,000B) 0x400A6F: main (mem1.cpp:21)
|
->02.15% (1,048,576B) 0x40142F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (new_allocator.h:89)
  ->02.15% (1,048,576B) 0x40121B: std::_Vector_base<int*, std::allocator<int*> >::_M_allocate(unsigned long) (stl_vector.h:140)
    ->02.15% (1,048,576B) 0x400DC5: std::vector<int*, std::allocator<int*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int**, std::vector<int*, std::allocator<int*> > >, int* const&) (vector.tcc:322)
      ->02.15% (1,048,576B) 0x400BC4: std::vector<int*, std::allocator<int*> >::push_back(int* const&) (stl_vector.h:741)
        ->01.08% (524,288B) 0x400A29: fa() (mem1.cpp:9)
        | ->01.08% (524,288B) 0x400A6A: main (mem1.cpp:20)
        |
        ->01.08% (524,288B) 0x400A52: fb() (mem1.cpp:14)
          ->01.08% (524,288B) 0x400A6F: main (mem1.cpp:21)
--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
52     13,412,013       49,454,528       48,505,376       949,152            0
53     13,594,438       50,217,896       49,253,776       964,120            0
54     13,776,858       50,981,264       50,002,176       979,088            0
55     13,959,283       51,744,632       50,750,576       994,056            0
56     14,141,703       52,508,000       51,498,976     1,009,024            0
57     14,324,128       53,271,368       52,247,376     1,023,992            0
58     14,506,548       54,034,736       52,995,776     1,038,960            0
59     14,797,117       55,574,960       54,526,352     1,048,608            0
98.11% (54,526,352B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->47.17% (26,214,800B) 0x400A14: fa() (mem1.cpp:8)
| ->47.17% (26,214,800B) 0x400A6A: main (mem1.cpp:20)
|
->47.17% (26,214,400B) 0x400A3D: fb() (mem1.cpp:13)
| ->47.17% (26,214,400B) 0x400A6F: main (mem1.cpp:21)
|
->03.77% (2,097,152B) 0x40142F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (new_allocator.h:89)
  ->03.77% (2,097,152B) 0x40121B: std::_Vector_base<int*, std::allocator<int*> >::_M_allocate(unsigned long) (stl_vector.h:140)
    ->03.77% (2,097,152B) 0x400DC5: std::vector<int*, std::allocator<int*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int**, std::vector<int*, std::allocator<int*> > >, int* const&) (vector.tcc:322)
      ->03.77% (2,097,152B) 0x400BC4: std::vector<int*, std::allocator<int*> >::push_back(int* const&) (stl_vector.h:741)
        ->02.83% (1,572,864B) 0x400A29: fa() (mem1.cpp:9)
        | ->02.83% (1,572,864B) 0x400A6A: main (mem1.cpp:20)
        |
        ->00.94% (524,288B) 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     14,979,577       55,614,528       54,565,152     1,049,376            0
61     15,162,002       56,377,896       55,313,552     1,064,344            0
62     15,344,422       57,141,264       56,061,952     1,079,312            0
63     15,526,847       57,904,632       56,810,352     1,094,280            0
64     15,709,267       58,668,000       57,558,752     1,109,248            0
65     15,891,692       59,431,368       58,307,152     1,124,216            0
66     16,074,112       60,194,736       59,055,552     1,139,184            0
67     16,256,537       60,958,104       59,803,952     1,154,152            0
68     16,438,957       61,721,472       60,552,352     1,169,120            0
69     16,621,382       62,484,840       61,300,752     1,184,088            0
98.10% (61,300,752B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->47.37% (29,602,000B) 0x400A14: fa() (mem1.cpp:8)
| ->47.37% (29,602,000B) 0x400A6A: main (mem1.cpp:20)
|
->47.37% (29,601,600B) 0x400A3D: fb() (mem1.cpp:13)
| ->47.37% (29,601,600B) 0x400A6F: main (mem1.cpp:21)
|
->03.36% (2,097,152B) 0x40142F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (new_allocator.h:89)
  ->03.36% (2,097,152B) 0x40121B: std::_Vector_base<int*, std::allocator<int*> >::_M_allocate(unsigned long) (stl_vector.h:140)
    ->03.36% (2,097,152B) 0x400DC5: std::vector<int*, std::allocator<int*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int**, std::vector<int*, std::allocator<int*> > >, int* const&) (vector.tcc:322)
      ->03.36% (2,097,152B) 0x400BC4: std::vector<int*, std::allocator<int*> >::push_back(int* const&) (stl_vector.h:741)
        ->01.68% (1,048,576B) 0x400A29: fa() (mem1.cpp:9)
        | ->01.68% (1,048,576B) 0x400A6A: main (mem1.cpp:20)
        |
        ->01.68% (1,048,576B) 0x400A52: fb() (mem1.cpp:14)
          ->01.68% (1,048,576B) 0x400A6F: main (mem1.cpp:21)
--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
70     16,803,802       63,248,208       62,049,152     1,199,056            0
71     16,986,227       64,011,576       62,797,552     1,214,024            0
72     17,168,647       64,774,944       63,545,952     1,228,992            0
73     17,351,072       65,538,312       64,294,352     1,243,960            0
74     17,533,492       66,301,680       65,042,752     1,258,928            0
75     17,715,917       67,065,048       65,791,152     1,273,896            0
76     17,898,337       67,828,416       66,539,552     1,288,864            0
77     18,080,762       68,591,784       67,287,952     1,303,832            0
78     18,263,182       69,355,152       68,036,352     1,318,800            0
79     18,445,607       70,118,520       68,784,752     1,333,768            0
98.10% (68,784,752B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->47.55% (33,344,000B) 0x400A14: fa() (mem1.cpp:8)
| ->47.55% (33,344,000B) 0x400A6A: main (mem1.cpp:20)
|
->47.55% (33,343,600B) 0x400A3D: fb() (mem1.cpp:13)
| ->47.55% (33,343,600B) 0x400A6F: main (mem1.cpp:21)
|
->02.99% (2,097,152B) 0x40142F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (new_allocator.h:89)
  ->02.99% (2,097,152B) 0x40121B: std::_Vector_base<int*, std::allocator<int*> >::_M_allocate(unsigned long) (stl_vector.h:140)
    ->02.99% (2,097,152B) 0x400DC5: std::vector<int*, std::allocator<int*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int**, std::vector<int*, std::allocator<int*> > >, int* const&) (vector.tcc:322)
      ->02.99% (2,097,152B) 0x400BC4: std::vector<int*, std::allocator<int*> >::push_back(int* const&) (stl_vector.h:741)
        ->01.50% (1,048,576B) 0x400A29: fa() (mem1.cpp:9)
        | ->01.50% (1,048,576B) 0x400A6A: main (mem1.cpp:20)
        |
        ->01.50% (1,048,576B) 0x400A52: fb() (mem1.cpp:14)
          ->01.50% (1,048,576B) 0x400A6F: main (mem1.cpp:21)
--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
80     18,628,027       70,881,888       69,533,152     1,348,736            0
81     18,810,452       71,645,256       70,281,552     1,363,704            0
82     18,992,872       72,408,624       71,029,952     1,378,672            0
83     19,175,297       73,171,992       71,778,352     1,393,640            0
84     19,357,717       73,935,360       72,526,752     1,408,608            0
85     19,540,142       74,698,728       73,275,152     1,423,576            0
86     19,722,562       75,462,096       74,023,552     1,438,544            0
87     19,904,987       76,225,464       74,771,952     1,453,512            0
88     20,087,407       76,988,832       75,520,352     1,468,480            0
89     20,269,832       77,752,200       76,268,752     1,483,448            0
98.09% (76,268,752B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->47.70% (37,086,000B) 0x400A14: fa() (mem1.cpp:8)
| ->47.70% (37,086,000B) 0x400A6A: main (mem1.cpp:20)
|
->47.70% (37,085,600B) 0x400A3D: fb() (mem1.cpp:13)
| ->47.70% (37,085,600B) 0x400A6F: main (mem1.cpp:21)
|
->02.70% (2,097,152B) 0x40142F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (new_allocator.h:89)
  ->02.70% (2,097,152B) 0x40121B: std::_Vector_base<int*, std::allocator<int*> >::_M_allocate(unsigned long) (stl_vector.h:140)
    ->02.70% (2,097,152B) 0x400DC5: std::vector<int*, std::allocator<int*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int**, std::vector<int*, std::allocator<int*> > >, int* const&) (vector.tcc:322)
      ->02.70% (2,097,152B) 0x400BC4: std::vector<int*, std::allocator<int*> >::push_back(int* const&) (stl_vector.h:741)
        ->01.35% (1,048,576B) 0x400A29: fa() (mem1.cpp:9)
        | ->01.35% (1,048,576B) 0x400A6A: main (mem1.cpp:20)
        |
        ->01.35% (1,048,576B) 0x400A52: fb() (mem1.cpp:14)
          ->01.35% (1,048,576B) 0x400A6F: main (mem1.cpp:21)
--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
90     20,452,252       78,515,568       77,017,152     1,498,416            0
91     20,634,677       79,278,936       77,765,552     1,513,384            0
92     20,817,097       80,042,304       78,513,952     1,528,352            0
93     20,999,522       80,805,672       79,262,352     1,543,320            0
94     21,181,942       81,569,040       80,010,752     1,558,288            0
95     21,364,367       82,332,408       80,759,152     1,573,256            0
96     21,546,787       83,095,776       81,507,552     1,588,224            0
97     21,690,735       83,697,168       82,097,152     1,600,016            0
98.09% (82,097,152B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->47.79% (40,000,000B) 0x400A14: fa() (mem1.cpp:8)
| ->47.79% (40,000,000B) 0x400A6A: main (mem1.cpp:20)
|
->47.79% (40,000,000B) 0x400A3D: fb() (mem1.cpp:13)
| ->47.79% (40,000,000B) 0x400A6F: main (mem1.cpp:21)
|
->02.51% (2,097,152B) 0x40142F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (new_allocator.h:89)
  ->02.51% (2,097,152B) 0x40121B: std::_Vector_base<int*, std::allocator<int*> >::_M_allocate(unsigned long) (stl_vector.h:140)
    ->02.51% (2,097,152B) 0x400DC5: std::vector<int*, std::allocator<int*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int**, std::vector<int*, std::allocator<int*> > >, int* const&) (vector.tcc:322)
      ->02.51% (2,097,152B) 0x400BC4: std::vector<int*, std::allocator<int*> >::push_back(int* const&) (stl_vector.h:741)
        ->01.25% (1,048,576B) 0x400A29: fa() (mem1.cpp:9)
        | ->01.25% (1,048,576B) 0x400A6A: main (mem1.cpp:20)
        |
        ->01.25% (1,048,576B) 0x400A52: fb() (mem1.cpp:14)
          ->01.25% (1,048,576B) 0x400A6F: main (mem1.cpp:21)

不要抓狂,听我给你解释这个输出是什么意思。

massif工作的时候会每隔一定时间对程序的内存使用取个快照。就是上面的一段:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--------------------------------------------------------------------------------
  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
--------------------------------------------------------------------------------
60     14,979,577       55,614,528       54,565,152     1,049,376            0
61     15,162,002       56,377,896       55,313,552     1,064,344            0
62     15,344,422       57,141,264       56,061,952     1,079,312            0
63     15,526,847       57,904,632       56,810,352     1,094,280            0
64     15,709,267       58,668,000       57,558,752     1,109,248            0
65     15,891,692       59,431,368       58,307,152     1,124,216            0
66     16,074,112       60,194,736       59,055,552     1,139,184            0
67     16,256,537       60,958,104       59,803,952     1,154,152            0
68     16,438,957       61,721,472       60,552,352     1,169,120            0
69     16,621,382       62,484,840       61,300,752     1,184,088            0
98.10% (61,300,752B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->47.37% (29,602,000B) 0x400A14: fa() (mem1.cpp:8)
| ->47.37% (29,602,000B) 0x400A6A: main (mem1.cpp:20)
|
->47.37% (29,601,600B) 0x400A3D: fb() (mem1.cpp:13)
| ->47.37% (29,601,600B) 0x400A6F: main (mem1.cpp:21)
|
->03.36% (2,097,152B) 0x40142F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (new_allocator.h:89)
  ->03.36% (2,097,152B) 0x40121B: std::_Vector_base<int*, std::allocator<int*> >::_M_allocate(unsigned long) (stl_vector.h:140)
    ->03.36% (2,097,152B) 0x400DC5: std::vector<int*, std::allocator<int*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int**, std::vector<int*, std::allocator<int*> > >, int* const&) (vector.tcc:322)
      ->03.36% (2,097,152B) 0x400BC4: std::vector<int*, std::allocator<int*> >::push_back(int* const&) (stl_vector.h:741)
        ->01.68% (1,048,576B) 0x400A29: fa() (mem1.cpp:9)
        | ->01.68% (1,048,576B) 0x400A6A: main (mem1.cpp:20)
        |
        ->01.68% (1,048,576B) 0x400A52: fb() (mem1.cpp:14)
->01.68% (1,048,576B) 0x400A6F: main (mem1.cpp:21)

这里我们主要看下半部分,它按照函数调用数的格式输出了每个函数里面每个内存分配点总共分配了多少内存。如上面:函数堆共分配了整个程序的98.10%内存,其中,mem1.cpp第8行的fa() 分配了47.37%,13行的fb也是47.3%。好了,我们知道了,所有的内存都用这俩地方了。。。果断优化。

还有更给力的工具吗?(显然,既然敢提出这个问题,就敢回答yes)

有!massif-visualizer,其实就是massif的图形前端。安装后用它打开刚刚的massif.out.xxxx效果如下:

太爽了!

内存 profile (zz)相关推荐

  1. unity, 内存profile,ImageEffects Temp和Unity GI SystemTex RGBM

    最近用unity的Profiler对公司项目进行内存profile,发现一些问题,记录一下. 用Memory Area的Detailed View,用法见:http://docs.unity3d.co ...

  2. Unity AssetBundle内存管理相关问题

    AssetBundle机制相关资料收集 最近网友通过网站搜索Unity3D在手机及其他平台下占用内存太大. 这里写下关于Unity3D对于内存的管理与优化. Unity3D 里有两种动态加载机制:一个 ...

  3. Unity加载机制及内存管理

    原文地址: http://game.ceeger.com/forum/read.php?tid=4394 作者写的非常精彩~ 一 Unity里有两种动态加载机制 1,Resources.Load:从一 ...

  4. 全面理解Unity加载和内存管理机制之二:进一步深入和细节

    Unity几种动态加载Prefab方式的差异: 其实存在3种加载prefab的方式: 一是静态引用,建一个public的变量,在Inspector里把prefab拉上去,用的时候instantiate ...

  5. Unity3D占用内存太大的解决方法【先转,慢慢看】

    2019独角兽企业重金招聘Python工程师标准>>> Unity3D占用内存太大的解决方法 最近网友通过网站搜索Unity3D在手机及其他平台下占用内存太大. 这里写下关于Unit ...

  6. 实战Go内存泄露【转】

    最近解决了我们项目中的一个内存泄露问题,事实再次证明pprof是一个好工具,但掌握好工具的正确用法,才能发挥好工具的威力,不然就算你手里有屠龙刀,也成不了天下第一,本文就是带你用pprof定位内存泄露 ...

  7. unity3d占用内存太大解决方法

    原帖:http://www.onevcat.com/2012/11/memory-in-unity3d/ 转载自星辰 Unity3D占用内存太大的解决方法 最近网友通过网站搜索Unity3D在手机及其 ...

  8. Unity3D占用内存详细解答

    Unity3D 里有两种动态加载机制:一个是Resources.Load,另外一个通过AssetBundle,其实两者区别不大. Resources.Load就是从一个缺省打进程序包里的AssetBu ...

  9. Unity3D 内存 释放

    最转载自:http://cl314413.blog.163.com/blog/static/190507976201322713921743/ 近网友通过网站搜索Unity3D在手机及其他平台下占用内 ...

最新文章

  1. .gitignore 无效及解决办法
  2. OpenCV中的CV_IMPL是什么意思?
  3. 服务器上的hdfs的配置文件中,namenode不能设置成127.0.0.1或者localhost,要设置ip或者映射别名
  4. LeetCode 790. 多米诺和托米诺平铺(动态规划)
  5. 【机房收费系统】--SSTab控件与MSHFlexGrid控件
  6. 趋势科技修复已遭利用的 Apex Central 0day
  7. 霍金撰文探讨如何建造时间机器
  8. spring框架Annotation之CRUD
  9. [网路]Pads 2007常见问题备份解答
  10. (226)FPGA入门推荐书籍
  11. 无人机巡检系统设想路线
  12. 3dsmax如何批量导入obj格式文件
  13. Oracle备份与恢复-误删数据文件恢复(非归档模式)
  14. windows Delete键和Backspace键的区别
  15. Codeforces894A QAQ
  16. 如何读一个在职在线的海外名校的计算机硕士
  17. 寻仙服务器维护到几点,寻仙10月14日上午服务器例行维护公告
  18. 调焦后焦实现不同距离成像_分辨率、调焦和景深
  19. C#模拟按键的一种实现方法
  20. pgSQL查询语句ERROR: relation “XXX“ does not exist

热门文章

  1. Apache关联Weblogic启动时爆错!libstdc++.so.5
  2. java实现上传zip/rar压缩文件,自动解压
  3. 手机充值了还是显示无服务器,手机显示已联网,但却不能用,怎么办?
  4. Next FlipBook Maker Pro(h5电子书翻页效果制作软件)官方正式版V2.7.20 | h5翻页杂志制作软件下载
  5. lsdyna如何设置set中的node_list_为 Windows PowerShell 设置 User Alias (命令别名)
  6. JavaScript常用的字符串操作对象方法
  7. ROS远程连接Turtlebot3并进行简单的移动控制
  8. 下载网页中的视频(m3u8文件下载,仅供交流学习)
  9. anki怎么设置学习计划_Anki:用这套记忆卡片,学习一切你背不下来的知识 #iOS #Android #PC...
  10. 图谱实战 | 再谈图谱表示:图网络表示GE与知识图谱表示KGE的原理对比与实操效果分析...