pleriche / FastMM5

FastMM is a fast replacement memory manager for Embarcadero Delphi applications that scales well across multiple threads and CPU cores, is not prone to memory fragmentation, and supports shared memory without the use of external .DLL files.
283 stars 73 forks source link

FastMM_LogStateToFile, sort by class also #43

Closed HHasenack closed 7 months ago

HHasenack commented 7 months ago

Hello Pierre

I use FastMM_LogStateToFile yto create "snapshots" of memory usage in order to find a transient memory leak (the leak is not there when app closes, but memory consumption keeps rising in between.

The output is sorted by the total # of bytes used by a class. Unfortuantely the classname is not used in the sorting as well, which makes it very hard to diff 2 different snapshots in case the (total) memory usage for classes are the same.

Can you add the class-name-based sorting as 2nd prio after the total memory usage of a class? This makes the diff much more readable.

I have looked into the FastMM5 source but didnt see a quick-and-easy way to accomplish this, and I'd rather not mess with code I dont fully understand 🦺 .

example output:

snapshot 1: .... 766 bytes: SVGIconImage.TSVGIconImage x 1 (766 bytes avg.) 766 bytes: uSGScrollBox.TSGScrollBox x 1 (766 bytes avg.) 766 bytes: Vcl.DBCtrls.TDBImage x 1 (766 bytes avg.) 766 bytes: uSGHintWindowVCL.TSGHintWIndow x 1 (766 bytes avg.) ....

snapshot 2: .... 766 bytes: SVGIconImage.TSVGIconImage x 1 (766 bytes avg.) 766 bytes: Vcl.DBCtrls.TDBImage x 1 (766 bytes avg.) 766 bytes: uSGHintWindowVCL.TSGHintWIndow x 1 (766 bytes avg.) 766 bytes: uSGScrollBox.TSGScrollBox x 1 (766 bytes avg.) ....

Regards - Hans (Licensed user S&G asset management)

pleriche commented 7 months ago

Hi Hans,

I have added a sort order parameter to FastMM_LogStateToFile, so you can choose whether you want the output sorted alphabetically, or in descending total memory usage. The default sort order remains descending total memory usage, but nodes that sort equally by size will now be sorted alphabetically.

Best regards, Pierre

HHasenack commented 7 months ago

Wow, thats faaaaast service, thx pierre!

Any way, would this be the right way to find a "delta" of the memory usage, or can you think of a better way to find out "transient" memory leaks between calls to rather complicated code?

pleriche commented 7 months ago

If you're trying to identify leaks in a specific block of code I would set FastMM_CurrentAllocationGroup to a unique value on entry to that block and then reset it on exit. You can then filter FastMM_WalkBlocks or FastMM_LogStateToFile on that allocation group to pinpoint issues in that block of code.