Skip to content

Commit e4c5b3e

Browse files
tommcdondavmason
andauthored
Write perfmap and jitdump files to /tmp by default (#88776)
Co-authored-by: David Mason <[email protected]>
1 parent 06b696c commit e4c5b3e

File tree

5 files changed

+38
-42
lines changed

5 files changed

+38
-42
lines changed

src/coreclr/inc/clrconfigvalues.h

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

482482
#ifdef FEATURE_PERFMAP
483483
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")
484-
RETAIL_CONFIG_STRING_INFO(EXTERNAL_PerfMapJitDumpPath, W("PerfMapJitDumpPath"), "Specifies a path to write the perf jitdump file. Defaults to GetTempPathA()")
484+
RETAIL_CONFIG_STRING_INFO_EX(EXTERNAL_PerfMapJitDumpPath, W("PerfMapJitDumpPath"), "Specifies a path to write the perf jitdump file. Defaults to /tmp", CLRConfig::LookupOptions::TrimWhiteSpaceFromStringValue)
485485
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")
486486
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.")
487487
#endif

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.GetUTF8(), 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, CHAR* guid);
2626

src/coreclr/vm/perfmap.cpp

Lines changed: 28 additions & 30 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;
@@ -36,6 +44,16 @@ void PerfMap::Initialize()
3644
PerfMap::Enable(perfMapType, false);
3745
}
3846

47+
const char * PerfMap::InternalConstructPath()
48+
{
49+
CLRConfigNoCache value = CLRConfigNoCache::Get("PerfMapJitDumpPath");
50+
if (value.IsSet())
51+
{
52+
return value.AsString();
53+
}
54+
return TEMP_DIRECTORY_PATH;
55+
}
56+
3957
void PerfMap::Enable(PerfMapType type, bool sendExisting)
4058
{
4159
LIMITED_METHOD_CONTRACT;
@@ -48,6 +66,8 @@ void PerfMap::Enable(PerfMapType type, bool sendExisting)
4866
{
4967
CrstHolder ch(&(s_csPerfMap));
5068

69+
const char* basePath = InternalConstructPath();
70+
5171
if (s_Current == nullptr && (type == PerfMapType::ALL || type == PerfMapType::PERFMAP))
5272
{
5373
s_Current = new PerfMap();
@@ -64,27 +84,13 @@ void PerfMap::Enable(PerfMapType type, bool sendExisting)
6484
}
6585

6686
int currentPid = GetCurrentProcessId();
67-
s_Current->OpenFileForPid(currentPid);
87+
s_Current->OpenFileForPid(currentPid, basePath);
6888
s_enabled = true;
6989
}
7090

7191
if (!PAL_PerfJitDump_IsStarted() && (type == PerfMapType::ALL || type == PerfMapType::JITDUMP))
72-
{
73-
const char* jitdumpPath;
74-
char jitdumpPathBuffer[4096];
75-
76-
CLRConfigNoCache value = CLRConfigNoCache::Get("PerfMapJitDumpPath");
77-
if (value.IsSet())
78-
{
79-
jitdumpPath = value.AsString();
80-
}
81-
else
82-
{
83-
GetTempPathA(sizeof(jitdumpPathBuffer) - 1, jitdumpPathBuffer);
84-
jitdumpPath = jitdumpPathBuffer;
85-
}
86-
87-
PAL_PerfJitDump_Start(jitdumpPath);
92+
{
93+
PAL_PerfJitDump_Start(basePath);
8894

8995
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapShowOptimizationTiers) != 0)
9096
{
@@ -209,23 +215,15 @@ PerfMap::~PerfMap()
209215
m_PerfInfo = nullptr;
210216
}
211217

212-
void PerfMap::OpenFileForPid(int pid)
218+
void PerfMap::OpenFileForPid(int pid, const char* basePath)
213219
{
214-
// Build the path to the map file on disk.
215-
WCHAR tempPath[MAX_LONGPATH+1];
216-
if(!GetTempPathW(MAX_LONGPATH, tempPath))
217-
{
218-
return;
219-
}
220-
221-
SString path;
222-
path.Append(tempPath);
223-
path.AppendPrintf("perf-%d.map", pid);
220+
SString fullPath;
221+
fullPath.Printf("%s/perf-%d.map", basePath, pid);
224222

225223
// Open the map file for writing.
226-
OpenFile(path);
224+
OpenFile(fullPath);
227225

228-
m_PerfInfo = new PerfInfo(pid);
226+
m_PerfInfo = new PerfInfo(pid, basePath);
229227
}
230228

231229
// Open the specified destination map file.

src/coreclr/vm/perfmap.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ class PerfMap
3838
// Set to true if an error is encountered when writing to the file.
3939
bool m_ErrorEncountered;
4040

41-
// Construct a new map for the specified pid.
41+
// Construct a new map
4242
PerfMap();
4343

44-
void OpenFileForPid(int pid);
44+
// Open a perfmap map for the specified pid
45+
void OpenFileForPid(int pid, const char* basePath);
4546

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

50+
// Default to /tmp or use DOTNET_PerfMapJitDumpPath if set
51+
static const char* InternalConstructPath();
52+
4953
protected:
5054
// Open the perf map file for write.
5155
void OpenFile(SString& path);

0 commit comments

Comments
 (0)