Skip to content

Commit ba88208

Browse files
author
Mike Kaufman
committed
adding gc start and end reasons to gc telemetry collection
1 parent e2ae16a commit ba88208

File tree

7 files changed

+151
-130
lines changed

7 files changed

+151
-130
lines changed

lib/Common/Memory/Chakra.Common.Memory.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<ClInclude Include="AutoAllocatorObjectPtr.h" />
112112
<ClInclude Include="AutoPtr.h" />
113113
<ClInclude Include="BucketStatsReporter.h" />
114+
<ClInclude Include="CollectionFlags.h" />
114115
<ClInclude Include="CollectionState.h" />
115116
<ClInclude Include="CommonMemoryPch.h" />
116117
<ClInclude Include="CustomHeap.h" />

lib/Common/Memory/Chakra.Common.Memory.vcxproj.filters

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<ClInclude Include="HeapBucketStats.h" />
131131
<ClInclude Include="RecyclerWaitReason.h" />
132132
<ClInclude Include="RecyclerWaitReasonInc.h" />
133+
<ClInclude Include="CollectionFlags.h" />
133134
</ItemGroup>
134135
<ItemGroup>
135136
<None Include="HeapBlock.inl" />
@@ -159,4 +160,4 @@
159160
<Filter>amd64</Filter>
160161
</MASM>
161162
</ItemGroup>
162-
</Project>
163+
</Project>

lib/Common/Memory/CollectionFlags.h

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#pragma once
2+
3+
namespace Memory
4+
{
5+
6+
enum CollectionFlags
7+
{
8+
CollectHeuristic_AllocSize = 0x00000001,
9+
CollectHeuristic_Time = 0x00000002,
10+
CollectHeuristic_TimeIfScriptActive = 0x00000004,
11+
CollectHeuristic_TimeIfInScript = 0x00000008,
12+
CollectHeuristic_Never = 0x00000080,
13+
CollectHeuristic_Mask = 0x000000FF,
14+
15+
CollectOverride_FinishConcurrent = 0x00001000,
16+
CollectOverride_ExhaustiveCandidate = 0x00002000,
17+
CollectOverride_ForceInThread = 0x00004000,
18+
CollectOverride_AllowDispose = 0x00008000,
19+
CollectOverride_AllowReentrant = 0x00010000,
20+
CollectOverride_ForceFinish = 0x00020000,
21+
CollectOverride_Explicit = 0x00040000,
22+
CollectOverride_DisableIdleFinish = 0x00080000,
23+
CollectOverride_BackgroundFinishMark = 0x00100000,
24+
CollectOverride_FinishConcurrentTimeout = 0x00200000,
25+
CollectOverride_NoExhaustiveCollect = 0x00400000,
26+
CollectOverride_SkipStack = 0x01000000,
27+
CollectOverride_CheckScriptContextClose = 0x02000000,
28+
CollectMode_Partial = 0x08000000,
29+
CollectMode_Concurrent = 0x10000000,
30+
CollectMode_Exhaustive = 0x20000000,
31+
CollectMode_DecommitNow = 0x40000000,
32+
CollectMode_CacheCleanup = 0x80000000,
33+
34+
CollectNowForceInThread = CollectOverride_ForceInThread,
35+
CollectNowForceInThreadExternal = CollectOverride_ForceInThread | CollectOverride_AllowDispose,
36+
CollectNowForceInThreadExternalNoStack = CollectOverride_ForceInThread | CollectOverride_AllowDispose | CollectOverride_SkipStack,
37+
CollectNowDefault = CollectOverride_FinishConcurrent,
38+
CollectNowDefaultLSCleanup = CollectOverride_FinishConcurrent | CollectOverride_AllowDispose,
39+
CollectNowDecommitNowExplicit = CollectNowDefault | CollectMode_DecommitNow | CollectMode_CacheCleanup | CollectOverride_Explicit | CollectOverride_AllowDispose,
40+
CollectNowConcurrent = CollectOverride_FinishConcurrent | CollectMode_Concurrent,
41+
CollectNowExhaustive = CollectOverride_FinishConcurrent | CollectMode_Exhaustive | CollectOverride_AllowDispose,
42+
CollectNowPartial = CollectOverride_FinishConcurrent | CollectMode_Partial,
43+
CollectNowConcurrentPartial = CollectMode_Concurrent | CollectNowPartial,
44+
45+
CollectOnAllocation = CollectHeuristic_AllocSize | CollectHeuristic_Time | CollectMode_Concurrent | CollectMode_Partial | CollectOverride_FinishConcurrent | CollectOverride_AllowReentrant | CollectOverride_FinishConcurrentTimeout,
46+
CollectOnTypedArrayAllocation = CollectHeuristic_AllocSize | CollectHeuristic_Time | CollectMode_Concurrent | CollectMode_Partial | CollectOverride_FinishConcurrent | CollectOverride_AllowReentrant | CollectOverride_FinishConcurrentTimeout | CollectOverride_AllowDispose,
47+
CollectOnScriptIdle = CollectOverride_CheckScriptContextClose | CollectOverride_FinishConcurrent | CollectMode_Concurrent | CollectMode_CacheCleanup | CollectOverride_SkipStack,
48+
CollectOnScriptExit = CollectOverride_CheckScriptContextClose | CollectHeuristic_AllocSize | CollectOverride_FinishConcurrent | CollectMode_Concurrent | CollectMode_CacheCleanup,
49+
CollectExhaustiveCandidate = CollectHeuristic_Never | CollectOverride_ExhaustiveCandidate,
50+
CollectOnScriptCloseNonPrimary = CollectNowConcurrent | CollectOverride_ExhaustiveCandidate | CollectOverride_AllowDispose,
51+
CollectOnRecoverFromOutOfMemory = CollectOverride_ForceInThread | CollectMode_DecommitNow,
52+
CollectOnSuspendCleanup = CollectNowConcurrent | CollectMode_Exhaustive | CollectMode_DecommitNow | CollectOverride_DisableIdleFinish,
53+
54+
FinishConcurrentOnIdle = CollectMode_Concurrent | CollectOverride_DisableIdleFinish,
55+
FinishConcurrentOnIdleAtRoot = CollectMode_Concurrent | CollectOverride_DisableIdleFinish | CollectOverride_SkipStack,
56+
FinishConcurrentDefault = CollectMode_Concurrent | CollectOverride_DisableIdleFinish | CollectOverride_BackgroundFinishMark,
57+
FinishConcurrentOnExitScript = FinishConcurrentDefault,
58+
FinishConcurrentOnEnterScript = FinishConcurrentDefault,
59+
FinishConcurrentOnAllocation = FinishConcurrentDefault,
60+
FinishDispose = CollectOverride_AllowDispose,
61+
FinishDisposeTimed = CollectOverride_AllowDispose | CollectHeuristic_TimeIfScriptActive,
62+
ForceFinishCollection = CollectOverride_ForceFinish | CollectOverride_ForceInThread,
63+
64+
#ifdef RECYCLER_STRESS
65+
CollectStress = CollectNowForceInThread,
66+
#if ENABLE_PARTIAL_GC
67+
CollectPartialStress = CollectMode_Partial,
68+
#endif
69+
#if ENABLE_CONCURRENT_GC
70+
CollectBackgroundStress = CollectNowDefault,
71+
CollectConcurrentStress = CollectNowConcurrent,
72+
#if ENABLE_PARTIAL_GC
73+
CollectConcurrentPartialStress = CollectConcurrentStress | CollectPartialStress,
74+
#endif
75+
#endif
76+
#endif
77+
78+
#if defined(CHECK_MEMORY_LEAK) || defined(LEAK_REPORT)
79+
CollectNowFinalGC = CollectNowExhaustive | CollectOverride_ForceInThread | CollectOverride_SkipStack | CollectOverride_Explicit | CollectOverride_AllowDispose,
80+
#endif
81+
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
82+
CollectNowExhaustiveSkipStack = CollectNowExhaustive | CollectOverride_SkipStack, // Used by test
83+
#endif
84+
};
85+
86+
// NOTE: There is perf lab test infrastructure that takes a dependency on the events in this enumeration. Any modifications may cause
87+
// errors in ETL analysis or report incorrect numbers. Please verify that the GC events are analyzed correctly with your changes.
88+
enum ETWEventGCActivationKind : unsigned
89+
{
90+
ETWEvent_GarbageCollect = 0, // force in-thread GC
91+
ETWEvent_ThreadCollect = 1, // thread GC with wait
92+
ETWEvent_ConcurrentCollect = 2,
93+
ETWEvent_PartialCollect = 3,
94+
95+
ETWEvent_ConcurrentMark = 11,
96+
ETWEvent_ConcurrentRescan = 12,
97+
ETWEvent_ConcurrentSweep = 13,
98+
ETWEvent_ConcurrentTransferSwept = 14,
99+
ETWEvent_ConcurrentFinishMark = 15,
100+
ETWEvent_ConcurrentSweep_TwoPassSweepPreCheck = 16, // Check whether we should do a 2-pass concurrent sweep.
101+
102+
// The following events are only relevant to the 2-pass concurrent sweep and should not be seen otherwise.
103+
ETWEvent_ConcurrentSweep_Pass1 = 17, // Concurrent sweep Pass1 of the blocks not getting allocated from during concurrent sweep.
104+
ETWEvent_ConcurrentSweep_FinishSweepPrep = 18, // Stop allocations and remove all blocks from SLIST so we can finish Pass1 of the remaining blocks.
105+
ETWEvent_ConcurrentSweep_FinishPass1 = 19, // Concurrent sweep Pass1 of the blocks that were set aside for allocations during concurrent sweep.
106+
ETWEvent_ConcurrentSweep_Pass2 = 20, // Concurrent sweep Pass1 of the blocks not getting allocated from during concurrent sweep.
107+
ETWEvent_ConcurrentSweep_FinishTwoPassSweep = 21, // Drain the SLIST at the end of the 2-pass concurrent sweep and begin normal allocations.
108+
};
109+
110+
#define IS_UNKNOWN_GC_TRIGGER(v) (v == ETWEvent_GC_Trigger_Unknown)
111+
112+
enum ETWEventGCActivationTrigger : unsigned
113+
{
114+
ETWEvent_GC_Trigger_Unknown = 0,
115+
ETWEvent_GC_Trigger_IdleCollect = 1,
116+
ETWEvent_GC_Trigger_Partial_GC_AllocSize_Heuristic = 2,
117+
ETWEvent_GC_Trigger_TimeAndAllocSize_Heuristic = 3,
118+
ETWEvent_GC_Trigger_TimeAndAllocSizeIfScriptActive_Heuristic = 4,
119+
ETWEvent_GC_Trigger_TimeAndAllocSizeIfInScript_Heuristic = 5,
120+
ETWEvent_GC_Trigger_NoHeuristic = 6,
121+
ETWEvent_GC_Trigger_Status_Completed = 7,
122+
ETWEvent_GC_Trigger_Status_StartedConcurrent = 8,
123+
ETWEvent_GC_Trigger_Status_Failed = 9,
124+
ETWEvent_GC_Trigger_Status_FailedTimeout = 10
125+
};
126+
127+
}

lib/Common/Memory/Recycler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5810,7 +5810,7 @@ Recycler::FinishConcurrentCollect(CollectionFlags flags)
58105810

58115811
const DWORD waitTime = forceInThread? INFINITE : RecyclerHeuristic::FinishConcurrentCollectWaitTime(this->GetRecyclerFlagsTable());
58125812
GCETW(GC_FINISHCONCURRENTWAIT_START, (this, waitTime));
5813-
const BOOL waited = WaitForConcurrentThread(waitTime);
5813+
const BOOL waited = WaitForConcurrentThread(waitTime, RecyclerWaitReason::FinishConcurrentCollect);
58145814
GCETW(GC_FINISHCONCURRENTWAIT_STOP, (this, !waited));
58155815
if (!waited)
58165816
{

lib/Common/Memory/Recycler.h

Lines changed: 5 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "RecyclerTelemetryInfo.h"
99
#include "RecyclerWaitReason.h"
1010
#include "Common/ObservableValue.h"
11+
#include "CollectionFlags.h"
1112

1213
namespace Js
1314
{
@@ -32,46 +33,6 @@ struct RecyclerMemoryData;
3233

3334
namespace Memory
3435
{
35-
// NOTE: There is perf lab test infrastructure that takes a dependency on the events in this enumeration. Any modifications may cause
36-
// errors in ETL analysis or report incorrect numbers. Please verify that the GC events are analyzed correctly with your changes.
37-
enum ETWEventGCActivationKind : unsigned
38-
{
39-
ETWEvent_GarbageCollect = 0, // force in-thread GC
40-
ETWEvent_ThreadCollect = 1, // thread GC with wait
41-
ETWEvent_ConcurrentCollect = 2,
42-
ETWEvent_PartialCollect = 3,
43-
44-
ETWEvent_ConcurrentMark = 11,
45-
ETWEvent_ConcurrentRescan = 12,
46-
ETWEvent_ConcurrentSweep = 13,
47-
ETWEvent_ConcurrentTransferSwept = 14,
48-
ETWEvent_ConcurrentFinishMark = 15,
49-
ETWEvent_ConcurrentSweep_TwoPassSweepPreCheck = 16, // Check whether we should do a 2-pass concurrent sweep.
50-
51-
// The following events are only relevant to the 2-pass concurrent sweep and should not be seen otherwise.
52-
ETWEvent_ConcurrentSweep_Pass1 = 17, // Concurrent sweep Pass1 of the blocks not getting allocated from during concurrent sweep.
53-
ETWEvent_ConcurrentSweep_FinishSweepPrep = 18, // Stop allocations and remove all blocks from SLIST so we can finish Pass1 of the remaining blocks.
54-
ETWEvent_ConcurrentSweep_FinishPass1 = 19, // Concurrent sweep Pass1 of the blocks that were set aside for allocations during concurrent sweep.
55-
ETWEvent_ConcurrentSweep_Pass2 = 20, // Concurrent sweep Pass1 of the blocks not getting allocated from during concurrent sweep.
56-
ETWEvent_ConcurrentSweep_FinishTwoPassSweep = 21, // Drain the SLIST at the end of the 2-pass concurrent sweep and begin normal allocations.
57-
};
58-
59-
#define IS_UNKNOWN_GC_TRIGGER(v) (v == ETWEvent_GC_Trigger_Unknown)
60-
61-
enum ETWEventGCActivationTrigger : unsigned
62-
{
63-
ETWEvent_GC_Trigger_Unknown = 0,
64-
ETWEvent_GC_Trigger_IdleCollect = 1,
65-
ETWEvent_GC_Trigger_Partial_GC_AllocSize_Heuristic = 2,
66-
ETWEvent_GC_Trigger_TimeAndAllocSize_Heuristic = 3,
67-
ETWEvent_GC_Trigger_TimeAndAllocSizeIfScriptActive_Heuristic = 4,
68-
ETWEvent_GC_Trigger_TimeAndAllocSizeIfInScript_Heuristic = 5,
69-
ETWEvent_GC_Trigger_NoHeuristic = 6,
70-
ETWEvent_GC_Trigger_Status_Completed = 7,
71-
ETWEvent_GC_Trigger_Status_StartedConcurrent = 8,
72-
ETWEvent_GC_Trigger_Status_Failed = 9,
73-
ETWEvent_GC_Trigger_Status_FailedTimeout = 10
74-
};
7536

7637
template <typename T> class RecyclerRootPtr;
7738

@@ -338,86 +299,6 @@ class RecyclerWeakReferenceRegion {
338299

339300
typedef void (__cdecl* ExternalRootMarker)(void *);
340301

341-
enum CollectionFlags
342-
{
343-
CollectHeuristic_AllocSize = 0x00000001,
344-
CollectHeuristic_Time = 0x00000002,
345-
CollectHeuristic_TimeIfScriptActive = 0x00000004,
346-
CollectHeuristic_TimeIfInScript = 0x00000008,
347-
CollectHeuristic_Never = 0x00000080,
348-
CollectHeuristic_Mask = 0x000000FF,
349-
350-
CollectOverride_FinishConcurrent = 0x00001000,
351-
CollectOverride_ExhaustiveCandidate = 0x00002000,
352-
CollectOverride_ForceInThread = 0x00004000,
353-
CollectOverride_AllowDispose = 0x00008000,
354-
CollectOverride_AllowReentrant = 0x00010000,
355-
CollectOverride_ForceFinish = 0x00020000,
356-
CollectOverride_Explicit = 0x00040000,
357-
CollectOverride_DisableIdleFinish = 0x00080000,
358-
CollectOverride_BackgroundFinishMark= 0x00100000,
359-
CollectOverride_FinishConcurrentTimeout = 0x00200000,
360-
CollectOverride_NoExhaustiveCollect = 0x00400000,
361-
CollectOverride_SkipStack = 0x01000000,
362-
CollectOverride_CheckScriptContextClose = 0x02000000,
363-
CollectMode_Partial = 0x08000000,
364-
CollectMode_Concurrent = 0x10000000,
365-
CollectMode_Exhaustive = 0x20000000,
366-
CollectMode_DecommitNow = 0x40000000,
367-
CollectMode_CacheCleanup = 0x80000000,
368-
369-
CollectNowForceInThread = CollectOverride_ForceInThread,
370-
CollectNowForceInThreadExternal = CollectOverride_ForceInThread | CollectOverride_AllowDispose,
371-
CollectNowForceInThreadExternalNoStack = CollectOverride_ForceInThread | CollectOverride_AllowDispose | CollectOverride_SkipStack,
372-
CollectNowDefault = CollectOverride_FinishConcurrent,
373-
CollectNowDefaultLSCleanup = CollectOverride_FinishConcurrent | CollectOverride_AllowDispose,
374-
CollectNowDecommitNowExplicit = CollectNowDefault | CollectMode_DecommitNow | CollectMode_CacheCleanup | CollectOverride_Explicit | CollectOverride_AllowDispose,
375-
CollectNowConcurrent = CollectOverride_FinishConcurrent | CollectMode_Concurrent,
376-
CollectNowExhaustive = CollectOverride_FinishConcurrent | CollectMode_Exhaustive | CollectOverride_AllowDispose,
377-
CollectNowPartial = CollectOverride_FinishConcurrent | CollectMode_Partial,
378-
CollectNowConcurrentPartial = CollectMode_Concurrent | CollectNowPartial,
379-
380-
CollectOnAllocation = CollectHeuristic_AllocSize | CollectHeuristic_Time | CollectMode_Concurrent | CollectMode_Partial | CollectOverride_FinishConcurrent | CollectOverride_AllowReentrant | CollectOverride_FinishConcurrentTimeout,
381-
CollectOnTypedArrayAllocation = CollectHeuristic_AllocSize | CollectHeuristic_Time | CollectMode_Concurrent | CollectMode_Partial | CollectOverride_FinishConcurrent | CollectOverride_AllowReentrant | CollectOverride_FinishConcurrentTimeout | CollectOverride_AllowDispose,
382-
CollectOnScriptIdle = CollectOverride_CheckScriptContextClose | CollectOverride_FinishConcurrent | CollectMode_Concurrent | CollectMode_CacheCleanup | CollectOverride_SkipStack,
383-
CollectOnScriptExit = CollectOverride_CheckScriptContextClose | CollectHeuristic_AllocSize | CollectOverride_FinishConcurrent | CollectMode_Concurrent | CollectMode_CacheCleanup,
384-
CollectExhaustiveCandidate = CollectHeuristic_Never | CollectOverride_ExhaustiveCandidate,
385-
CollectOnScriptCloseNonPrimary = CollectNowConcurrent | CollectOverride_ExhaustiveCandidate | CollectOverride_AllowDispose,
386-
CollectOnRecoverFromOutOfMemory = CollectOverride_ForceInThread | CollectMode_DecommitNow,
387-
CollectOnSuspendCleanup = CollectNowConcurrent | CollectMode_Exhaustive | CollectMode_DecommitNow | CollectOverride_DisableIdleFinish,
388-
389-
FinishConcurrentOnIdle = CollectMode_Concurrent | CollectOverride_DisableIdleFinish,
390-
FinishConcurrentOnIdleAtRoot = CollectMode_Concurrent | CollectOverride_DisableIdleFinish | CollectOverride_SkipStack,
391-
FinishConcurrentDefault = CollectMode_Concurrent | CollectOverride_DisableIdleFinish | CollectOverride_BackgroundFinishMark,
392-
FinishConcurrentOnExitScript = FinishConcurrentDefault,
393-
FinishConcurrentOnEnterScript = FinishConcurrentDefault,
394-
FinishConcurrentOnAllocation = FinishConcurrentDefault,
395-
FinishDispose = CollectOverride_AllowDispose,
396-
FinishDisposeTimed = CollectOverride_AllowDispose | CollectHeuristic_TimeIfScriptActive,
397-
ForceFinishCollection = CollectOverride_ForceFinish | CollectOverride_ForceInThread,
398-
399-
#ifdef RECYCLER_STRESS
400-
CollectStress = CollectNowForceInThread,
401-
#if ENABLE_PARTIAL_GC
402-
CollectPartialStress = CollectMode_Partial,
403-
#endif
404-
#if ENABLE_CONCURRENT_GC
405-
CollectBackgroundStress = CollectNowDefault,
406-
CollectConcurrentStress = CollectNowConcurrent,
407-
#if ENABLE_PARTIAL_GC
408-
CollectConcurrentPartialStress = CollectConcurrentStress | CollectPartialStress,
409-
#endif
410-
#endif
411-
#endif
412-
413-
#if defined(CHECK_MEMORY_LEAK) || defined(LEAK_REPORT)
414-
CollectNowFinalGC = CollectNowExhaustive | CollectOverride_ForceInThread | CollectOverride_SkipStack | CollectOverride_Explicit | CollectOverride_AllowDispose,
415-
#endif
416-
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
417-
CollectNowExhaustiveSkipStack = CollectNowExhaustive | CollectOverride_SkipStack, // Used by test
418-
#endif
419-
};
420-
421302
class RecyclerCollectionWrapper
422303
{
423304
public:
@@ -806,9 +687,9 @@ class Recycler
806687
};
807688

808689
#if defined(ENABLE_JS_ETW)
809-
uint collectionStartReason;
690+
ETWEventGCActivationTrigger collectionStartReason;
810691
CollectionFlags collectionStartFlags;
811-
uint collectionFinishReason;
692+
ETWEventGCActivationTrigger collectionFinishReason;
812693
#endif
813694

814695
class CollectionStateChangedObserver : public ObservableValueObserver<CollectionState>
@@ -826,11 +707,11 @@ class Recycler
826707
#ifdef ENABLE_BASIC_TELEMETRY
827708
if (oldVal == CollectionState::CollectionStateNotCollecting && newVal != CollectionState::CollectionStateNotCollecting && newVal != CollectionState::Collection_PreCollection)
828709
{
829-
this->recycler->GetRecyclerTelemetryInfo().StartPass();
710+
this->recycler->GetRecyclerTelemetryInfo().StartPass(newVal);
830711
}
831712
else if (oldVal != CollectionState::CollectionStateNotCollecting && oldVal != CollectionState::Collection_PreCollection && newVal == CollectionState::CollectionStateNotCollecting)
832713
{
833-
this->recycler->GetRecyclerTelemetryInfo().EndPass();
714+
this->recycler->GetRecyclerTelemetryInfo().EndPass(oldVal);
834715
}
835716
#endif
836717
}

0 commit comments

Comments
 (0)