How to display symbols in stack trace of google-perftools heap profiler - google-perftools

We're using google-perftools heap profiler in a TDD environment. We get the heap dump at the end that we can use pprof to see the hot spots. It shows the symbols but gives little to no information about how the leak is reached in the stack. In fact, there's no organization in the output that I can see whatsoever.
The stack trace of the largest leak is displayed at runtime but does not show any symbols. We're correctly setting the PPROF_PATH environment variable but it's not having any effect. How can we enable this?

Related

Valgrind shows memory leak but no memory allocation took place

this is a rather simple question.
In my school we use a remote CentOS server to compile and test our programs. For some reason, valgrind always shows a 4096B leak in spite of the fact that no malloc was used. Does anyone here have any idea where this problem might stem from?
Your program makes a call to printf. This library might allocate memory for its own usage. More generally, depending on the OS/libc/..., various allocations might be done just to start a program.
Note also that in this case, you see that there is one block still allocated at exit, and that this block is part of the suppressed count. That means that valgrind suppression file already ensures that this memory does not appear in the list of leaks to be examined.
In summary: no problem.
In any case, when you suspect you have a leak, you can look at the details of the leaks e.g. their allocation stack trace to see if these are triggered by your application.
In addition to #phd's answer, there are a few things you can do to see more clearly what is going on.
If you run Valgrind with -s or -v it will show details of the suppressions used.
You can use --trace-malloc=yes to see all calls to allocation functions (only do that for small applications). Similarly you can run with --default-suppressions=no and than you will see the details of the memory (with --leak-check=full --show-reachable=yes in this case)
Finally, are you using an old Centos / GNU libc? A few years ago Valgrind got a mechanism to cleanup things like io buffers so you shouldn't get this sort of message with recent Valgrind and recent Linux + libc.

Multithreaded 64 bit process goes "Out of memory"

I have memory and CPU intensive application which runs several hundred concurrent threads that do text processing. There is a lot of going on in background, processing files, logging to disk, and so on. Application is compiled for x64 platform, under XE2.
Occassionaly, it crashes, and I've been trying to debug this issue for a few days, but without success. Here is the bug report: http://pastebin.com/raw.php?i=sSUXCznT
I tried running it under debugger and it reports Out of Memory exception after a while. At the point of crash, it was using 670mb of RAM, and machine has 32gb total RAM.
I was thinking it may be fragmentation, but if I'm understanding this bug report correctly, it says largest free block : 8185.75 GB, which indicates that fragmentation isn't the issue here.
Application isn't leaking memory anywhere (atleast that I know of), I have ReportMemoryLeaksOnShutdown enabled and it works fine.
Since I don't have any other ideas why it would crash with Out of memory exception, I would like to get some hints so I can get on the right path to fix this.
Try setting a breakpoint in System.pas procedure Error(errorCode: TRuntimeError);. Your Application should stop there when the out of memory happens. When you get there, skip the ErrorAt function (by using Debug->"Set next statement" in the context menu). That will silently ignore the exception so you can debug the call stack easier. Leave the functions with F7 until you have a useful stack trace.

how to display top heap allocations grouped by stack?

I have a dump of a process that was running with user-stack-traces flag on. I am trying to analyze a leak from WinDbg. Using instructions here I am able to see top allocations grouped by allocation sizes, list all allocations with specific size, display stack of an allocation using allocation address.
Is there a way to display top allocations grouped by stack? (By 'top' I mean highest contributors to total heap size or total allocation count.) All the information is already in the dump, I just need the right WinDbg extension. I would be surprised if no one wrote such an extension so far.

Finding allocation site for double-free errors (with valgrind)

Given a double-free error (reported by valgrind), is there a way to find out where the memory was allocated? Valgrind only tells me the location of the deallocation site (i.e. the call to free()), but I would like to know where the memory was allocated.
To get Valgrind keep tracks of allocation stack traces, you have to use options:
--track-origins=yes --keep-stacktraces=alloc-and-free
Valgrind will then report allocation stack under Block was alloc'd at section, just after Address ... inside a block of size x free'd alert.
In case your application is large, --error-limit=no --num-callers=40 options may be useful too.
The first check I would do is verifying that the error is indeed due to a double-free error. Sometimes, running a program (including with valgrind) can show a double-free error while in reality, it's a memory corruption problem (for example a memory overflow).
The best way to check is to apply the advice detailed in the answers : How to track down a double free or corruption error in C++ with gdb.
First of all, you can try to compile your program with flags fsanitize=address -g. This will instrument the memory of the program at runtime to keep track of all allocations, detect overflows, etc.
In any case, if the problem is indeed a double-free, the error message should contain all the necessary information for you to debug the problem.

How can I use valgrind for memory profile

Can you please tell me how can I use valgrind for memory profile?
The article I found from google talks about how to use valgrind for memory leak. I am interested in how to use that for memory profiling (i.e. how much memory is used by what classes)?
Thank you.
You can use valgrind's Massif tool to get a heap profile. This code is still labelled "experimental", and it does not ship with all versions of valgrind. You may have to download and build from source.
Also note that the heap profile is organized by allocation site, which is a finer granularity than classes. If you need information organized by class, you will have to read the developer documentation and get the machine-readable format, then figure out which allocation sites go with which classes - perhaps with support from your compiler.
Even without support for classes, however, the Massif profile may be useful.

Resources