Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Enable earlier and disable later
  • Loading branch information
cshung committed Aug 14, 2020
commit a1f07e42be5e77326ff36c939b3a87679dc0a4fb
2 changes: 0 additions & 2 deletions src/coreclr/src/gc/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ class GCConfigStringHolder
INT_CONFIG (GCHeapHardLimitLOHPercent, "GCHeapHardLimitLOHPercent", "System.GC.HeapHardLimitLOHPercent", 0, "Specifies the GC heap LOH usage as a percentage of the total memory") \
INT_CONFIG (GCHeapHardLimitPOHPercent, "GCHeapHardLimitPOHPercent", "System.GC.HeapHardLimitPOHPercent", 0, "Specifies the GC heap POH usage as a percentage of the total memory") \
INT_CONFIG (GCEnabledInstructionSets, "GCEnabledInstructionSets", NULL, -1, "Specifies whether GC can use AVX2 or AVX512F - 0 for neither, 1 for AVX2, 3 for AVX512F")\
INT_CONFIG (GCGenAnalysisGen, "GCGenAnalysisGen", NULL, -1, "Specifies which generation to analysis") \
INT_CONFIG (GCGenAnalysisBytes, "GCGenAnalysisBytes", NULL, 0, "Specifies how much promoted bytes to trigger generation analysis") \

// This class is responsible for retreiving configuration information
// for how the GC should operate.
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/src/inc/clrconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,12 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeRundown, W("EventPipeRundown"), 1, "E
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeCircularMB, W("EventPipeCircularMB"), 1024, "The EventPipe circular buffer size in megabytes.")
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeProcNumbers, W("EventPipeProcNumbers"), 0, "Enable/disable capturing processor numbers in EventPipe event headers")

//
// Generational Aware Analysis
//
RETAIL_CONFIG_DWORD_INFO(INTERNAL_GCGenAnalysisGen, W("GCGenAnalysisGen"), 0, "TBD")
RETAIL_CONFIG_DWORD_INFO(INTERNAL_GCGenAnalysisBytes, W("GCGenAnalysisBytes"), 0, "TBD")

//
// Diagnostics Ports
//
Expand Down
52 changes: 52 additions & 0 deletions src/coreclr/src/vm/eventpipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ void EventPipe::FinishInitialize()
}
}

int gcGenAnalysisState = 0;
EventPipeSession* gcGenAnalysisEventPipeSession = nullptr;
uint64_t gcGenAnalysisEventPipeSessionId = (uint64_t)-1;
int gcGenAnalysis = 0;
int64_t gcGenAnalysisGen = -1;
int64_t gcGenAnalysisBytes = 0;

//
// If EventPipe environment variables are specified, parse them and start a session
//
Expand Down Expand Up @@ -237,6 +244,51 @@ void EventPipe::EnableViaEnvironmentVariables()
);
EventPipe::StartStreaming(sessionID);
}
if (gcGenAnalysis == 0)
{
if (CLRConfig::IsConfigOptionSpecified(L"GCGenAnalysisGen"))
{
gcGenAnalysisGen = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_GCGenAnalysisGen);
if (CLRConfig::IsConfigOptionSpecified(L"GCGenAnalysisBytes"))
{
gcGenAnalysisBytes = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_GCGenAnalysisBytes);
gcGenAnalysis = 1;
}
else
{
gcGenAnalysis = 2;
}
}
}
if (gcGenAnalysis == 1 && gcGenAnalysisState == 0)
{
gcGenAnalysisState = 1;
LPCWSTR outputPath = nullptr;
outputPath = W("gcgenaware.nettrace");
NewHolder<EventPipeProviderConfiguration> pProviders = nullptr;
int providerCnt = 1;
pProviders = new EventPipeProviderConfiguration[providerCnt];
const uint64_t GenAwareKeyword = 0x10000000000; // This keyword is necessary for the start and stop events
const uint64_t GCHeapAndTypeNamesKeyword = 0x00001000000; // This keyword is necessary for the type names
const uint64_t GCHeapSurvivalAndMovementKeyword = 0x00000400000; // This keyword is necessary for the generation range data.
const uint64_t GCHeapDumpKeyword = 0x00000100000; // This keyword is necessary for enabling walking the heap
const uint64_t TypeKeyword = 0x00000080000; // This keyword is necessary for enabling BulkType events
const uint64_t keyword = GenAwareKeyword|GCHeapAndTypeNamesKeyword|GCHeapSurvivalAndMovementKeyword|GCHeapDumpKeyword|TypeKeyword;
pProviders[0] = EventPipeProviderConfiguration(W("Microsoft-Windows-DotNETRuntime"), keyword, 5, nullptr);
gcGenAnalysisEventPipeSessionId = EventPipe::Enable(
outputPath,
1024,
pProviders,
providerCnt,
EventPipeSessionType::File,
EventPipeSerializationFormat::NetTraceV4,
false,
nullptr
);
gcGenAnalysisEventPipeSession= EventPipe::GetSession(gcGenAnalysisEventPipeSessionId);
gcGenAnalysisEventPipeSession->Pause();
EventPipe::StartStreaming(gcGenAnalysisEventPipeSessionId);
}
}

void EventPipe::Shutdown()
Expand Down
11 changes: 10 additions & 1 deletion src/coreclr/src/vm/finalizerthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "finalizerthread.h"
#include "threadsuspend.h"
#include "jithost.h"
#include "eventpipe.h"

#ifdef FEATURE_COMINTEROP
#include "runtimecallablewrapper.h"
Expand Down Expand Up @@ -218,7 +219,8 @@ void FinalizerThread::WaitForFinalizerEvent (CLREvent *event)

static BOOL s_FinalizerThreadOK = FALSE;


extern int gcGenAnalysisState;
extern uint64_t gcGenAnalysisEventPipeSessionId;

VOID FinalizerThread::FinalizerThreadWorker(void *args)
{
Expand Down Expand Up @@ -267,6 +269,13 @@ VOID FinalizerThread::FinalizerThreadWorker(void *args)
g_TriggerHeapDump = FALSE;
}
#endif
if (gcGenAnalysisState == 2)
{
gcGenAnalysisState = 3;
EventPipe::Disable(gcGenAnalysisEventPipeSessionId);
// Writing an empty file to indicate completion
fclose(fopen("trace.nettrace.completed","w+"));
}

if (!bPriorityBoosted)
{
Expand Down
69 changes: 5 additions & 64 deletions src/coreclr/src/vm/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@

#include "gcrefmap.h"

int event_pipe_state = 0;
EventPipeSession* pEventPipeSession = nullptr;
uint64_t sessionId = (uint64_t)-1;
int gcGenAnalysis = 0;
int64_t gcGenAnalysisGen = 999;
int64_t gcGenAnalysisBytes = 0;

void GCToEEInterface::SuspendEE(SUSPEND_REASON reason)
{
WRAPPER_NO_CONTRACT;
Expand All @@ -29,50 +22,6 @@ void GCToEEInterface::SuspendEE(SUSPEND_REASON reason)
_ASSERTE(reason == SUSPEND_FOR_GC || reason == SUSPEND_FOR_GC_PREP);

g_pDebugInterface->SuspendForGarbageCollectionStarted();

if (gcGenAnalysis == 0)
{
if (GetIntConfigValue("GCGenAnalysisGen", nullptr, &gcGenAnalysisGen))
{
if (GetIntConfigValue("GCGenAnalysisBytes", nullptr, &gcGenAnalysisBytes))
{
gcGenAnalysis = 1;
}
else
{
gcGenAnalysis = 2;
}
}
}
if (gcGenAnalysis == 1 && event_pipe_state == 0)
{
event_pipe_state = 1;
LPCWSTR outputPath = nullptr;
outputPath = W("gcgenaware.nettrace");
NewHolder<EventPipeProviderConfiguration> pProviders = nullptr;
int providerCnt = 1;
pProviders = new EventPipeProviderConfiguration[providerCnt];
const uint64_t GenAwareKeyword = 0x10000000000; // This keyword is necessary for the start and stop events
const uint64_t GCHeapAndTypeNamesKeyword = 0x00001000000; // This keyword is necessary for the type names
const uint64_t GCHeapSurvivalAndMovementKeyword = 0x00000400000; // This keyword is necessary for the generation range data.
const uint64_t GCHeapDumpKeyword = 0x00000100000; // This keyword is necessary for enabling walking the heap
const uint64_t TypeKeyword = 0x00000080000; // This keyword is necessary for enabling BulkType events
const uint64_t keyword = GenAwareKeyword|GCHeapAndTypeNamesKeyword|GCHeapSurvivalAndMovementKeyword|GCHeapDumpKeyword|TypeKeyword;
pProviders[0] = EventPipeProviderConfiguration(W("Microsoft-Windows-DotNETRuntime"), keyword, 5, nullptr);
sessionId = EventPipe::Enable(
outputPath,
1024,
pProviders,
providerCnt,
EventPipeSessionType::File,
EventPipeSerializationFormat::NetTraceV4,
false,
nullptr
);
pEventPipeSession= EventPipe::GetSession(sessionId);
pEventPipeSession->Pause();
EventPipe::StartStreaming(sessionId);
}

ThreadSuspend::SuspendEE((ThreadSuspend::SUSPEND_REASON)reason);

Expand All @@ -82,19 +31,10 @@ void GCToEEInterface::SuspendEE(SUSPEND_REASON reason)
void GCToEEInterface::RestartEE(bool bFinishedGC)
{
WRAPPER_NO_CONTRACT;
CONTRACT_VIOLATION(ThrowsViolation);

g_pDebugInterface->ResumeForGarbageCollectionStarted();

ThreadSuspend::RestartEE(bFinishedGC, TRUE);

if (event_pipe_state == 2)
{
event_pipe_state = 3;
EventPipe::Disable(sessionId);
// Writing an empty file to indicate completion
fclose(fopen("trace.nettrace.completed","w+"));
}
}

VOID GCToEEInterface::SyncBlockCacheWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintptr_t lp2)
Expand Down Expand Up @@ -1657,19 +1597,20 @@ void GCToEEInterface::AnalyzeSurvivorsFinished(int condemnedGeneration, uint64_t
}
}

if (event_pipe_state == 1)
if (gcGenAnalysisState == 1)
{
if (condemnedGeneration == gcGenAnalysisGen && (promoted_bytes > (uint64_t)gcGenAnalysisBytes))
{
event_pipe_state = 2;
pEventPipeSession->Resume();
gcGenAnalysisState = 2;
gcGenAnalysisEventPipeSession->Resume();
FireEtwGenAwareBegin();
s_forcedGCInProgress = true;
GCProfileWalkHeap();
s_forcedGCInProgress = false;
reportGenerationBounds();
FireEtwGenAwareEnd();
pEventPipeSession->Pause();
gcGenAnalysisEventPipeSession->Pause();
EnableFinalization(true);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/src/vm/gcenv.ee.standalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "eventpipe.h"
#include "eventpipesession.h"
extern bool s_forcedGCInProgress;
extern int gcGenAnalysisState;
extern EventPipeSession* gcGenAnalysisEventPipeSession;
extern uint64_t gcGenAnalysisEventPipeSessionId;
extern int gcGenAnalysis;
extern int64_t gcGenAnalysisGen;
extern int64_t gcGenAnalysisBytes;

// the method table for the WeakReference class
extern MethodTable* pWeakReferenceMT;
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/src/vm/gcenv.ee.static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "eventpipe.h"
#include "eventpipesession.h"
extern bool s_forcedGCInProgress;
extern int gcGenAnalysisState;
extern EventPipeSession* gcGenAnalysisEventPipeSession;
extern uint64_t gcGenAnalysisEventPipeSessionId;
extern int gcGenAnalysis;
extern int64_t gcGenAnalysisGen;
extern int64_t gcGenAnalysisBytes;

// the method table for the WeakReference class
extern MethodTable* pWeakReferenceMT;
Expand Down