Skip to content

Commit 622277e

Browse files
authored
Separate the generation of PerfMap and JitDump files (#82142)
1 parent 49da0bd commit 622277e

File tree

2 files changed

+70
-53
lines changed

2 files changed

+70
-53
lines changed

src/coreclr/vm/perfmap.cpp

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "perfinfo.h"
1313
#include "pal.h"
1414

15+
1516
// The code addresses are actually native image offsets during crossgen. Print
1617
// them as 32-bit numbers for consistent output when cross-targeting and to
1718
// make the output more compact.
@@ -21,14 +22,23 @@
2122
Volatile<bool> PerfMap::s_enabled = false;
2223
PerfMap * PerfMap::s_Current = nullptr;
2324
bool PerfMap::s_ShowOptimizationTiers = false;
25+
unsigned PerfMap::s_StubsMapped = 0;
26+
27+
enum
28+
{
29+
DISABLED,
30+
ALL,
31+
JITDUMP,
32+
PERFMAP
33+
};
2434

2535
// Initialize the map for the process - called from EEStartupHelper.
2636
void PerfMap::Initialize()
2737
{
2838
LIMITED_METHOD_CONTRACT;
2939

3040
// Only enable the map if requested.
31-
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled))
41+
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == ALL || CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == PERFMAP)
3242
{
3343
// Get the current process id.
3444
int currentPid = GetCurrentProcessId();
@@ -49,7 +59,10 @@ void PerfMap::Initialize()
4959
}
5060

5161
s_enabled = true;
62+
}
5263

64+
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == ALL || CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled) == JITDUMP)
65+
{
5366
const char* jitdumpPath;
5467
char jitdumpPathBuffer[4096];
5568

@@ -65,6 +78,13 @@ void PerfMap::Initialize()
6578
}
6679

6780
PAL_PerfJitDump_Start(jitdumpPath);
81+
82+
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapShowOptimizationTiers) != 0)
83+
{
84+
s_ShowOptimizationTiers = true;
85+
}
86+
87+
s_enabled = true;
6888
}
6989
}
7090

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

92-
m_StubsMapped = 0;
93-
94112
// Build the path to the map file on disk.
95113
WCHAR tempPath[MAX_LONGPATH+1];
96114
if(!GetTempPathW(MAX_LONGPATH, tempPath))
@@ -119,7 +137,7 @@ PerfMap::PerfMap()
119137
// Initialize with no failures.
120138
m_ErrorEncountered = false;
121139

122-
m_StubsMapped = 0;
140+
s_StubsMapped = 0;
123141
}
124142

125143
// Clean-up resources.
@@ -157,6 +175,11 @@ void PerfMap::WriteLine(SString& line)
157175
{
158176
STANDARD_VM_CONTRACT;
159177

178+
if (m_FileStream == nullptr || m_ErrorEncountered)
179+
{
180+
return;
181+
}
182+
160183
EX_TRY
161184
{
162185
// Write the line.
@@ -177,50 +200,9 @@ void PerfMap::WriteLine(SString& line)
177200
EX_CATCH{} EX_END_CATCH(SwallowAllExceptions);
178201
}
179202

180-
// Log a method to the map.
181-
void PerfMap::LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, const char *optimizationTier)
182-
{
183-
CONTRACTL{
184-
THROWS;
185-
GC_NOTRIGGER;
186-
MODE_PREEMPTIVE;
187-
PRECONDITION(pMethod != nullptr);
188-
PRECONDITION(pCode != nullptr);
189-
PRECONDITION(codeSize > 0);
190-
} CONTRACTL_END;
191-
192-
if (m_FileStream == nullptr || m_ErrorEncountered)
193-
{
194-
// A failure occurred, do not log.
195-
return;
196-
}
197-
198-
// Logging failures should not cause any exceptions to flow upstream.
199-
EX_TRY
200-
{
201-
// Get the full method signature.
202-
SString name;
203-
pMethod->GetFullMethodInfo(name);
204-
205-
// Build the map file line.
206-
if (optimizationTier != nullptr && s_ShowOptimizationTiers)
207-
{
208-
name.AppendPrintf("[%s]", optimizationTier);
209-
}
210-
SString line;
211-
line.Printf(FMT_CODE_ADDR " %x %s\n", pCode, codeSize, name.GetUTF8());
212-
213-
// Write the line.
214-
WriteLine(line);
215-
PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr);
216-
}
217-
EX_CATCH{} EX_END_CATCH(SwallowAllExceptions);
218-
}
219-
220-
221203
void PerfMap::LogImageLoad(PEAssembly * pPEAssembly)
222204
{
223-
if (s_enabled)
205+
if (s_enabled && s_Current != nullptr)
224206
{
225207
s_Current->LogImage(pPEAssembly);
226208
}
@@ -259,6 +241,15 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
259241
{
260242
LIMITED_METHOD_CONTRACT;
261243

244+
CONTRACTL{
245+
THROWS;
246+
GC_NOTRIGGER;
247+
MODE_PREEMPTIVE;
248+
PRECONDITION(pMethod != nullptr);
249+
PRECONDITION(pCode != nullptr);
250+
PRECONDITION(codeSize > 0);
251+
} CONTRACTL_END;
252+
262253
if (!s_enabled)
263254
{
264255
return;
@@ -270,7 +261,30 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
270261
optimizationTier = PrepareCodeConfig::GetJitOptimizationTierStr(pConfig, pMethod);
271262
}
272263

273-
s_Current->LogMethod(pMethod, pCode, codeSize, optimizationTier);
264+
// Logging failures should not cause any exceptions to flow upstream.
265+
EX_TRY
266+
{
267+
// Get the full method signature.
268+
SString name;
269+
pMethod->GetFullMethodInfo(name);
270+
271+
// Build the map file line.
272+
if (optimizationTier != nullptr && s_ShowOptimizationTiers)
273+
{
274+
name.AppendPrintf("[%s]", optimizationTier);
275+
}
276+
SString line;
277+
line.Printf(FMT_CODE_ADDR " %x %s\n", pCode, codeSize, name.GetUTF8());
278+
279+
// Write the line.
280+
if(s_Current != nullptr)
281+
{
282+
s_Current->WriteLine(line);
283+
}
284+
PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr);
285+
}
286+
EX_CATCH{} EX_END_CATCH(SwallowAllExceptions);
287+
274288
}
275289

276290
// Log a pre-compiled method to the perfmap.
@@ -327,7 +341,7 @@ void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode,
327341
{
328342
LIMITED_METHOD_CONTRACT;
329343

330-
if (!s_enabled || s_Current->m_FileStream == nullptr)
344+
if (!s_enabled)
331345
{
332346
return;
333347
}
@@ -346,12 +360,15 @@ void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode,
346360

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

353367
// Write the line.
354-
s_Current->WriteLine(line);
368+
if(s_Current != nullptr)
369+
{
370+
s_Current->WriteLine(line);
371+
}
355372
PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr);
356373
}
357374
EX_CATCH{} EX_END_CATCH(SwallowAllExceptions);

src/coreclr/vm/perfmap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class PerfMap
2424
// Indicates whether optimization tiers should be shown for methods in perf maps
2525
static bool s_ShowOptimizationTiers;
2626

27+
// Set to true if an error is encountered when writing to the file.
28+
static unsigned s_StubsMapped;
29+
2730
// The file stream to write the map to.
2831
CFileStream * m_FileStream;
2932

@@ -33,9 +36,6 @@ class PerfMap
3336
// Set to true if an error is encountered when writing to the file.
3437
bool m_ErrorEncountered;
3538

36-
// Set to true if an error is encountered when writing to the file.
37-
unsigned m_StubsMapped;
38-
3939
// Construct a new map for the specified pid.
4040
PerfMap(int pid);
4141

0 commit comments

Comments
 (0)