0

I'm using callgrind in order to profile a C++ program. The program has a very complex main method (which solves an NP-complete problem), and with large problems it becomes the main resource hogger of the application (96% of time in this one method of approximately 120 lines).

While I don't expect miracles as the problem is hard, the method spends 60% of its time making allocations/deallocations. Thus, I wanted to try to understand where/how exactly the memory was being requested so that I can decide if there is a better way to implement it.

Callgrind however does not seem to be able to give me this information. Is there any way I could obtain it? I'm on Linux, and I'm not using an IDE (just vim and g++).

EDIT: I've looked at the suggested duplicate question (track C++ memory allocations). However, it doesn't look like it's what I need, unless I am misunderstanding. Massif looks like a tool to track memory usage; the memory usage of my application is relatively constant (around 1MB total max), but I have constant small allocations/deallocations that I don't know the origin, only the general whereabouts. I don't care about who has my memory in a given snapshot, I care about who keeps allocating and deallocating all the time. Can Massif be used to track these?

Svalorzen
  • 5,353
  • 3
  • 30
  • 54
  • It should proved you with line numbers. Are you compiling with the `-g` flag? – kabanus Apr 03 '19 at 18:36
  • @kabanus Using callgrind I get the names of the functions and the call graph; but not the line numbers of where the calls are made. Massif does give me that, but since it does snapshots it doesn't look like it can help detecting where there are many allocations/deallocations in series while memory usage is relatively constant. – Svalorzen Apr 04 '19 at 14:10
  • If the dup-target Nathan marked does not solve your problem, address that in your question, and ping him to get your question re-opened. – kabanus Apr 04 '19 at 17:33

0 Answers0