Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix profiling objectsallocatedbyclass #63814

Merged
merged 3 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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