cuitao2046 / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

DumpAddressMap() may not completely dump /proc/self/maps #281

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Prepare a binary which when run produces a size in /proc/self/maps that's 
larger than 10240.
2. Call method MallocExtension::instance()->GetHeapSample().
3. The above method appends the content of /proc/self/maps in its output - 
compare against the actual data in /proc/self/maps.

What is the expected output? What do you see instead?

The output of MallocExtension::instance()->GetHeapSample() is expected to 
contain /proc/self/maps completely. In reality, it only contains enough that 
fits in 10240 bytes.

What version of the product are you using? On what operating system?

1.6. Ubuntu 10.10.

Please provide any additional information below.

The bug is in function DumpAddressMap() in malloc_extension.cc. Here is the 
relevant code:

  for (int amap_size = 10240; amap_size < 10000000; amap_size *= 2) {
    result->resize(old_resultlen + amap_size);
    const int bytes_written =
        tcmalloc::FillProcSelfMaps(&((*result)[old_resultlen]), amap_size);
    if (bytes_written < amap_size - 1) {   // we fit!

The problem is that the call to tcmalloc::FillProcSelfMaps() does return less 
than 10240 bytes as it doesn't want to include partial lines. This makes the 
above loop think that complete data has been returned. In reality, if a larger 
amap_size had been used, the cal to FillProcSelfMaps() would have returned the 
additional lines from /proc/self/maps.

As a result of this bug, pprof is unable to symbolize much of the data returned 
by /pprof/heap and /pprof/growth. It prints them as raw addresses.

Original issue reported on code.google.com by mohit.a...@gmail.com on 6 Nov 2010 at 9:57

GoogleCodeExporter commented 9 years ago
Yes, you are right.  I'll fix this for the next release.

I've attached a patch.  Can you check if it fixes things for you in the problem 
situation you were seeing?

Original comment by csilv...@gmail.com on 9 Nov 2010 at 4:59

Attachments:

GoogleCodeExporter commented 9 years ago

Yes, this fixes it.

Original comment by mohit.a...@gmail.com on 15 Nov 2010 at 6:10

GoogleCodeExporter commented 9 years ago
This should be fixed in perftools 1.7, just released.

Original comment by csilv...@gmail.com on 5 Feb 2011 at 12:23