Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest way to find which data types are most garbage collected?

I've looked around a little at the explanations of profiling but I'm not seeing a way to get straight at which data types are being garbage collected the most. Is there a way to do that?

Some of our code is running 50% or even 80% in the garbage collector, so... trying to track down what data types are being garbaged.

like image 806
mentics Avatar asked Mar 23 '11 19:03

mentics


People also ask

Which method is used for garbage collection?

The gc() method is used to invoke the garbage collector to perform cleanup processing. The gc() is found in System and Runtime classes.

What is garbage collection data?

Garbage collection is a term used in computer programming to describe the process of finding and deleting objects which are no longer being referenced by other objects. In other words, garbage collection is the process of removing any objects which are not being used by any other objects.

Which of the following is example of garbage collection method?

3. Which of the following is a garbage collection technique? Explanation: A mark and sweep garbage collection consists of two phases, the mark phase and the sweep phase. I mark phase all the objects reachable by java threads, native handles and other root sources are marked alive and others are garbage.

Which part of memory is involved in garbage collection?

The managed heap After the CLR initializes the garbage collector, it allocates a segment of memory to store and manage objects. This memory is called the managed heap, as opposed to a native heap in the operating system.


1 Answers

For profiling you can add quite a few options to the app when you run it. Firstly you can add "+RTS -sstderr". This gives you the broad stats that you described so I guess you already know this!

1,835,837,744 bytes allocated in the heap
328,944,448 bytes copied during GC
2,908,728 bytes maximum residency (25 sample(s))
142,056 bytes maximum slop
9 MB total memory in use (1 MB lost due to fragmentation)

Generation 0: 3483 collections, 0 parallel, 1.54s, 1.54s elapsed
Generation 1: 25 collections, 0 parallel, 0.09s, 0.07s elapsed

INIT time 0.00s ( 0.00s elapsed)
MUT time 3.04s ( 3.13s elapsed)
GC time 1.63s ( 1.61s elapsed)
RP time 0.00s ( 0.00s elapsed)
PROF time 0.00s ( 0.00s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 4.67s ( 4.74s elapsed)
%GC time 34.9% (34.0% elapsed)
Alloc rate 603,893,994 bytes per MUT second
Productivity 65.1% of total user, 64.2% of total elapsed

As you can see from the example output above, I write some pretty bad Haskell. You can delve into this more with some additional options and improve things.

  1. -prof - Enables profiling
  2. -caf-all - Constant Applicative form for all top-level items (constant costs, one for each module.)
  3. -auto-all - Cost-centre analysis for every top-level function

Once you get the profiling information out, you can print out pretty pictures like the one below (hp2ps). This shows allocation rates. As you can see from below it's pretty simple to find the function that's doing too much work.

Picture of the allocation rate of various functions

Whilst this doesn't give per type information, it does help isolate what's happening. I found Real World Haskell to be tremendously useful.

like image 116
Jeff Foster Avatar answered Oct 16 '22 22:10

Jeff Foster