Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b402106
[7.0-staging] Bump branding to 7.0.7 (#84597)
carlossanlop Apr 11, 2023
2165458
[release/7.0-staging] Update dependencies from dotnet/arcade dotnet/l…
dotnet-maestro[bot] Apr 12, 2023
70c91e2
Fix AwaitableSocketAsyncEventArgs reorderings on weaker memory models…
github-actions[bot] Apr 14, 2023
bc4b1f2
Merge pull request #84611 from dotnet-maestro-bot/merge/release/7.0-t…
carlossanlop Apr 19, 2023
6e3c5c7
Backport #78136 to .NET 7 (#84936)
jkoritzinsky Apr 21, 2023
b3793a9
Update dependencies from https://github.com/dotnet/icu build 20230418…
dotnet-maestro[bot] Apr 24, 2023
91c7793
Skip DllImportSearchPathsTest on wasm (#84735)
elinor-fung Apr 24, 2023
f61192d
[PERF] Remove pipeline dependencies and steps for running Maui Mobile…
LoopedBard3 Apr 24, 2023
7aa3f0c
Backport PR#77480 to 7.0. (#85309)
PeterSolMS Apr 25, 2023
f16c731
Add metadata update for overrides (#85259)
fanyang-mono Apr 26, 2023
fbd8c18
Caching settings.pause_mode to avoid deadlock (#84738)
github-actions[bot] Apr 26, 2023
86ce6a1
[release/7.0-staging] Update dependencies from dotnet/hotreload-utils…
dotnet-maestro[bot] Apr 27, 2023
06e5b35
[native-library] If a dllimport is specified with an absolute path, l…
github-actions[bot] Apr 27, 2023
3a80b29
Added the ability to specify a Spin Count Unit via a GC Configuration…
mrsharm Apr 27, 2023
12aaae4
Fix createdump arg parsing for signal-based exceptions (#85423)
github-actions[bot] Apr 28, 2023
693a3c6
define UNW_AARCH64 aliases conditionally (#84874)
VSadov May 3, 2023
98528ec
Merge pull request #85719 from dotnet-maestro-bot/merge/release/7.0-t…
carlossanlop May 3, 2023
7416d98
Add missing TarFile.CreateFromDirectoryAsync roundtrip tests. (#84856)
github-actions[bot] May 3, 2023
17d84d7
Add status code and exception info to System.Net.Http events (#84806)
MihaZupan May 3, 2023
47f52f1
[release/7.0-staging] Update dependencies from xharness, arcade (#85726)
dotnet-maestro[bot] May 4, 2023
c8ab0d3
[release/7.0-staging] Make WindowsServiceLifetime gracefully stop (#8…
ericstj May 4, 2023
5b71fde
Servicing docs improvements (#85731)
carlossanlop May 6, 2023
cd73b4f
Port perfmap work to 7 (#85072)
davmason May 8, 2023
bf47f0d
[Release/7.0] Port EventCounters multi session support to 7.0 (#84679)
davmason May 11, 2023
2b28c92
[release/7.0-staging] [browser] fix job queue timespan calculation (#…
github-actions[bot] May 12, 2023
e005374
Fix HTTP3 header decoder buffer allocation (#78862) (#85977)
ManickaP May 15, 2023
fb0bf59
Update dependencies from https://github.com/dotnet/emsdk build 202305…
dotnet-maestro[bot] May 15, 2023
bf7c094
Add linker flags to add fixup data to PDBs (#58417) (#84358)
github-actions[bot] May 15, 2023
6f9d91c
[release/7.0] Suppress clang-16 warnings (backport #81573) (#84444)
ayakael May 15, 2023
edef3b9
[release/7.0-staging] Microsoft.NETCore.Platforms: support adding rid…
github-actions[bot] May 16, 2023
b4a441a
add RID for Alpine 3.18 (#86280)
github-actions[bot] May 16, 2023
eb3160d
Add Ubuntu 22.10 kinetic kudu RIDs for .NET 7 (#84984)
dviererbe May 16, 2023
1182123
[7.0-staging] Reset OOB packages from 7.0.6 (#84600)
carlossanlop May 16, 2023
92f8090
Add Ubuntu 23.10 (Mantic Minotaur) RIDs to .NET 7 (#86306)
dviererbe May 16, 2023
a2fd545
Merge branch 'release/7.0' into release/7.0-staging
carlossanlop May 16, 2023
751fa8b
Revert "[7.0-staging] Reset OOB packages from 7.0.6 (#84600)"
carlossanlop May 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Port perfmap work to 7 (#85072)
Co-authored-by: Daniel Ramos <[email protected]>
  • Loading branch information
davmason and Daniel Ramos authored May 8, 2023
commit cd73b4f758f15d4f798372e1321f152231e6fd50
154 changes: 102 additions & 52 deletions src/coreclr/vm/perfmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "perfinfo.h"
#include "pal.h"


// The code addresses are actually native image offsets during crossgen. Print
// them as 32-bit numbers for consistent output when cross-targeting and to
// make the output more compact.
Expand All @@ -21,14 +22,23 @@
Volatile<bool> PerfMap::s_enabled = false;
PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
unsigned PerfMap::s_StubsMapped = 0;

enum
{
DISABLED,
ALL,
JITDUMP,
PERFMAP
};

// Initialize the map for the process - called from EEStartupHelper.
void PerfMap::Initialize()
{
LIMITED_METHOD_CONTRACT;

// Only enable the map if requested.
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled))
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == ALL || CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == PERFMAP)
{
// Get the current process id.
int currentPid = GetCurrentProcessId();
Expand All @@ -49,7 +59,10 @@ void PerfMap::Initialize()
}

s_enabled = true;
}

if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == ALL || CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == JITDUMP)
{
const char* jitdumpPath;
char jitdumpPathBuffer[4096];

Expand All @@ -65,6 +78,13 @@ void PerfMap::Initialize()
}

PAL_PerfJitDump_Start(jitdumpPath);

if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapShowOptimizationTiers) != 0)
{
s_ShowOptimizationTiers = true;
}

s_enabled = true;
}
}

Expand All @@ -89,8 +109,6 @@ PerfMap::PerfMap(int pid)
// Initialize with no failures.
m_ErrorEncountered = false;

m_StubsMapped = 0;

// Build the path to the map file on disk.
WCHAR tempPath[MAX_LONGPATH+1];
if(!GetTempPathW(MAX_LONGPATH, tempPath))
Expand All @@ -117,8 +135,6 @@ PerfMap::PerfMap()

// Initialize with no failures.
m_ErrorEncountered = false;

m_StubsMapped = 0;
}

// Clean-up resources.
Expand Down Expand Up @@ -156,6 +172,11 @@ void PerfMap::WriteLine(SString& line)
{
STANDARD_VM_CONTRACT;

if (m_FileStream == nullptr || m_ErrorEncountered)
{
return;
}

EX_TRY
{
// Write the line.
Expand All @@ -176,50 +197,9 @@ void PerfMap::WriteLine(SString& line)
EX_CATCH{} EX_END_CATCH(SwallowAllExceptions);
}

// Log a method to the map.
void PerfMap::LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, const char *optimizationTier)
{
CONTRACTL{
THROWS;
GC_NOTRIGGER;
MODE_PREEMPTIVE;
PRECONDITION(pMethod != nullptr);
PRECONDITION(pCode != nullptr);
PRECONDITION(codeSize > 0);
} CONTRACTL_END;

if (m_FileStream == nullptr || m_ErrorEncountered)
{
// A failure occurred, do not log.
return;
}

// Logging failures should not cause any exceptions to flow upstream.
EX_TRY
{
// Get the full method signature.
SString name;
pMethod->GetFullMethodInfo(name);

// Build the map file line.
if (optimizationTier != nullptr && s_ShowOptimizationTiers)
{
name.AppendPrintf("[%s]", optimizationTier);
}
SString line;
line.Printf(FMT_CODE_ADDR " %x %s\n", pCode, codeSize, name.GetUTF8());

// Write the line.
WriteLine(line);
PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr);
}
EX_CATCH{} EX_END_CATCH(SwallowAllExceptions);
}


void PerfMap::LogImageLoad(PEAssembly * pPEAssembly)
{
if (s_enabled)
if (s_enabled && s_Current != nullptr)
{
s_Current->LogImage(pPEAssembly);
}
Expand Down Expand Up @@ -258,6 +238,15 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
{
LIMITED_METHOD_CONTRACT;

CONTRACTL{
THROWS;
GC_NOTRIGGER;
MODE_PREEMPTIVE;
PRECONDITION(pMethod != nullptr);
PRECONDITION(pCode != nullptr);
PRECONDITION(codeSize > 0);
} CONTRACTL_END;

if (!s_enabled)
{
return;
Expand All @@ -269,7 +258,31 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
optimizationTier = PrepareCodeConfig::GetJitOptimizationTierStr(pConfig, pMethod);
}

s_Current->LogMethod(pMethod, pCode, codeSize, optimizationTier);
// Logging failures should not cause any exceptions to flow upstream.
EX_TRY
{
// Get the full method signature.
SString name;
pMethod->GetFullMethodInfo(name);

// Build the map file line.
if (optimizationTier != nullptr && s_ShowOptimizationTiers)
{
name.AppendPrintf("[%s]", optimizationTier);
}

SString line;
line.Printf(FMT_CODE_ADDR " %x %s\n", pCode, codeSize, name.GetUTF8());

// Write the line.
if(s_Current != nullptr)
{
s_Current->WriteLine(line);
}
PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr);
}
EX_CATCH{} EX_END_CATCH(SwallowAllExceptions);

}

// Log a pre-compiled method to the perfmap.
Expand Down Expand Up @@ -326,7 +339,7 @@ void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode,
{
LIMITED_METHOD_CONTRACT;

if (!s_enabled || s_Current->m_FileStream == nullptr)
if (!s_enabled)
{
return;
}
Expand All @@ -344,13 +357,15 @@ void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode,
}

SString name;
// Build the map file line.
name.Printf("stub<%d> %s<%s>", ++(s_Current->m_StubsMapped), stubType, stubOwner);
name.Printf("stub<%d> %s<%s>", ++(s_StubsMapped), stubType, stubOwner);
SString line;
line.Printf(FMT_CODE_ADDR " %x %s\n", pCode, codeSize, name.GetUTF8());

// Write the line.
s_Current->WriteLine(line);
if(s_Current != nullptr)
{
s_Current->WriteLine(line);
}
PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr);
}
EX_CATCH{} EX_END_CATCH(SwallowAllExceptions);
Expand Down Expand Up @@ -407,6 +422,41 @@ NativeImagePerfMap::NativeImagePerfMap(Assembly * pAssembly, BSTR pDestPath)
}
}

void NativeImagePerfMap::LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, const char *optimizationTier)
{
CONTRACTL{
THROWS;
GC_NOTRIGGER;
MODE_PREEMPTIVE;
PRECONDITION(pMethod != nullptr);
PRECONDITION(pCode != nullptr);
PRECONDITION(codeSize > 0);
} CONTRACTL_END;

// Logging failures should not cause any exceptions to flow upstream.
EX_TRY
{
// Get the full method signature.
SString name;
pMethod->GetFullMethodInfo(name);

// Build the map file line.
if (optimizationTier != nullptr && s_ShowOptimizationTiers)
{
name.AppendPrintf("[%s]", optimizationTier);
}
SString line;
line.Printf(FMT_CODE_ADDR " %x %s\n", pCode, codeSize, name.GetUTF8());

if (s_Current != nullptr)
{
s_Current->WriteLine(line);
}
PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr);
}
EX_CATCH{} EX_END_CATCH(SwallowAllExceptions);
}

// Log data to the perfmap for the specified module.
void NativeImagePerfMap::LogDataForModule(Module * pModule)
{
Expand Down
28 changes: 14 additions & 14 deletions src/coreclr/vm/perfmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ class PerfMap
private:
static Volatile<bool> s_enabled;

// The one and only PerfMap for the process.
static PerfMap * s_Current;

// Indicates whether optimization tiers should be shown for methods in perf maps
static bool s_ShowOptimizationTiers;
// Set to true if an error is encountered when writing to the file.
static unsigned s_StubsMapped;

// The file stream to write the map to.
CFileStream * m_FileStream;
Expand All @@ -33,16 +30,16 @@ class PerfMap
// Set to true if an error is encountered when writing to the file.
bool m_ErrorEncountered;

// Set to true if an error is encountered when writing to the file.
unsigned m_StubsMapped;

// Construct a new map for the specified pid.
PerfMap(int pid);

// Write a line to the map file.
void WriteLine(SString & line);

protected:
// Indicates whether optimization tiers should be shown for methods in perf maps
static bool s_ShowOptimizationTiers;

// The one and only PerfMap for the process.
static PerfMap * s_Current;

// Construct a new map without a specified file name.
// Used for offline creation of NGEN map files.
PerfMap();
Expand All @@ -53,16 +50,16 @@ class PerfMap
// Open the perf map file for write.
void OpenFile(SString& path);

// Does the actual work to log a method to the map.
void LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, const char *optimizationTier);

// Does the actual work to log an image
void LogImage(PEAssembly * pPEAssembly);

// Get the image signature and store it as a string.
static void GetNativeImageSignature(PEAssembly * pPEAssembly, WCHAR * pwszSig, unsigned int nSigSize);

public:
// Write a line to the map file.
void WriteLine(SString & line);

// Initialize the map for the current process.
static void Initialize();

Expand Down Expand Up @@ -91,6 +88,9 @@ class NativeImagePerfMap : PerfMap
// Specify the address format since it's now possible for 'perf script' to output file offsets or RVAs.
bool m_EmitRVAs;

// Does the actual work to log a method to the map.
void LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, const char *optimizationTier);

// Log a pre-compiled method to the map.
void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode, PEImageLayout *pLoadedLayout, const char *optimizationTier);

Expand Down