From: Sergey Andreenko Date: Fri, 24 Aug 2018 05:54:52 +0000 (-0700) Subject: Fix superpmi-shim-counter (dotnet/coreclr#19639) X-Git-Tag: submit/tizen/20210909.063632~11030^2~4067 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=127ebe99e74da66078ce3b2a24e2175b6c1775d5;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix superpmi-shim-counter (dotnet/coreclr#19639) * fix the issue * improve counter perfomance do not rewrite output file after each method Commit migrated from https://github.com/dotnet/coreclr/commit/59ea9c4e1937ea44faddb31dc3f17f8f1001f1d3 --- diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitcompiler.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitcompiler.cpp index e0121c3..37a0559 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitcompiler.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitcompiler.cpp @@ -27,7 +27,6 @@ CorJitResult __stdcall interceptor_ICJC::compileMethod(ICorJitInfo* CorJitResult temp = original_ICorJitCompiler->compileMethod(&our_ICorJitInfo, info, flags, nativeEntry, nativeSizeOfCode); - mcs->SaveTextFile(); return temp; } diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp index eb4a56d..ad12ffc 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp @@ -5,6 +5,7 @@ #include "standardpch.h" #include "methodcallsummarizer.h" +#include "logging.h" MethodCallSummarizer::MethodCallSummarizer(WCHAR* logPath) { @@ -133,6 +134,12 @@ void MethodCallSummarizer::SaveTextFile() HANDLE hFile = CreateFileW(dataFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + LogError("Couldn't open file '%ws': error %d", dataFileName, ::GetLastError()); + return; + } + DWORD len = (DWORD)sprintf_s(buff, 512, "FunctionName,Count\n"); WriteFile(hFile, buff, len, &bytesWritten, NULL); diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp index f838ea6..b234727 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp @@ -17,12 +17,13 @@ #include "spmiutil.h" #include "jithost.h" -HMODULE g_hRealJit = 0; // We leak this currently (could do the proper shutdown in process_detach) -WCHAR* g_realJitPath = nullptr; // We leak this (could do the proper shutdown in process_detach) -WCHAR* g_logPath = nullptr; // Again, we leak this one too... -char* g_logFilePath = nullptr; // We *don't* leak this, hooray! -WCHAR* g_HomeDirectory = nullptr; -WCHAR* g_DefaultRealJitPath = nullptr; +HMODULE g_hRealJit = 0; // We leak this currently (could do the proper shutdown in process_detach) +WCHAR* g_realJitPath = nullptr; // We leak this (could do the proper shutdown in process_detach) +WCHAR* g_logPath = nullptr; // Again, we leak this one too... +char* g_logFilePath = nullptr; // We *don't* leak this, hooray! +WCHAR* g_HomeDirectory = nullptr; +WCHAR* g_DefaultRealJitPath = nullptr; +MethodCallSummarizer* g_globalContext = nullptr; void SetDefaultPaths() { @@ -95,6 +96,11 @@ extern "C" BOOL delete[] g_logFilePath; g_logFilePath = nullptr; + if (g_globalContext != nullptr) + { + g_globalContext->SaveTextFile(); + } + break; case DLL_THREAD_ATTACH: @@ -131,6 +137,15 @@ extern "C" void __stdcall jitStartup(ICorJitHost* host) } g_ourJitHost = new JitHost(host); + + if (g_globalContext == nullptr) + { + SetLogPath(); + g_globalContext = new MethodCallSummarizer(g_logPath); + } + + g_ourJitHost->setMethodCallSummarizer(g_globalContext); + pnjitStartup(g_ourJitHost); } @@ -144,7 +159,6 @@ extern "C" ICorJitCompiler* __stdcall getJit() SetDefaultPaths(); SetLibName(); - SetLogPath(); // Load Library if (g_hRealJit == 0) @@ -174,11 +188,13 @@ extern "C" ICorJitCompiler* __stdcall getJit() pJitInstance = new interceptor_ICJC(); pJitInstance->original_ICorJitCompiler = tICJI; - pJitInstance->mcs = new MethodCallSummarizer(g_logPath); - if (g_ourJitHost != nullptr) + + if (g_globalContext == nullptr) { - g_ourJitHost->setMethodCallSummarizer(pJitInstance->mcs); + SetLogPath(); + g_globalContext = new MethodCallSummarizer(g_logPath); } + pJitInstance->mcs = g_globalContext; return pJitInstance; }