Skip to content

Commit 4b843da

Browse files
committed
Add Pid support for all genaware analysis files
1 parent 529bfb6 commit 4b843da

File tree

6 files changed

+31
-45
lines changed

6 files changed

+31
-45
lines changed

src/coreclr/inc/stresslog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@
259259
#define STRESS_LOG_GC_STACK
260260
#endif //_DEBUG
261261

262+
void AppendPid(LPCWSTR logFilename, LPWSTR fileName, size_t fileNameLength);
263+
262264
class ThreadStressLog;
263265

264266
struct StressLogMsg;

src/coreclr/utilcode/stresslog.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,38 +143,42 @@ void StressLog::Leave(CRITSEC_COOKIE) {
143143
DecCantAllocCount();
144144
}
145145

146-
#ifdef MEMORY_MAPPED_STRESSLOG
147-
static LPVOID CreateMemoryMappedFile(LPWSTR logFilename, size_t maxBytesTotal)
146+
void AppendPid(LPCWSTR logFilename, LPWSTR fileName, size_t fileNameLength)
148147
{
149-
if (maxBytesTotal < sizeof(StressLog::StressLogHeader))
150-
{
151-
return nullptr;
152-
}
153-
WCHAR fileName[MAX_PATH];
154-
155148
// if the string "{pid}" occurs in the logFilename,
156149
// replace it by the PID of our process
157150
// only the first occurrence will be replaced
158151
const WCHAR* pidLit = W("{pid}");
159-
WCHAR* pidPtr = wcsstr(logFilename, pidLit);
152+
const WCHAR* pidPtr = wcsstr(logFilename, pidLit);
160153
if (pidPtr != nullptr)
161154
{
162155
// copy the file name up to the "{pid}" occurrence
163156
ptrdiff_t pidInx = pidPtr - logFilename;
164-
wcsncpy_s(fileName, MAX_PATH, logFilename, pidInx);
157+
wcsncpy_s(fileName, fileNameLength, logFilename, pidInx);
165158

166159
// append the string representation of the PID
167160
DWORD pid = GetCurrentProcessId();
168161
WCHAR pidStr[20];
169162
_itow_s(pid, pidStr, ARRAY_SIZE(pidStr), 10);
170-
wcscat_s(fileName, MAX_PATH, pidStr);
163+
wcscat_s(fileName, fileNameLength, pidStr);
171164

172165
// append the rest of the filename
173-
wcscat_s(fileName, MAX_PATH, logFilename + pidInx + wcslen(pidLit));
166+
wcscat_s(fileName, fileNameLength, logFilename + pidInx + wcslen(pidLit));
167+
}
168+
}
174169

175-
logFilename = fileName;
170+
#ifdef MEMORY_MAPPED_STRESSLOG
171+
static LPVOID CreateMemoryMappedFile(LPWSTR logFilename, size_t maxBytesTotal)
172+
{
173+
if (maxBytesTotal < sizeof(StressLog::StressLogHeader))
174+
{
175+
return nullptr;
176176
}
177-
HandleHolder hFile = WszCreateFile(logFilename,
177+
178+
WCHAR fileName[MAX_PATH];
179+
AppendPid(logFilename, fileName, MAX_PATH);
180+
181+
HandleHolder hFile = WszCreateFile(fileName,
178182
GENERIC_READ | GENERIC_WRITE,
179183
FILE_SHARE_READ,
180184
NULL, // default security descriptor

src/coreclr/vm/finalizerthread.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,11 @@ VOID FinalizerThread::FinalizerThreadWorker(void *args)
281281
GenAnalysis::EnableGenerationalAwareSession();
282282
#endif
283283
}
284+
284285
// Writing an empty file to indicate completion
285-
fclose(fopen(GENAWARE_COMPLETION_FILE_NAME,"w+"));
286+
WCHAR outputPath[MAX_PATH];
287+
AppendPid(GENAWARE_COMPLETION_FILE_NAME, outputPath, MAX_PATH);
288+
fclose(_wfopen(outputPath, W("w+")));
286289
}
287290

288291
if (!bPriorityBoosted)

src/coreclr/vm/gcenv.ee.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,9 @@ void GCToEEInterface::AnalyzeSurvivorsFinished(size_t gcIndex, int condemnedGene
16951695
{
16961696
EX_TRY
16971697
{
1698-
GenerateDump (GENAWARE_DUMP_FILE_NAME, 2, GenerateDumpFlagsNone, nullptr, 0);
1698+
WCHAR outputPath[MAX_PATH];
1699+
AppendPid(GENAWARE_DUMP_FILE_NAME, outputPath, MAX_PATH);
1700+
GenerateDump (outputPath, 2, GenerateDumpFlagsNone, nullptr, 0);
16991701
}
17001702
EX_CATCH {}
17011703
EX_END_CATCH(SwallowAllExceptions);

src/coreclr/vm/genanalysis.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,33 +76,8 @@ bool gcGenAnalysisDump = false;
7676

7777
/* static */ void GenAnalysis::EnableGenerationalAwareSession()
7878
{
79-
LPCWSTR outputPath = nullptr;
80-
outputPath = GENAWARE_TRACE_FILE_NAME;
81-
82-
// if the string "{pid}" occurs in the logFilename,
83-
// replace it by the PID of our process
84-
// only the first occurrence will be replaced
85-
86-
WCHAR fileName[MAX_PATH];
87-
const WCHAR* pidLit = W("{pid}");
88-
const WCHAR* pidPtr = wcsstr(outputPath, pidLit);
89-
if (pidPtr != nullptr)
90-
{
91-
// copy the file name up to the "{pid}" occurrence
92-
ptrdiff_t pidInx = pidPtr - outputPath;
93-
wcsncpy_s(fileName, MAX_PATH, outputPath, pidInx);
94-
95-
// append the string representation of the PID
96-
DWORD pid = GetCurrentProcessId();
97-
WCHAR pidStr[20];
98-
_itow_s(pid, pidStr, ARRAY_SIZE(pidStr), 10);
99-
wcscat_s(fileName, MAX_PATH, pidStr);
100-
101-
// append the rest of the filename
102-
wcscat_s(fileName, MAX_PATH, outputPath + pidInx + wcslen(pidLit));
103-
104-
outputPath = fileName;
105-
}
79+
WCHAR outputPath[MAX_PATH];
80+
AppendPid(GENAWARE_TRACE_FILE_NAME, outputPath, MAX_PATH);
10681

10782
NewArrayHolder<COR_PRF_EVENTPIPE_PROVIDER_CONFIG> pProviders;
10883
int providerCnt = 1;

src/coreclr/vm/genanalysis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ enum GcGenAnalysisState
1919
};
2020

2121
#define GENAWARE_TRACE_FILE_NAME W("gcgenaware.{pid}.nettrace")
22-
#define GENAWARE_DUMP_FILE_NAME W("gcgenaware.dmp")
23-
#define GENAWARE_COMPLETION_FILE_NAME "gcgenaware.nettrace.completed"
22+
#define GENAWARE_DUMP_FILE_NAME W("gcgenaware.{pid}.dmp")
23+
#define GENAWARE_COMPLETION_FILE_NAME W("gcgenaware.{pid}.nettrace.completed")
2424

2525
extern bool s_forcedGCInProgress;
2626
extern GcGenAnalysisState gcGenAnalysisState;

0 commit comments

Comments
 (0)