locked
Get loaded class details - CLR profiler RRS feed

  • Question

  • In my .Net CLR Profiler(using corprofiler),I have collected the class details(classid,classname) using NativeCallback::ClassLoadFinished(ClassID classID, HRESULT hrStatus) callback method.

    NativeCallback::ObjectReferences(ObjectID objectId, ClassID classId,ULONG cObjectRefs, ObjectID objectRefIds[]) callback method also says each object remaining in the heap after a garbage collection has completed.

    Strangely , the class Id that i receive in the ObjectReferences call back has not come in ClassLoadStarted or in ClassLoadFinished methods. I was guessing (as documented) all the classes that comes in ObjectReferences must have come in ClassLoadStarted/Finished. But i get some new class Ids(that was not reported in ClassLoadStarted/Finished) too in ObjectReferences.

    How that happens? To get the number of classes loaded by CLR which callback should i take? 

    Should i consolidate the class id's that i receive in ObjectReferences and ClassLoadStarted/Finished ..?


    Tuesday, July 18, 2017 7:28 AM

Answers

  • In GC finished i have get the class details from the map. Now, ObjectReferences map has the more class details than ClassLoadFinished map.

    i.e ,(ObjectReferencesmap size >ClassLoadFinishedmap size).

    Apparently the ClassLoadFinished callback is unreliable for classes defined in NGENed assemblies. Unfortunately I have not been able to find any details on this. You can confirm if this is the cause of what you are seeing by disabling NGENed images (COR_PRF_DISABLE_ALL_NGEN_IMAGES).

    I have small doubt on this,
    1. In the above two methods,which callback method calling at first? i thought ClassLoadFinished.
    2. ObjectReferences callback methods uses the classid as argument which is already loaded(ClassLoadFinished)? or any other chance to come directly?

    3. which is the better method to collect loaded class details without missing anyone?

    I believe there is a potential race between ClassLoadFinished and ObjectAllocated, but also getting a GC in before the ClassLoadFinished might be a bit of a stretch. In any case, the ClassID cannot be used for information requests until the ClassLoadFinished callback; so if you do happen to get the ObjectReferences callback before the ClassLoadFinished callback, all you can really do is note that you want the details and collect them when the ClassLoadFinished callback comes.

    https://blogs.msdn.microsoft.com/davbr/2011/10/17/metadata-tokens-run-time-ids-and-type-loading/


    Tuesday, July 18, 2017 12:53 PM

All replies

  • In GC finished i have get the class details from the map. Now, ObjectReferences map has the more class details than ClassLoadFinished map.

    i.e ,(ObjectReferencesmap size >ClassLoadFinishedmap size).

    Apparently the ClassLoadFinished callback is unreliable for classes defined in NGENed assemblies. Unfortunately I have not been able to find any details on this. You can confirm if this is the cause of what you are seeing by disabling NGENed images (COR_PRF_DISABLE_ALL_NGEN_IMAGES).

    I have small doubt on this,
    1. In the above two methods,which callback method calling at first? i thought ClassLoadFinished.
    2. ObjectReferences callback methods uses the classid as argument which is already loaded(ClassLoadFinished)? or any other chance to come directly?

    3. which is the better method to collect loaded class details without missing anyone?

    I believe there is a potential race between ClassLoadFinished and ObjectAllocated, but also getting a GC in before the ClassLoadFinished might be a bit of a stretch. In any case, the ClassID cannot be used for information requests until the ClassLoadFinished callback; so if you do happen to get the ObjectReferences callback before the ClassLoadFinished callback, all you can really do is note that you want the details and collect them when the ClassLoadFinished callback comes.

    https://blogs.msdn.microsoft.com/davbr/2011/10/17/metadata-tokens-run-time-ids-and-type-loading/


    Tuesday, July 18, 2017 12:53 PM
  • Hi brain,

    After I set the mask COR_PRF_DISABLE_ALL_NGEN_IMAGES, I got more class details in ClassLoadFinished/ClassLoadstarted callback. Except the array of classes.

    For example,

    I got these details from objectreference callback method.

    classes ID :140730921429426
    className :System.String[]
    -------------------
    classes ID :140730923282490
    className :System.Collections.Hashtable+bucket[]
    -------------------
    classes ID :140730921408530
    className :System.Object[]
    -------------------

    can you clarify me, why this classes not loaded? 


    Thursday, July 20, 2017 12:54 PM