Skip to content

Commit

Permalink
Fix profiling objectsallocatedbyclass (#63814) (#64284)
Browse files Browse the repository at this point in the history
* Add test for ObjectsAllocatedByClass profiler callbacks

* Fix ObjectsAllocatedByClass profiler callbacks based on wrong flag

* Fix wrong args in test log

Co-authored-by: Olivier Giniaux <oginiaux@smartadserver.com>

Co-authored-by: Olivier Giniaux <oginiaux@gmail.com>
Co-authored-by: Olivier Giniaux <oginiaux@smartadserver.com>
  • Loading branch information
3 people authored Feb 7, 2022
1 parent 78ca1be commit 3535b89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/coreclr/vm/proftoeeinterfaceimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ bool AllocByClassHelper(Object * pBO, void * pv)
_ASSERTE(pv != NULL);

{
BEGIN_PROFILER_CALLBACK(CORProfilerTrackAllocations());
BEGIN_PROFILER_CALLBACK(CORProfilerTrackGC());
// Pass along the call
g_profControlBlock.AllocByClass(
(ObjectID) pBO,
Expand Down
18 changes: 18 additions & 0 deletions src/tests/profiler/native/gcprofiler/gcprofiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ HRESULT GCProfiler::Shutdown()
{
printf("GCProfiler::Shutdown: FAIL: Expected GarbageCollectionFinished to be called\n");
}
else if (_allocatedByClassCalls == 0)
{
printf("GCProfiler::Shutdown: FAIL: Expected ObjectsAllocatedByClass to be called\n");
}
else if (_pohObjectsSeenRootReferences == 0 || _pohObjectsSeenObjectReferences == 0)
{
printf("GCProfiler::Shutdown: FAIL: no POH objects seen. root references=%d object references=%d\n",
Expand Down Expand Up @@ -86,6 +90,20 @@ HRESULT GCProfiler::GarbageCollectionFinished()
return S_OK;
}

HRESULT GCProfiler::ObjectsAllocatedByClass(ULONG cClassCount, ClassID classIds[], ULONG cObjects[])
{
SHUTDOWNGUARD();

_allocatedByClassCalls++;
if (_gcStarts != _allocatedByClassCalls)
{
_failures++;
printf("GCProfiler::ObjectsAllocatedByClass: FAIL: Expected ObjectsAllocatedByClass Calls == GCStart. AllocatedByClassCalls=%d, GCStart=%d\n", (int)_allocatedByClassCalls, (int)_gcStarts);
}

return S_OK;
}

HRESULT GCProfiler::ObjectReferences(ObjectID objectId, ClassID classId, ULONG cObjectRefs, ObjectID objectRefIds[])
{
SHUTDOWNGUARD();
Expand Down
3 changes: 3 additions & 0 deletions src/tests/profiler/native/gcprofiler/gcprofiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GCProfiler : public Profiler
GCProfiler() : Profiler(),
_gcStarts(0),
_gcFinishes(0),
_allocatedByClassCalls(0),
_failures(0),
_pohObjectsSeenRootReferences(0),
_pohObjectsSeenObjectReferences(0),
Expand All @@ -28,12 +29,14 @@ class GCProfiler : public Profiler
virtual HRESULT STDMETHODCALLTYPE Shutdown();
virtual HRESULT STDMETHODCALLTYPE GarbageCollectionStarted(int cGenerations, BOOL generationCollected[], COR_PRF_GC_REASON reason);
virtual HRESULT STDMETHODCALLTYPE GarbageCollectionFinished();
virtual HRESULT STDMETHODCALLTYPE ObjectsAllocatedByClass(ULONG cClassCount, ClassID classIds[], ULONG cObjects[]);
virtual HRESULT STDMETHODCALLTYPE ObjectReferences(ObjectID objectId, ClassID classId, ULONG cObjectRefs, ObjectID objectRefIds[]);
virtual HRESULT STDMETHODCALLTYPE RootReferences(ULONG cRootRefs, ObjectID rootRefIds[]);

private:
std::atomic<int> _gcStarts;
std::atomic<int> _gcFinishes;
std::atomic<int> _allocatedByClassCalls;
std::atomic<int> _failures;
std::atomic<int> _pohObjectsSeenRootReferences;
std::atomic<int> _pohObjectsSeenObjectReferences;
Expand Down

0 comments on commit 3535b89

Please sign in to comment.