Skip to content

Commit a6b4969

Browse files
tommcdondavmason
andauthored
Write perfmap and jitdump files to /tmp by default [7.0 port] (#89053)
* Write perfmap and jitdump files to /tmp by default * Simplify perfmap path generation * Minor comment update --------- Co-authored-by: David Mason <[email protected]>
1 parent a75fb66 commit a6b4969

File tree

5 files changed

+59
-51
lines changed

5 files changed

+59
-51
lines changed

src/coreclr/inc/clrconfigvalues.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_ProfAPI_ValidateNGENInstrumentation, W("Pro
490490

491491
#ifdef FEATURE_PERFMAP
492492
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux to enable writing /tmp/perf-$pid.map. It is disabled by default")
493-
RETAIL_CONFIG_STRING_INFO(EXTERNAL_PerfMapJitDumpPath, W("PerfMapJitDumpPath"), "Specifies a path to write the perf jitdump file. Defaults to GetTempPathA()")
493+
RETAIL_CONFIG_STRING_INFO(EXTERNAL_PerfMapJitDumpPath, W("PerfMapJitDumpPath"), "Specifies a path to write the perf jitdump file. Defaults to /tmp")
494494
RETAIL_CONFIG_DWORD_INFO(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")
495495
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.")
496496
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.")

src/coreclr/vm/perfinfo.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@
1010
#include "perfinfo.h"
1111
#include "pal.h"
1212

13-
PerfInfo::PerfInfo(int pid)
13+
PerfInfo::PerfInfo(int pid, const char* basePath)
1414
: m_Stream(nullptr)
1515
{
1616
LIMITED_METHOD_CONTRACT;
1717

18-
SString tempPath;
19-
if (!WszGetTempPath(tempPath))
20-
{
21-
return;
22-
}
23-
2418
SString path;
25-
path.Printf("%Sperfinfo-%d.map", tempPath.GetUnicode(), pid);
19+
path.Printf("%s/perfinfo-%d.map", basePath, pid);
2620
OpenFile(path);
2721
}
2822

src/coreclr/vm/perfinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class PerfInfo {
2222
public:
23-
PerfInfo(int pid);
23+
PerfInfo(int pid, const char* basePath);
2424
~PerfInfo();
2525
void LogImage(PEAssembly* pPEAssembly, WCHAR* guid);
2626

src/coreclr/vm/perfmap.cpp

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919

2020
#define FMT_CODE_ADDR "%p"
2121

22+
#ifndef __ANDROID__
23+
#define TEMP_DIRECTORY_PATH "/tmp"
24+
#else
25+
// On Android, "/tmp/" doesn't exist; temporary files should go to
26+
// /data/local/tmp/
27+
#define TEMP_DIRECTORY_PATH "/data/local/tmp"
28+
#endif
29+
2230
Volatile<bool> PerfMap::s_enabled = false;
2331
PerfMap * PerfMap::s_Current = nullptr;
2432
bool PerfMap::s_ShowOptimizationTiers = false;
@@ -37,55 +45,64 @@ void PerfMap::Initialize()
3745
{
3846
LIMITED_METHOD_CONTRACT;
3947

48+
const DWORD perfMapEnabled = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled);
49+
if (perfMapEnabled == DISABLED)
50+
{
51+
return;
52+
}
53+
54+
// Build the path to the map file on disk.
55+
char tempPathBuffer[MAX_LONGPATH+1];
56+
const char* tempPath = InternalConstructPath(tempPathBuffer, sizeof(tempPathBuffer));
57+
4058
// Only enable the map if requested.
41-
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == ALL || CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == PERFMAP)
59+
if (perfMapEnabled == ALL || perfMapEnabled == PERFMAP)
4260
{
4361
// Get the current process id.
4462
int currentPid = GetCurrentProcessId();
4563

4664
// Create the map.
47-
s_Current = new PerfMap(currentPid);
65+
s_Current = new PerfMap(currentPid, tempPath);
4866

4967
int signalNum = (int) CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapIgnoreSignal);
5068

5169
if (signalNum > 0)
5270
{
5371
PAL_IgnoreProfileSignal(signalNum);
5472
}
55-
56-
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapShowOptimizationTiers) != 0)
57-
{
58-
s_ShowOptimizationTiers = true;
59-
}
60-
61-
s_enabled = true;
6273
}
6374

64-
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == ALL || CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == JITDUMP)
75+
// only enable JitDumps if requested
76+
if (perfMapEnabled == ALL || perfMapEnabled == JITDUMP)
6577
{
66-
const char* jitdumpPath;
67-
char jitdumpPathBuffer[4096];
78+
PAL_PerfJitDump_Start(tempPath);
79+
}
6880

69-
CLRConfigNoCache value = CLRConfigNoCache::Get("PerfMapJitDumpPath");
70-
if (value.IsSet())
71-
{
72-
jitdumpPath = value.AsString();
73-
}
74-
else
75-
{
76-
GetTempPathA(sizeof(jitdumpPathBuffer) - 1, jitdumpPathBuffer);
77-
jitdumpPath = jitdumpPathBuffer;
78-
}
81+
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapShowOptimizationTiers) != 0)
82+
{
83+
s_ShowOptimizationTiers = true;
84+
}
85+
86+
s_enabled = true;
87+
}
7988

80-
PAL_PerfJitDump_Start(jitdumpPath);
89+
// InternalConstructPath is guaranteed to return a non-null path
90+
// the function uses the input buffer only whe PerfMapJitDumpPath environment variable is set
91+
const char * PerfMap::InternalConstructPath(char *tmpBuf, int lenBuf)
92+
{
93+
DWORD len = GetEnvironmentVariableA("DOTNET_PerfMapJitDumpPath", tmpBuf, lenBuf);
94+
if (len == 0)
95+
{
96+
len = GetEnvironmentVariableA("COMPlus_PerfMapJitDumpPath", tmpBuf, lenBuf);
97+
}
8198

82-
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapShowOptimizationTiers) != 0)
83-
{
84-
s_ShowOptimizationTiers = true;
85-
}
86-
87-
s_enabled = true;
99+
if (len == 0 || // GetEnvironmentVariableA returns 0 if the variable is not found,
100+
len >= lenBuf) // or the length of the string not including the null terminator on success.
101+
{
102+
return TEMP_DIRECTORY_PATH;
88103
}
104+
105+
return tmpBuf;
89106
}
90107

91108
// Destroy the map for the process - called from EEShutdownHelper.
@@ -102,27 +119,21 @@ void PerfMap::Destroy()
102119
}
103120

104121
// Construct a new map for the process.
105-
PerfMap::PerfMap(int pid)
122+
PerfMap::PerfMap(int pid, const char* path)
106123
{
107124
LIMITED_METHOD_CONTRACT;
108125

109126
// Initialize with no failures.
110127
m_ErrorEncountered = false;
111128

112129
// Build the path to the map file on disk.
113-
WCHAR tempPath[MAX_LONGPATH+1];
114-
if(!GetTempPathW(MAX_LONGPATH, tempPath))
115-
{
116-
return;
117-
}
118-
119-
SString path;
120-
path.Printf("%Sperf-%d.map", &tempPath, pid);
130+
SString pathFile;
131+
pathFile.Printf("%s/perf-%d.map", path, pid);
121132

122133
// Open the map file for writing.
123-
OpenFile(path);
134+
OpenFile(pathFile);
124135

125-
m_PerfInfo = new PerfInfo(pid);
136+
m_PerfInfo = new PerfInfo(pid, path);
126137
}
127138

128139
// Construct a new map without a specified file name.

src/coreclr/vm/perfmap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class PerfMap
3131
bool m_ErrorEncountered;
3232

3333
// Construct a new map for the specified pid.
34-
PerfMap(int pid);
34+
PerfMap(int pid, const char* path);
35+
36+
// Default to /tmp or use DOTNET_PerfMapJitDumpPath if set
37+
static const char* InternalConstructPath(char *tmpBuf, int lenBuf);
3538

3639
protected:
3740
// Indicates whether optimization tiers should be shown for methods in perf maps

0 commit comments

Comments
 (0)