|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +#include "enumthreadsprofiler.h" |
| 5 | + |
| 6 | +GUID EnumThreadsProfiler::GetClsid() |
| 7 | +{ |
| 8 | + // {0742962D-2ED3-44B0-BA84-06B1EF0A0A0B} |
| 9 | + GUID clsid = { 0x0742962d, 0x2ed3, 0x44b0,{ 0xba, 0x84, 0x06, 0xb1, 0xef, 0x0a, 0x0a, 0x0b } }; |
| 10 | + return clsid; |
| 11 | +} |
| 12 | + |
| 13 | +HRESULT EnumThreadsProfiler::Initialize(IUnknown* pICorProfilerInfoUnk) |
| 14 | +{ |
| 15 | + Profiler::Initialize(pICorProfilerInfoUnk); |
| 16 | + printf("EnumThreadsProfiler::Initialize\n"); |
| 17 | + |
| 18 | + HRESULT hr = S_OK; |
| 19 | + if (FAILED(hr = pCorProfilerInfo->SetEventMask2(COR_PRF_MONITOR_GC | COR_PRF_MONITOR_SUSPENDS, COR_PRF_HIGH_MONITOR_NONE))) |
| 20 | + { |
| 21 | + printf("FAIL: ICorProfilerInfo::SetEventMask2() failed hr=0x%x", hr); |
| 22 | + IncrementFailures(); |
| 23 | + } |
| 24 | + |
| 25 | + return hr; |
| 26 | +} |
| 27 | + |
| 28 | +HRESULT STDMETHODCALLTYPE EnumThreadsProfiler::GarbageCollectionStarted(int cGenerations, BOOL generationCollected[], COR_PRF_GC_REASON reason) |
| 29 | +{ |
| 30 | + SHUTDOWNGUARD(); |
| 31 | + |
| 32 | + printf("EnumThreadsProfiler::GarbageCollectionStarted\n"); |
| 33 | + _gcStarts.fetch_add(1, std::memory_order_relaxed); |
| 34 | + if (_gcStarts < _gcFinishes) |
| 35 | + { |
| 36 | + IncrementFailures(); |
| 37 | + printf("EnumThreadsProfiler::GarbageCollectionStarted: FAIL: Expected GCStart >= GCFinish. Start=%d, Finish=%d\n", (int)_gcStarts, (int)_gcFinishes); |
| 38 | + } |
| 39 | + |
| 40 | + return S_OK; |
| 41 | +} |
| 42 | + |
| 43 | +HRESULT STDMETHODCALLTYPE EnumThreadsProfiler::GarbageCollectionFinished() |
| 44 | +{ |
| 45 | + SHUTDOWNGUARD(); |
| 46 | + |
| 47 | + printf("EnumThreadsProfiler::GarbageCollectionFinished\n"); |
| 48 | + _gcFinishes.fetch_add(1, std::memory_order_relaxed); |
| 49 | + if (_gcStarts < _gcFinishes) |
| 50 | + { |
| 51 | + IncrementFailures(); |
| 52 | + printf("EnumThreadsProfiler::GarbageCollectionFinished: FAIL: Expected GCStart >= GCFinish. Start=%d, Finish=%d\n", (int)_gcStarts, (int)_gcFinishes); |
| 53 | + } |
| 54 | + |
| 55 | + return S_OK; |
| 56 | +} |
| 57 | + |
| 58 | +HRESULT STDMETHODCALLTYPE EnumThreadsProfiler::RuntimeSuspendFinished() |
| 59 | +{ |
| 60 | + SHUTDOWNGUARD(); |
| 61 | + |
| 62 | + printf("EnumThreadsProfiler::RuntimeSuspendFinished\n"); |
| 63 | + |
| 64 | + ICorProfilerThreadEnum* threadEnum = nullptr; |
| 65 | + HRESULT enumThreadsHR = pCorProfilerInfo->EnumThreads(&threadEnum); |
| 66 | + printf("Finished enumerating threads\n"); |
| 67 | + _profilerEnumThreadsCompleted.fetch_add(1, std::memory_order_relaxed); |
| 68 | + threadEnum->Release(); |
| 69 | + return enumThreadsHR; |
| 70 | +} |
| 71 | + |
| 72 | +HRESULT EnumThreadsProfiler::Shutdown() |
| 73 | +{ |
| 74 | + Profiler::Shutdown(); |
| 75 | + |
| 76 | + if (_gcStarts == 0) |
| 77 | + { |
| 78 | + printf("EnumThreadsProfiler::Shutdown: FAIL: Expected GarbageCollectionStarted to be called\n"); |
| 79 | + } |
| 80 | + else if (_gcFinishes == 0) |
| 81 | + { |
| 82 | + printf("EnumThreadsProfiler::Shutdown: FAIL: Expected GarbageCollectionFinished to be called\n"); |
| 83 | + } |
| 84 | + else if (_profilerEnumThreadsCompleted == 0) |
| 85 | + { |
| 86 | + printf("EnumThreadsProfiler::Shutdown: FAIL: Expected RuntimeSuspendFinished to be called and EnumThreads completed\n"); |
| 87 | + } |
| 88 | + else if(_failures == 0) |
| 89 | + { |
| 90 | + printf("PROFILER TEST PASSES\n"); |
| 91 | + } |
| 92 | + else |
| 93 | + { |
| 94 | + // failures were printed earlier when _failures was incremented |
| 95 | + } |
| 96 | + fflush(stdout); |
| 97 | + |
| 98 | + return S_OK; |
| 99 | +} |
| 100 | + |
| 101 | +void EnumThreadsProfiler::IncrementFailures() |
| 102 | +{ |
| 103 | + _failures.fetch_add(1, std::memory_order_relaxed); |
| 104 | +} |
0 commit comments