sob
sob

Reputation: 1088

Debugging memory allocation with glibc-2.22

I am working on a custom embedded Linux distribution, libc is glibc-2.22.

How to track memory allocations/frees for an application while the application runs in automation for long duration. Are there hooks in glibc that will generate logs each time an allocation/free happens in my application?

Upvotes: 0

Views: 908

Answers (2)

Florian Weimer
Florian Weimer

Reputation: 33727

There is a glibc branch with a high-performance allocation tracer:

It's still a bit rough, but it has been used with some degree of success with multi-threaded, allocation-intense workloads.

Upvotes: 0

Employed Russian
Employed Russian

Reputation: 213877

Are there hooks in glibc that will generate logs each time an allocation/free happens in my application?

No. Writing to log on every allocation would be

  • too expensive (a high performance malloc can allocate memory in a few 10s of instructions and without any system calls)
  • mostly useless: usually you don't just want to know that 2000 bytes where allocated; you also want to know where they were allocated from, and that is definitely too slow to perform on every allocation in a production application.

Your requirements are not unique: e.g. Google runs applications for many days, and developers often want to know how much memory is being consumed by which parts (when you run 100s of 1000s of applications, a wasted MB here and there quickly adds up).

To this end, tcmalloc comes with heap profiler, which can answer many of above questions. So does jemalloc as well.

Upvotes: 0

Related Questions