0

Is it possible to set a breakpoint immediately before GC collects gen2, using windbg?
The following breaks after GC, how can I change it to work for my needs:

bp clr!ThreadSuspend::RestartEE ".if (dwo(clr!SVR::GCHeap::GcCondemnedGeneration)==2) {kb} .else {g}"

From what I understood, GcCondemnedGeneration is set only after GC finishes.
The reason I need it is to be able to !dumpgen 2 -stats and compare with a previous dump that was made immediately after the previous gen2 GC cycle.
This comparison indicates how many instances of each type have reached gen2 during a specific scenario in my application, which is my main thing I try to achieve. Any other idea to achieve this comparison is welcome.

Thanks

Simon
  • 83
  • 7
  • How about a .NET memory profiler like https://www.jetbrains.com/dotmemory/ Many companies already have a license, because it's part of R# Ultimate, they just don't know it. – Thomas Weller Apr 27 '20 at 15:27
  • Does https://stackoverflow.com/questions/31188494/how-to-break-on-garbage-collection still work? – Thomas Weller Apr 27 '20 at 15:31
  • Hi Thomas, I'm not aware whether dotmemory supports this functionality of dumping the heap immediately before GC on a specific generation. As for link you provided, I'm familiar with GarbageCollect function but unfortunately it breaks on GCs made on any of the generations, while I need to break before gen2 GC. The thing is, my process has many gen0 and gen1 cycles until it needs to do gen2. – Simon Apr 28 '20 at 10:01
  • I see. I have dotMemory, so I can try different scenarios. Is it possible for you to create a [mcve] which someone could use to try WinDbg and/or profilers? Just some example program that behaves roughly as your real program does? – Thomas Weller Apr 28 '20 at 11:49
  • I could but it will take some time and I'm not sure how it will be beneficial. I need to know how many instances of every type are promoted to Gen2. Trying to do compare memory dumps AFTER a gen2 collection will miss the point since the freed instances aren't there anymore. My service I'm debugging is a production web service with many modules and it consumes 60GB RAM due to the heavy data it loads. I'm trying to locate the places where the code don't reuse the data structures correctly and I think the method I presented is the only one. Let me know what you think. – Simon Apr 30 '20 at 07:50
  • I requested the MRE just because I don't have a small application available which produces enough objects or which is long-lived enough to trigger a Gen 2 collection. I also don't want to use any arbitrary .NET program, because it might take many steps to trigger a Gen 2 collection. Maybe I need 10 attempts to find the right steps in WinDbg. I want to focus on the debugging part, not on the application part. It can really be just a few lines. Take this as an example: https://stackoverflow.com/a/30361185/480982 – Thomas Weller Apr 30 '20 at 09:14

0 Answers0