[Mono-devel-list] Profiler Idea

Paolo Molaro lupus at ximian.com
Tue Jan 13 14:55:08 EST 2004

On 01/13/04 Ben Maurer wrote:
> Recently, while doing a profile, I saw the following lines:
> >      433 KB System.String::ToCharArray(int,int)
> >          433 KB      247 System.Char[]                                   
> >   Callers (with count) that contribute at least for 1%:
> >          247  100 % System.String::ToCharArray()
> > ########################
> Now, obviously, I have seen this method before. But for the first time
> today, I reflected on how useless this data was. You get no idea *WHO*
> is calling the method.

The first part of the profile output has the call info, so you just need
to see which methods call ToCharArray(int,int).

> So, I was thinking `maybe we should make a list of common allocators
> like that that are just called by other methods.' For example, in
> Hashtable, you often get profiles like:
> >      316 KB System.Collections.Hashtable::Rehash()
> >          316 KB       29 .Slot[]                                         
> >   Callers (with count) that contribute at least for 1%:
> >           29  100 % System.Collections.Hashtable::PutImpl(object,object,bool)
> However, it is hard to track down who is causing the rehashes because
> not all calls to PutImpl cause a rehash.

It does not matter which specific call causes the rehash, since the
rehash is implementation dependent. You can just look at which method
causes the most items to be added to the hash. But usually it doesn't
make sense to reduce the number of items added to an hash table. In most
cases, instead, you should check that the hash functions are good enough
so that the keys are spread evenly over the internal array.

> So, I would like to propose the following set of changes:
>       * All allocations from System.Collections that are in the mscorlib
>         assembly shall be attributed to the first non-System.Collections
>         caller. For example, in the case of Rehash() the attribution for
>         the allocation shall go to the method which called the public
>         interface for Hashtable.

Just check in the call profile which method calls the emthods that add
things to collections.

>       * For other select methods and classes, we shall apply a similar
>         rule. For example, ToCharArray would be attributed to the method
>         that called the 0 args overload.

I don't think adding special case hacks is a good thing.
It would be better if, for each method, we could also output the total
amount of memory allocated (by the method and by the called methods as


lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better

More information about the Mono-devel-list mailing list