Maoni0 / realmon

A monitoring tool that tells you when GCs happen in a process and some characteristics about these GCs
MIT License
281 stars 25 forks source link

investigate memory usage #23

Open Maoni0 opened 2 years ago

Maoni0 commented 2 years ago

I looked at the tool briefly today and I could see sometimes the memory usage go up pretty quickly (like when I was using one gcmon process to monitor anther gcmon process 😀). a hasty look at the callstacks for VirtualAlloc* in windbg gives me a few categories for committed bytes - some are understandable; others aren't. for example, this is a pretty common callstack -

00 00007ffb`1433b36d     : 00000000`00000001 00007ffb`147db558 00000000`00000000 00007ffb`143ba699 : KERNELBASE!VirtualAlloc [minkernel\kernelbase\mmsup.c @ 1022] 
01 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!ClrVirtualAlloc+0x12 [D:\a\_work\1\s\src\coreclr\vm\hosting.cpp @ 75] 
[some gc frames omitted]
0b 00007ffb`14348ee1     : 00000000`00000002 00000000`00000050 00000116`e659d6c8 00000000`00000000 : coreclr!WKS::GCHeap::Alloc+0x84 [D:\a\_work\1\s\src\coreclr\gc\gc.cpp @ 43664] 
0c (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!Alloc+0xb3 [D:\a\_work\1\s\src\coreclr\vm\gchelpers.cpp @ 228] 
0d (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!AllocateObject+0x11b [D:\a\_work\1\s\src\coreclr\vm\gchelpers.cpp @ 981] 
0e 00007ffa`b4ef8022     : 00007ffa`b4fa4ea8 00000000`00000003 00000116`c609a488 00007ffa`b4efba7d : coreclr!JIT_New+0x201 [D:\a\_work\1\s\src\coreclr\vm\jithelpers.cpp @ 2324] 
0f 00007ffa`b4ef105a     : 00000116`c603c3a8 00000116`c603bee8 00000116`c6066100 00000116`c63b1fe8 : Microsoft_Diagnostics_Tracing_TraceEvent!Microsoft.Diagnostics.Tracing.Parsers.Clr.GCPerHeapHistoryTraceData.GenData(Microsoft.Diagnostics.Tracing.Parsers.Clr.Gens)+0x6212
10 00007ffa`b4ee9194     : 00000116`c609a188 00007ffb`14453876 00000000`00000000 00000116`c5f368e0 : Microsoft_Diagnostics_Tracing_TraceEvent!Microsoft.Diagnostics.Tracing.Analysis.GC.GCStats.ProcessPerHeapHistory(Microsoft.Diagnostics.Tracing.Analysis.TraceLoadedDotNetRuntime, Microsoft.Diagnostics.Tracing.Parsers.Clr.GCPerHeapHistoryTraceData)+0x27a
11 00007ffa`b4ef73d9     : 00000116`e81d1740 00000015`1ed7d860 00000116`e81d1f58 00000000`00000238 : Microsoft_Diagnostics_Tracing_TraceEvent!Microsoft.Diagnostics.Tracing.TraceEventDispatcher.DoDispatch(Microsoft.Diagnostics.Tracing.TraceEvent)+0x74
12 00007ffa`b4ee8ce2     : 00000116`e81d1f20 00000015`1ed7d969 00000116`e81b80e0 00000000`00000010 : Microsoft_Diagnostics_Tracing_TraceEvent!Microsoft.Diagnostics.Tracing.ETWTraceEventSource.RawDispatch(EVENT_RECORD*)+0xe6c9
13 00007ffb`4ac337fb     : 00000116`e81d1f20 00000015`1ed7d969 00000116`00000238 00000116`e828c6d0 : System_Console!ILStubClass.IL_STUB_ReversePInvoke(Int64)+0x42
14 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : sechost!EtwpDoEventRecordCallbacks+0x24 [minkernel\etw\control\tracedc.cpp @ 1945] 
15 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : sechost!EtwpDoEventCallbacks+0x31 [minkernel\etw\control\tracedc.cpp @ 1956] 
16 00007ffb`4ac33633     : 00000116`e828c6d0 00000000`00000000 00000000`00000000 7fffffff`ffffffff : sechost!EtwpLoadEventTrigger+0x15b [minkernel\etw\control\tracert.cpp @ 1435] 
17 00007ffb`4ac3b86a     : 00000000`00000000 00000015`1ed7db40 00000116`e828c6d0 00000000`00000000 : sechost!EtwpProcessRealTimeTraces+0xc7 [minkernel\etw\control\tracert.cpp @ 468] 
18 00007ffa`b4ee5be4     : 00000000`00000000 00007ffb`00000001 00000116`c5f377c8 00000000`00000000 : sechost!ProcessTrace+0x18a [minkernel\etw\control\tracedc.cpp @ 2469] 

we are still processing the GC events even though we are not displaying the results because those are not event happening in the process we asked for. these should be dead though since I'm not storing them anywhere. should verify this is the case.

but things like this seem odd -

 # RetAddr               : Args to Child                                                           : Call Site
00 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : KERNELBASE!VirtualAllocEx [minkernel\kernelbase\mmsup.c @ 1041] 
01 00007ffb`1440261d     : 00001d59`e1a7ba00 00000000`00000001 00007ffb`2ba50000 00000000`00000202 : KERNELBASE!VirtualAlloc+0x4 [minkernel\kernelbase\mmsup.c @ 1023] 
02 00007ffb`1436ab25     : 00000000`00000030 00000015`1dffdf29 00000000`00000030 00000000`00000000 : coreclr!UnlockedLoaderHeap::GetMoreCommittedPages+0x79 [D:\a\_work\1\s\src\coreclr\utilcode\loaderheap.cpp @ 1234] 
03 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!UnlockedLoaderHeap::UnlockedAllocMem_NoThrow+0xe6 [D:\a\_work\1\s\src\coreclr\utilcode\loaderheap.cpp @ 1400] 
04 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!UnlockedLoaderHeap::UnlockedAllocMem+0xe6 [D:\a\_work\1\s\src\coreclr\utilcode\loaderheap.cpp @ 1266] 
05 00007ffb`14344940     : 00000116`c4155178 00000015`1dffe379 00007ffb`147e29d0 00000116`c4155178 : coreclr!LoaderHeap::RealAllocMemUnsafe+0x141 [D:\a\_work\1\s\src\coreclr\inc\loaderheap.h @ 561] 
06 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!LoaderHeap::RealAllocMem+0x15 [D:\a\_work\1\s\src\coreclr\inc\loaderheap.h @ 517] 
07 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!EEJitManager::allocCode+0x379 [D:\a\_work\1\s\src\coreclr\vm\codeman.cpp @ 2707] 
08 00007ffb`2ba91b54     : 00000116`e660c800 00000116`00000000 00000116`00000001 00007ffb`0000001f : coreclr!CEEJitInfo::allocMem+0x570 [D:\a\_work\1\s\src\coreclr\vm\jitinterface.cpp @ 12451] 
09 00007ffb`2bb18433     : 00000015`1dffeb2c 00000116`e660bf18 00000116`e660c830 00007ffb`2ba50000 : clrjit!emitter::emitEndCodeGen+0x124 [D:\a\_work\1\s\src\coreclr\jit\emit.cpp @ 5731] 
0a 00007ffb`2bb1d482     : 00000116`e660c830 00000015`1dffe4b0 00000000`00000000 00007ffb`2bb880b0 : clrjit!CodeGen::genEmitMachineCode+0x183 [D:\a\_work\1\s\src\coreclr\jit\codegencommon.cpp @ 2446] 
0b 00007ffb`2bb18567     : 00000116`e660c830 00000015`1dffeaa8 00000000`00000000 00007ffb`2ba50000 : clrjit!CodeGenPhase::DoPhase+0x12 [D:\a\_work\1\s\src\coreclr\jit\codegen.h @ 1610] 
0c (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : clrjit!Phase::Run+0x44 [D:\a\_work\1\s\src\coreclr\jit\phase.cpp @ 61] 
0d (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : clrjit!DoPhase+0x4b [D:\a\_work\1\s\src\coreclr\jit\codegen.h @ 1623] 
0e 00007ffb`2bac4aed     : 00000116`e660bf18 00000116`e6613758 00000000`00000000 00000116`e6613758 : clrjit!CodeGen::genGenerateCode+0xd7 [D:\a\_work\1\s\src\coreclr\jit\codegencommon.cpp @ 2099] 
0f 00007ffb`2ba7deb1     : 00000116`e660bf18 00000116`e660bf18 00000000`00000000 00000116`e660bf18 : clrjit!Compiler::compCompile+0xf1d [D:\a\_work\1\s\src\coreclr\jit\compiler.cpp @ 5216] 
10 00007ffb`2ba8209a     : 00007ffa`b48f56d0 00000116`e660bf18 00000015`1dffeba0 00000015`1dfff900 : clrjit!Compiler::compCompileHelper+0x291 [D:\a\_work\1\s\src\coreclr\jit\compiler.cpp @ 6422] 
11 00007ffb`2ba83492     : 00000000`00000000 00000000`00000000 00007ffa`b49b4950 00000015`1dffe9d0 : clrjit!Compiler::compCompile+0x24a [D:\a\_work\1\s\src\coreclr\jit\compiler.cpp @ 5685] 
12 00007ffb`2bb1b633     : 00007ffa`b49b4950 00007ffa`b47e4000 00000015`1dffeb80 00000015`1dffee30 : clrjit!jitNativeCode+0x262 [D:\a\_work\1\s\src\coreclr\jit\compiler.cpp @ 7055] 
13 00007ffb`14367571     : 00000116`e6587110 00000000`00000000 00000015`1dfff0d8 00000015`1dffecd0 : clrjit!CILJit::compileMethod+0x83 [D:\a\_work\1\s\src\coreclr\jit\ee_il_dll.cpp @ 279] 
14 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!invokeCompileMethodHelper+0x86 [D:\a\_work\1\s\src\coreclr\vm\jitinterface.cpp @ 12774] 
15 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!invokeCompileMethod+0xc5 [D:\a\_work\1\s\src\coreclr\vm\jitinterface.cpp @ 12839] 
16 00007ffb`14366c31     : 00000015`00000096 00000015`1dfff0d8 00000015`1dfff070 00000015`1dffef10 : coreclr!UnsafeJitFunction+0x7f1 [D:\a\_work\1\s\src\coreclr\vm\jitinterface.cpp @ 13355] 
17 00007ffb`143668fc     : 00000000`00000001 00007ffa`b49b4950 00007ffa`b49b4950 00007ffb`4c73b86b : coreclr!MethodDesc::JitCompileCodeLocked+0x1f1 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 1051] 
18 00007ffb`1435f7f9     : 00000116`e8243a70 00000015`1dfff520 00000116`e8243a70 00000116`e8243a78 : coreclr!MethodDesc::JitCompileCodeLockedEventWrapper+0x148 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 920] 
19 00007ffb`14399dc2     : 00007ffa`b49b4950 00000116`00000000 00000000`00000000 00000000`00000000 : coreclr!MethodDesc::JitCompileCode+0x2a9 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 860] 
1a 00007ffb`14399cee     : 00000000`00000000 00000000`00000000 00000116`e6521b90 00007ffa`00000000 : coreclr!MethodDesc::PrepareILBasedCode+0x66 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 439] 
1b (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!MethodDesc::PrepareCode+0x10 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 332] 
1c 00007ffb`1439a445     : 00000000`00000000 00000000`00000064 00000116`c4183920 00000000`00000002 : coreclr!TieredCompilationManager::CompileCodeVersion+0xce [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 906] 
1d (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!TieredCompilationManager::OptimizeMethod+0x22 [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 883] 
1e 00007ffb`1445bcb8     : 00000116`c4183920 00000015`1dfff7b8 00000000`0004e200 00000000`0007a120 : coreclr!TieredCompilationManager::DoBackgroundWork+0x125 [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 768] 
1f 00007ffb`1445bbac     : 00000000`00989680 00007ffb`147d5f98 00000116`c414f860 00000000`0004e200 : coreclr!TieredCompilationManager::BackgroundWorkerStart+0xc8 [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 482] 
20 00007ffb`143cf921     : 00000000`00000130 00000000`00000000 00000000`00000000 00007ffb`143cb8ee : coreclr!TieredCompilationManager::BackgroundWorkerBootstrapper1+0x5c [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 431] 
21 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!ManagedThreadBase_DispatchInner+0xd [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7312] 
22 00007ffb`143cf9fa     : 00000000`00000000 00000000`00000130 00000000`00000000 00000000`00000000 : coreclr!ManagedThreadBase_DispatchMiddle+0x85 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7356] 
23 00007ffb`14473efa     : 00000116`00000001 ffffffff`ffffffff 00000116`e828b8f0 00000116`e6587110 : coreclr!ManagedThreadBase_DispatchOuter+0xae [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7515] 
24 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!ManagedThreadBase_FullTransition+0x24 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7560] 
25 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!ManagedThreadBase::KickOff+0x24 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7595] 
26 00007ffb`4c627034     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : coreclr!TieredCompilationManager::BackgroundWorkerBootstrapper0+0x3a [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 414] 
27 00007ffb`4c762651     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14 [clientcore\base\win32\client\thread.c @ 64] 
28 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21 [minkernel\ntdll\rtlstrt.c @ 1153] 
 # RetAddr               : Args to Child                                                           : Call Site
00 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : KERNELBASE!VirtualAllocExNuma [minkernel\kernelbase\mmsup.c @ 1066] 
01 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : KERNELBASE!VirtualAllocEx+0xd [minkernel\kernelbase\mmsup.c @ 1041] 
02 00007ffb`1440261d     : 00007ffa`b4fb9000 00000000`00001000 00007ffb`2ba50000 00000000`00000202 : KERNELBASE!VirtualAlloc+0x11 [minkernel\kernelbase\mmsup.c @ 1023] 
03 00007ffb`1436ab25     : 00000000`00000030 00000015`1dffdf29 00000000`00000030 00000000`00000000 : coreclr!UnlockedLoaderHeap::GetMoreCommittedPages+0x79 [D:\a\_work\1\s\src\coreclr\utilcode\loaderheap.cpp @ 1234] 
04 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!UnlockedLoaderHeap::UnlockedAllocMem_NoThrow+0xe6 [D:\a\_work\1\s\src\coreclr\utilcode\loaderheap.cpp @ 1400] 
05 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!UnlockedLoaderHeap::UnlockedAllocMem+0xe6 [D:\a\_work\1\s\src\coreclr\utilcode\loaderheap.cpp @ 1266] 
06 00007ffb`14344940     : 00000116`c4155178 00000015`1dffe379 00007ffb`147e29d0 00000116`c4155178 : coreclr!LoaderHeap::RealAllocMemUnsafe+0x141 [D:\a\_work\1\s\src\coreclr\inc\loaderheap.h @ 561] 
07 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!LoaderHeap::RealAllocMem+0x15 [D:\a\_work\1\s\src\coreclr\inc\loaderheap.h @ 517] 
08 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!EEJitManager::allocCode+0x379 [D:\a\_work\1\s\src\coreclr\vm\codeman.cpp @ 2707] 
09 00007ffb`2ba91b54     : 00000116`e660c800 00000116`00000000 00000116`00000001 00007ffb`0000001f : coreclr!CEEJitInfo::allocMem+0x570 [D:\a\_work\1\s\src\coreclr\vm\jitinterface.cpp @ 12451] 
0a 00007ffb`2bb18433     : 00000015`1dffeb2c 00000116`e660bf18 00000116`e660c830 00007ffb`2ba50000 : clrjit!emitter::emitEndCodeGen+0x124 [D:\a\_work\1\s\src\coreclr\jit\emit.cpp @ 5731] 
0b 00007ffb`2bb1d482     : 00000116`e660c830 00000015`1dffe4b0 00000000`00000000 00007ffb`2bb880b0 : clrjit!CodeGen::genEmitMachineCode+0x183 [D:\a\_work\1\s\src\coreclr\jit\codegencommon.cpp @ 2446] 
0c 00007ffb`2bb18567     : 00000116`e660c830 00000015`1dffeaa8 00000000`00000000 00007ffb`2ba50000 : clrjit!CodeGenPhase::DoPhase+0x12 [D:\a\_work\1\s\src\coreclr\jit\codegen.h @ 1610] 
0d (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : clrjit!Phase::Run+0x44 [D:\a\_work\1\s\src\coreclr\jit\phase.cpp @ 61] 
0e (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : clrjit!DoPhase+0x4b [D:\a\_work\1\s\src\coreclr\jit\codegen.h @ 1623] 
0f 00007ffb`2bac4aed     : 00000116`e660bf18 00000116`e6613758 00000000`00000000 00000116`e6613758 : clrjit!CodeGen::genGenerateCode+0xd7 [D:\a\_work\1\s\src\coreclr\jit\codegencommon.cpp @ 2099] 
10 00007ffb`2ba7deb1     : 00000116`e660bf18 00000116`e660bf18 00000000`00000000 00000116`e660bf18 : clrjit!Compiler::compCompile+0xf1d [D:\a\_work\1\s\src\coreclr\jit\compiler.cpp @ 5216] 
11 00007ffb`2ba8209a     : 00007ffa`b48f56d0 00000116`e660bf18 00000015`1dffeba0 00000015`1dfff900 : clrjit!Compiler::compCompileHelper+0x291 [D:\a\_work\1\s\src\coreclr\jit\compiler.cpp @ 6422] 
12 00007ffb`2ba83492     : 00000000`00000000 00000000`00000000 00007ffa`b49b4950 00000015`1dffe9d0 : clrjit!Compiler::compCompile+0x24a [D:\a\_work\1\s\src\coreclr\jit\compiler.cpp @ 5685] 
13 00007ffb`2bb1b633     : 00007ffa`b49b4950 00007ffa`b47e4000 00000015`1dffeb80 00000015`1dffee30 : clrjit!jitNativeCode+0x262 [D:\a\_work\1\s\src\coreclr\jit\compiler.cpp @ 7055] 
14 00007ffb`14367571     : 00000116`e6587110 00000000`00000000 00000015`1dfff0d8 00000015`1dffecd0 : clrjit!CILJit::compileMethod+0x83 [D:\a\_work\1\s\src\coreclr\jit\ee_il_dll.cpp @ 279] 
15 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!invokeCompileMethodHelper+0x86 [D:\a\_work\1\s\src\coreclr\vm\jitinterface.cpp @ 12774] 
16 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!invokeCompileMethod+0xc5 [D:\a\_work\1\s\src\coreclr\vm\jitinterface.cpp @ 12839] 
17 00007ffb`14366c31     : 00000015`00000096 00000015`1dfff0d8 00000015`1dfff070 00000015`1dffef10 : coreclr!UnsafeJitFunction+0x7f1 [D:\a\_work\1\s\src\coreclr\vm\jitinterface.cpp @ 13355] 
18 00007ffb`143668fc     : 00000000`00000001 00007ffa`b49b4950 00007ffa`b49b4950 00007ffb`4c73b86b : coreclr!MethodDesc::JitCompileCodeLocked+0x1f1 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 1051] 
19 00007ffb`1435f7f9     : 00000116`e8243a70 00000015`1dfff520 00000116`e8243a70 00000116`e8243a78 : coreclr!MethodDesc::JitCompileCodeLockedEventWrapper+0x148 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 920] 
1a 00007ffb`14399dc2     : 00007ffa`b49b4950 00000116`00000000 00000000`00000000 00000000`00000000 : coreclr!MethodDesc::JitCompileCode+0x2a9 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 860] 
1b 00007ffb`14399cee     : 00000000`00000000 00000000`00000000 00000116`e6521b90 00007ffa`00000000 : coreclr!MethodDesc::PrepareILBasedCode+0x66 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 439] 
1c (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!MethodDesc::PrepareCode+0x10 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp @ 332] 
1d 00007ffb`1439a445     : 00000000`00000000 00000000`00000064 00000116`c4183920 00000000`00000002 : coreclr!TieredCompilationManager::CompileCodeVersion+0xce [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 906] 
1e (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!TieredCompilationManager::OptimizeMethod+0x22 [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 883] 
1f 00007ffb`1445bcb8     : 00000116`c4183920 00000015`1dfff7b8 00000000`0004e200 00000000`0007a120 : coreclr!TieredCompilationManager::DoBackgroundWork+0x125 [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 768] 
20 00007ffb`1445bbac     : 00000000`00989680 00007ffb`147d5f98 00000116`c414f860 00000000`0004e200 : coreclr!TieredCompilationManager::BackgroundWorkerStart+0xc8 [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 482] 
21 00007ffb`143cf921     : 00000000`00000130 00000000`00000000 00000000`00000000 00007ffb`143cb8ee : coreclr!TieredCompilationManager::BackgroundWorkerBootstrapper1+0x5c [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 431] 
22 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!ManagedThreadBase_DispatchInner+0xd [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7312] 
23 00007ffb`143cf9fa     : 00000000`00000000 00000000`00000130 00000000`00000000 00000000`00000000 : coreclr!ManagedThreadBase_DispatchMiddle+0x85 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7356] 
24 00007ffb`14473efa     : 00000116`00000001 ffffffff`ffffffff 00000116`e828b8f0 00000116`e6587110 : coreclr!ManagedThreadBase_DispatchOuter+0xae [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7515] 
25 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!ManagedThreadBase_FullTransition+0x24 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7560] 
26 (Inline Function)     : --------`-------- --------`-------- --------`-------- --------`-------- : coreclr!ManagedThreadBase::KickOff+0x24 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp @ 7595] 
27 00007ffb`4c627034     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : coreclr!TieredCompilationManager::BackgroundWorkerBootstrapper0+0x3a [D:\a\_work\1\s\src\coreclr\vm\tieredcompilation.cpp @ 414] 
28 00007ffb`4c762651     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14 [clientcore\base\win32\client\thread.c @ 64] 
29 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21 [minkernel\ntdll\rtlstrt.c @ 1153] 

and I'm seeing many of these (which is odd 'cause we should only be disposing the session once).

would be worthwhile to do a deeper investigation.

MokoSan commented 2 years ago

Edited repost of my research from https://github.com/Maoni0/realmon/issues/25

@Maoni0, for the second problem i.e. "disposing" the session multiple times, my guess is this be because the name of the session is hardcoded as MySession here and based on the way you tested the program, multiple of these sessions are being created with the same name which seems like a violation of what's described in the TraceProgrammer's Guide in this that's causing "unexpected" code paths:

"Creates a new TraceEventSession, each session is given a name that is unique ACROSS THE MACHINE. In our case we called our session MySession. Sessions CAN live beyond the lifetime of process that created them, and this name is how you refer to these sessions from other processes besides the process that created them. We also specify a file where the data is to be logged. By convention, these data files use the .ETL (Event Trace Log) suffix."

Solution: Pass in a forced unique session name via a command line argument?