From: Brian Robbins Date: Thu, 29 Aug 2019 17:06:48 +0000 (-0700) Subject: Emit RVA Instead of File Offset by Default in Native Image PerfMap Files (#26423) X-Git-Tag: accepted/tizen/unified/20191011.080124~80 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b4dccce31967d39e3e1071816069f24c6523c17a;p=platform%2Fupstream%2Fcoreclr.git Emit RVA Instead of File Offset by Default in Native Image PerfMap Files (#26423) --- diff --git a/src/inc/clrconfigvalues.h b/src/inc/clrconfigvalues.h index a97e53d..c034f4f 100644 --- a/src/inc/clrconfigvalues.h +++ b/src/inc/clrconfigvalues.h @@ -565,6 +565,7 @@ RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_ProfAPI_ValidateNGENInstrumentation, W("Pro RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux to enable writing /tmp/perf-$pid.map. It is disabled by default", CLRConfig::REGUTIL_default) RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored as a marker in the perf logs. It is disabled by default", CLRConfig::REGUTIL_default) RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapShowOptimizationTiers, W("PerfMapShowOptimizationTiers"), 1, "Shows optimization tiers in the perf map for methods, as part of the symbol name. Useful for seeing separate stack frames for different optimization tiers of each method.") +RETAIL_CONFIG_STRING_INFO(EXTERNAL_NativeImagePerfMapFormat, W("NativeImagePerfMapFormat"), "Specifies the format of native image perfmap files generated by crossgen. Valid options are RVA or OFFSET.") #endif RETAIL_CONFIG_STRING_INFO(EXTERNAL_StartupDelayMS, W("StartupDelayMS"), "") diff --git a/src/vm/perfinfo.cpp b/src/vm/perfinfo.cpp index 3c8841b..7075137 100644 --- a/src/vm/perfinfo.cpp +++ b/src/vm/perfinfo.cpp @@ -41,7 +41,9 @@ void PerfInfo::LogImage(PEFile* pFile, WCHAR* guid) SString value; const SString& path = pFile->GetPath(); - value.Printf("%S%c%S", path.GetUnicode(), sDelimiter, guid); + PEImageLayout *pLoadedLayout = pFile->GetLoaded(); + SIZE_T baseAddr = (SIZE_T)pLoadedLayout->GetBase(); + value.Printf("%S%c%S%c%p", path.GetUnicode(), sDelimiter, guid, sDelimiter, baseAddr); SString command; command.Printf("%s", "ImageLoad"); diff --git a/src/vm/perfmap.cpp b/src/vm/perfmap.cpp index ae2a5b0..bc49bfe 100644 --- a/src/vm/perfmap.cpp +++ b/src/vm/perfmap.cpp @@ -336,6 +336,14 @@ NativeImagePerfMap::NativeImagePerfMap(Assembly * pAssembly, BSTR pDestPath) // Open the perf map file. OpenFile(sDestPerfMapPath); + + // Determine whether to emit RVAs or file offsets based on the specified configuration. + m_EmitRVAs = true; + CLRConfigStringHolder wszFormat(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_NativeImagePerfMapFormat)); + if(wszFormat != NULL && (wcsncmp(wszFormat, strOFFSET, wcslen(strOFFSET)) == 0)) + { + m_EmitRVAs = false; + } } // Log data to the perfmap for the specified module. @@ -371,7 +379,7 @@ void NativeImagePerfMap::LogDataForModule(Module * pModule) } // Log a pre-compiled method to the perfmap. -void NativeImagePerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode, PEImageLayout * pLoadedLayout, const char *optimizationTier) +void NativeImagePerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode, PEImageLayout *pLoadedLayout, const char *optimizationTier) { STANDARD_VM_CONTRACT; @@ -387,14 +395,25 @@ void NativeImagePerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode, // NGEN can split code between hot and cold sections which are separate in memory. // Emit an entry for each section if it is used. + PCODE addr; if (methodRegionInfo.hotSize > 0) { - LogMethod(pMethod, pLoadedLayout->RvaToOffset((PCODE)methodRegionInfo.hotStartAddress - baseAddr), methodRegionInfo.hotSize, optimizationTier); + addr = (PCODE)methodRegionInfo.hotStartAddress - baseAddr; + if (!m_EmitRVAs) + { + addr = pLoadedLayout->RvaToOffset(addr); + } + LogMethod(pMethod, addr, methodRegionInfo.hotSize, optimizationTier); } if (methodRegionInfo.coldSize > 0) { - LogMethod(pMethod, pLoadedLayout->RvaToOffset((PCODE)methodRegionInfo.coldStartAddress - baseAddr), methodRegionInfo.coldSize, optimizationTier); + addr = (PCODE)methodRegionInfo.coldStartAddress - baseAddr; + if (!m_EmitRVAs) + { + addr = pLoadedLayout->RvaToOffset(addr); + } + LogMethod(pMethod, addr, methodRegionInfo.coldSize, optimizationTier); } } diff --git a/src/vm/perfmap.h b/src/vm/perfmap.h index 22d8452..5788dcc 100644 --- a/src/vm/perfmap.h +++ b/src/vm/perfmap.h @@ -81,8 +81,13 @@ public: class NativeImagePerfMap : PerfMap { private: + const WCHAR *strOFFSET = W("OFFSET"); + + // Specify the address format since it's now possible for 'perf script' to output file offsets or RVAs. + bool m_EmitRVAs; + // Log a pre-compiled method to the map. - void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode, PEImageLayout * pLoadedLayout, const char *optimizationTier); + void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode, PEImageLayout *pLoadedLayout, const char *optimizationTier); public: // Construct a new map for a native image.