Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
added a lightweight GC profiling option
Browse files Browse the repository at this point in the history
  • Loading branch information
Maoni0 committed Feb 27, 2019
1 parent d056831 commit 17d3f2c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/inc/corprof.idl
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,13 @@ typedef enum

COR_PRF_HIGH_DISABLE_TIERED_COMPILATION = 0x00000008,

COR_PRF_HIGH_BASIC_GC = 0x00000010,

COR_PRF_HIGH_REQUIRE_PROFILE_IMAGE = 0,

COR_PRF_HIGH_ALLOWABLE_AFTER_ATTACH = COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED | COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS,
COR_PRF_HIGH_ALLOWABLE_AFTER_ATTACH = COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED |
COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS |
COR_PRF_HIGH_BASIC_GC,

// MONITOR_IMMUTABLE represents all flags that may only be set during initialization.
// Trying to change any of these flags elsewhere will result in a
Expand Down
14 changes: 14 additions & 0 deletions src/inc/profilepriv.inl
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,20 @@ inline BOOL CORProfilerDisableTieredCompilation()
((&g_profControlBlock)->dwEventMaskHigh & COR_PRF_HIGH_DISABLE_TIERED_COMPILATION));
}

inline BOOL CORProfilerTrackBasicGC()
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
CANNOT_TAKE_LOCK;
}
CONTRACTL_END;

return (CORProfilerPresent() &&
((&g_profControlBlock)->dwEventMaskHigh & COR_PRF_HIGH_BASIC_GC));
}

#if defined(PROFILING_SUPPORTED) && !defined(CROSSGEN_COMPILE)

#if defined(FEATURE_PROFAPI_ATTACH_DETACH)
Expand Down
3 changes: 2 additions & 1 deletion src/pal/prebuilt/inc/corprof.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,9 @@ enum __MIDL___MIDL_itf_corprof_0000_0000_0006
COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED = 0x2,
COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS = 0x4,
COR_PRF_HIGH_DISABLE_TIERED_COMPILATION = 0x8,
COR_PRF_HIGH_BASIC_GC = 0x10,
COR_PRF_HIGH_REQUIRE_PROFILE_IMAGE = 0,
COR_PRF_HIGH_ALLOWABLE_AFTER_ATTACH = ( COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED | COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS ) ,
COR_PRF_HIGH_ALLOWABLE_AFTER_ATTACH = ( COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED | COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS | COR_PRF_HIGH_BASIC_GC) ,
COR_PRF_HIGH_MONITOR_IMMUTABLE = COR_PRF_HIGH_DISABLE_TIERED_COMPILATION
} COR_PRF_HIGH_MONITOR;

Expand Down
9 changes: 8 additions & 1 deletion src/vm/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,17 +742,24 @@ void GCToEEInterface::DiagGCStart(int gen, bool isInduced)
void GCToEEInterface::DiagUpdateGenerationBounds()
{
#ifdef GC_PROFILING
if (CORProfilerTrackGC())
if (CORProfilerTrackGC() || CORProfilerTrackBasicGC())
UpdateGenerationBounds();
#endif // GC_PROFILING
}

void GCToEEInterface::DiagGCEnd(size_t index, int gen, int reason, bool fConcurrent)
{
#ifdef GC_PROFILING
// We were only doing generation bounds and GC finish callback for non concurrent GCs so
// I am keeping that behavior to not break profilers. But if BasicGC monitoring is enabled
// we will do these for all GCs.
if (!fConcurrent)
{
GCProfileWalkHeap();
}

if (CORProfilerTrackBasicGC() || (!fConcurrent && CORProfilerTrackGC()))
{
DiagUpdateGenerationBounds();
GarbageCollectionFinishedCallback();
}
Expand Down
6 changes: 3 additions & 3 deletions src/vm/proftoeeinterfaceimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ void __stdcall GarbageCollectionStartedCallback(int generation, BOOL induced)

// Notify the profiler of start of the collection
{
BEGIN_PIN_PROFILER(CORProfilerTrackGC());
BEGIN_PIN_PROFILER(CORProfilerTrackGC() || CORProfilerTrackBasicGC());
BOOL generationCollected[COR_PRF_GC_LARGE_OBJECT_HEAP+1];
if (generation == COR_PRF_GC_GEN_2)
generation = COR_PRF_GC_LARGE_OBJECT_HEAP;
Expand Down Expand Up @@ -718,7 +718,7 @@ void __stdcall GarbageCollectionFinishedCallback()
#ifdef PROFILING_SUPPORTED
// Notify the profiler of end of the collection
{
BEGIN_PIN_PROFILER(CORProfilerTrackGC());
BEGIN_PIN_PROFILER(CORProfilerTrackGC() || CORProfilerTrackBasicGC());
g_profControlBlock.pProfInterface->GarbageCollectionFinished();
END_PIN_PROFILER();
}
Expand Down Expand Up @@ -858,7 +858,7 @@ void __stdcall UpdateGenerationBounds()

#ifdef PROFILING_SUPPORTED
// Notify the profiler of start of the collection
if (CORProfilerTrackGC())
if (CORProfilerTrackGC() || CORProfilerTrackBasicGC())
{
// generate a new generation table
GenerationTable *newGenerationTable = new (nothrow) GenerationTable();
Expand Down

0 comments on commit 17d3f2c

Please sign in to comment.