diff options
Diffstat (limited to 'src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp')
-rw-r--r-- | src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp | 63 |
1 files changed, 4 insertions, 59 deletions
diff --git a/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp b/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp index ad12ffcff1..ca1e191c08 100644 --- a/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp +++ b/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp @@ -6,6 +6,7 @@ #include "standardpch.h" #include "methodcallsummarizer.h" #include "logging.h" +#include "spmiutil.h" MethodCallSummarizer::MethodCallSummarizer(WCHAR* logPath) { @@ -13,66 +14,10 @@ MethodCallSummarizer::MethodCallSummarizer(WCHAR* logPath) names = nullptr; counts = nullptr; - WCHAR* ExecutableName = GetCommandLineW(); - WCHAR* quote1 = NULL; + WCHAR* executableName = GetCommandLineW(); + const WCHAR* dataFileExtension = W(".csv"); - // if there are any quotes in filename convert them to spaces. - while ((quote1 = wcsstr(ExecutableName, W("\""))) != NULL) - *quote1 = W(' '); - - // remove any illegal or annoying characters from file name by converting them to underscores - while ((quote1 = wcspbrk(ExecutableName, W("=<>:\"/\\|?! *.,"))) != NULL) - *quote1 = W('_'); - - const WCHAR* DataFileExtension = W(".csv"); - size_t ExecutableNameLength = wcslen(ExecutableName); - size_t DataFileExtensionLength = wcslen(DataFileExtension); - size_t logPathLength = wcslen(logPath); - - unsigned int randNumber = 0; - WCHAR RandNumberString[9]; - RandNumberString[0] = L'\0'; - size_t RandNumberLength = 0; - - size_t dataFileNameLength = - logPathLength + 1 + ExecutableNameLength + 1 + RandNumberLength + 1 + DataFileExtensionLength + 1; - - const size_t MaxAcceptablePathLength = - MAX_PATH - 20; // subtract 20 to leave buffer, for possible random number addition - if (dataFileNameLength >= MaxAcceptablePathLength) - { - // The path name is too long; creating the file will fail. This can happen because we use the command line, - // which for ngen includes lots of environment variables, for example. - - // Assume (!) the extra space is all in the ExecutableName, so shorten that. - ExecutableNameLength -= dataFileNameLength - MaxAcceptablePathLength; - - dataFileNameLength = MaxAcceptablePathLength; - -#ifdef FEATURE_PAL - PAL_Random(&randNumber, sizeof(randNumber)); -#else // !FEATURE_PAL - rand_s(&randNumber); -#endif // !FEATURE_PAL - - RandNumberLength = 9; // 8 hex digits + null - swprintf_s(RandNumberString, RandNumberLength, W("%08X"), randNumber); - - dataFileNameLength += RandNumberLength - 1; - } - - dataFileName = new WCHAR[dataFileNameLength]; - dataFileName[0] = 0; - wcsncat_s(dataFileName, dataFileNameLength, logPath, logPathLength); - wcsncat_s(dataFileName, dataFileNameLength, W("\\\0"), 1); - wcsncat_s(dataFileName, dataFileNameLength, ExecutableName, ExecutableNameLength); - - if (RandNumberLength > 0) - { - wcsncat_s(dataFileName, dataFileNameLength, RandNumberString, RandNumberLength); - } - - wcsncat_s(dataFileName, dataFileNameLength, DataFileExtension, DataFileExtensionLength); + dataFileName = getResultFileName(logPath, executableName, dataFileExtension); } // lots of ways will be faster.. this happens to be decently simple and good enough for the task at hand and nicely |