Brainstorming: ASAN snapshots

Hi all,

I'm debugging a memory leak in a large code base, and it's not going
very well. Let's say I have plenty of time to think about other
things.

I was wondering if it would be possible to use the sanitizer
infrastructure to generate memory usage snapshots, something like a
report mapping allocation backtrace to number of outstanding
allocations.

With something like that in place, it should be easy to catch leaks
where memory is still reachable but kept alive indefinitely. Take two
snapshots and diff -- the backtraces growing in outstanding
allocations are prime suspects. I think gperftools/tcmalloc has a mode
like this, but I haven't used it myself.

Is this at all feasible? Are patches welcome? I can't say I understand
ASAN very well, but it feels like there is basic infrastructure
already in place for this.

Thanks,
- Kim

Hi all,

I'm debugging a memory leak in a large code base, and it's not going
very well. Let's say I have plenty of time to think about other
things.

I was wondering if it would be possible to use the sanitizer
infrastructure to generate memory usage snapshots, something like a
report mapping allocation backtrace to number of outstanding
allocations.

With something like that in place, it should be easy to catch leaks
where memory is still reachable but kept alive indefinitely. Take two
snapshots and diff -- the backtraces growing in outstanding
allocations are prime suspects. I think gperftools/tcmalloc has a mode
like this, but I haven't used it myself.

Is this at all feasible?

Yes. Take a look at lib/asan/asan_memory_profile.cc and
test/asan/TestCases/Linux/print_memory_profile_test.cc
It's a toy memory profiler which prints the current allocated memory
chunks.
Very close to what you are describing (if not exactly that)

I used this functionality myself in a situation similar to yours and it
helped.

Are patches welcome?

It depends. I am currently not ready to review large refactoring in this
code because
I hope to make one myself (maybe...)
Small incremental improvements -- yes.

--kcc

Is this at all feasible?

Yes. Take a look at lib/asan/asan_memory_profile.cc and
test/asan/TestCases/Linux/print_memory_profile_test.cc
It's a toy memory profiler which prints the current allocated memory chunks.
Very close to what you are describing (if not exactly that)

I used this functionality myself in a situation similar to yours and it
helped.

Cool, thanks. I'll see if I can connect the dots locally.

Are patches welcome?

It depends. I am currently not ready to review large refactoring in this
code because I hope to make one myself (maybe...)
Small incremental improvements -- yes.

Realistically, I probably won't have time to work on this enough to
build something useful outside of my office, but it's nice to know
there's mechanics for this sort of thing.

Thanks,
- Kim

>
>>
>> Is this at all feasible?
>
>
> Yes. Take a look at lib/asan/asan_memory_profile.cc and
> test/asan/TestCases/Linux/print_memory_profile_test.cc
> It's a toy memory profiler which prints the current allocated memory
chunks.
> Very close to what you are describing (if not exactly that)
>
> I used this functionality myself in a situation similar to yours and it
> helped.

Cool, thanks. I'll see if I can connect the dots locally.

>> Are patches welcome?
>
> It depends. I am currently not ready to review large refactoring in this
> code because I hope to make one myself (maybe...)
> Small incremental improvements -- yes.

Realistically, I probably won't have time to work on this enough to
build something useful outside of my office, but it's nice to know
there's mechanics for this sort of thing.

Please let us know if you've found this useful and/or if you needed some
improvements.
Currently, this functionality exists mostly because I needed it myself.
It would great to make it more generally useful.

--kcc