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 // See the LICENSE file in the project root for more information.
13 //=============================================================================
14 // ALL THE JIT PERF STATS GATHERING CODE IS COMPILED ONLY IF THE ENABLE_JIT_PERF WAS DEFINED.
15 #if defined(ENABLE_JIT_PERF)
17 __int64 g_JitCycles = 0;
18 size_t g_NonJitCycles = 0;
19 CRITSEC_COOKIE g_csJit;
20 __int64 g_tlsJitCycles = 0;
23 size_t g_dwTlsx86CodeSize = 0;
24 size_t g_TotalILCodeSize = 0;
25 size_t g_Totalx86CodeSize = 0;
26 size_t g_TotalMethodsJitted = 0;
36 LARGE_INTEGER cycleFreq;
37 if (QueryPerformanceFrequency (&cycleFreq))
39 double dJitC = (double) g_JitCycles;
40 double dNonJitC = (double) g_NonJitCycles;
41 double dFreq = (double)cycleFreq.QuadPart;
42 double compileSpeed = (double)g_TotalILCodeSize/(dJitC/dFreq);
44 PERFLOG((W("Jit Cycles"), (dJitC - dNonJitC), CYCLES));
45 PERFLOG((W("Jit Time"), (dJitC - dNonJitC)/dFreq, SECONDS));
46 PERFLOG((W("Non Jit Cycles"), dNonJitC, CYCLES));
47 PERFLOG((W("Non Jit Time"), dNonJitC/dFreq, SECONDS));
48 PERFLOG((W("Total Jit Cycles"), dJitC, CYCLES));
49 PERFLOG((W("Total Jit Time"), dJitC/dFreq, SECONDS));
50 PERFLOG((W("Methods Jitted"), (UINT_PTR)g_TotalMethodsJitted, COUNT));
51 PERFLOG((W("IL Code Compiled"), (UINT_PTR)g_TotalILCodeSize, BYTES));
52 PERFLOG((W("X86 Code Emitted"), (UINT_PTR)g_Totalx86CodeSize, BYTES));
53 // Included the perf counter description in this case because its not obvious what we are reporting.
54 PERFLOG((W("ExecTime"), compileSpeed/1000, KBYTES_PER_SEC, W("IL Code compiled/sec")));
58 void InitJitPerf(void)
66 InlineSString<4> lpszValue;
67 g_fJitPerfOn = WszGetEnvironmentVariable (W("JIT_PERF_OUTPUT"), lpszValue);
70 g_csJit = ClrCreateCriticalSection(CrstJitPerf,CRST_UNSAFE_ANYMODE);
74 void DoneJitPerfStats()
84 ClrDeleteCriticalSection(g_csJit);
86 // Output stats to stdout and if necessary to the perf automation file.
93 void StartNonJITPerfWorker(LARGE_INTEGER * pCycleStart)
101 pCycleStart->QuadPart = 0;
103 size_t pTlsNonJitCycles = (size_t) ClrFlsGetValue (TlsIdx_JitPerf);
104 if ((pTlsNonJitCycles & 1) == 0 ) { /* odd value indicates we are in the EE */
105 ClrFlsSetValue(TlsIdx_JitPerf, (LPVOID)(pTlsNonJitCycles + 1));
106 QueryPerformanceCounter(pCycleStart);
110 void StopNonJITPerfWorker(LARGE_INTEGER * pCycleStart)
118 LARGE_INTEGER CycleStop;
120 if (pCycleStart->QuadPart != 0 && QueryPerformanceCounter(&CycleStop) ) {
121 size_t pTlsNonJitCycles = (size_t)ClrFlsGetValue (TlsIdx_JitPerf);
122 pTlsNonJitCycles += static_cast<size_t>(CycleStop.QuadPart - pCycleStart->QuadPart);
123 pTlsNonJitCycles &= ~1; /* even indicate we are not in EE */
124 ClrFlsSetValue(TlsIdx_JitPerf, (LPVOID)(pTlsNonJitCycles));
129 #endif //ENABLE_JIT_PERF