Skip to content

Commit e43e315

Browse files
authored
Various fixes for generation aware analysis (#70764)
1 parent ccc2250 commit e43e315

File tree

8 files changed

+39
-22
lines changed

8 files changed

+39
-22
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/ceemain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ void EEStartupHelper()
673673
// Initialize the event pipe.
674674
EventPipeAdapter::Initialize();
675675
#endif // FEATURE_PERFTRACING
676-
GenAnalysis::Initialize();
677676

678677
#ifdef TARGET_UNIX
679678
PAL_SetShutdownCallback(EESocketCleanupHelper);
@@ -899,6 +898,7 @@ void EEStartupHelper()
899898
// EventPipe initialization, so this is done after the GC has been fully initialized.
900899
EventPipeAdapter::FinishInitialize();
901900
#endif // FEATURE_PERFTRACING
901+
GenAnalysis::Initialize();
902902

903903
// This isn't done as part of InitializeGarbageCollector() above because thread
904904
// creation requires AppDomains to have been set up.

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ bool gcGenAnalysisDump = false;
7676

7777
/* static */ void GenAnalysis::EnableGenerationalAwareSession()
7878
{
79-
LPCWSTR outputPath = nullptr;
80-
outputPath = GENAWARE_TRACE_FILE_NAME;
79+
WCHAR outputPath[MAX_PATH];
80+
AppendPid(GENAWARE_TRACE_FILE_NAME, outputPath, MAX_PATH);
81+
8182
NewArrayHolder<COR_PRF_EVENTPIPE_PROVIDER_CONFIG> pProviders;
8283
int providerCnt = 1;
8384
pProviders = new COR_PRF_EVENTPIPE_PROVIDER_CONFIG[providerCnt];
@@ -110,4 +111,8 @@ bool gcGenAnalysisDump = false;
110111
EventPipeAdapter::StartStreaming(gcGenAnalysisEventPipeSessionId);
111112
gcGenAnalysisState = GcGenAnalysisState::Enabled;
112113
}
114+
else
115+
{
116+
gcGenAnalysisTrace = false;
117+
}
113118
}

src/coreclr/vm/genanalysis.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ enum GcGenAnalysisState
1818
Done = 3,
1919
};
2020

21-
#define GENAWARE_TRACE_FILE_NAME W("gcgenaware.nettrace")
22-
#define GENAWARE_DUMP_FILE_NAME W("gcgenaware.dmp")
23-
#define GENAWARE_COMPLETION_FILE_NAME "gcgenaware.nettrace.completed"
21+
#define GENAWARE_TRACE_FILE_NAME W("gcgenaware.{pid}.nettrace")
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;

src/native/eventpipe/ep-session.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ ep_session_alloc (
180180
case EP_SESSION_TYPE_FILESTREAM :
181181
if (output_path) {
182182
file_stream_writer = ep_file_stream_writer_alloc (output_path);
183+
ep_raise_error_if_nok (file_stream_writer != NULL);
183184
instance->file = ep_file_alloc (ep_file_stream_writer_get_stream_writer_ref (file_stream_writer), format);
184185
ep_raise_error_if_nok (instance->file != NULL);
185186
file_stream_writer = NULL;

0 commit comments

Comments
 (0)