Skip to content

Commit

Permalink
Handle the case when pid replacement is not needed (#73664)
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung authored Aug 10, 2022
1 parent 9bd2cb5 commit 7c9b252
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/inc/stresslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
#define STRESS_LOG_GC_STACK
#endif //_DEBUG

void AppendPid(LPCWSTR logFilename, LPWSTR fileName, size_t fileNameLength);
LPCWSTR ReplacePid(LPCWSTR logFilename, LPWSTR fileName, size_t fileNameLength);

class ThreadStressLog;

Expand Down
11 changes: 8 additions & 3 deletions src/coreclr/utilcode/stresslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void StressLog::Leave(CRITSEC_COOKIE) {
DecCantAllocCount();
}

void AppendPid(LPCWSTR logFilename, LPWSTR fileName, size_t fileNameLength)
LPCWSTR ReplacePid(LPCWSTR logFilename, LPWSTR fileName, size_t fileNameLength)
{
// if the string "{pid}" occurs in the logFilename,
// replace it by the PID of our process
Expand All @@ -164,6 +164,11 @@ void AppendPid(LPCWSTR logFilename, LPWSTR fileName, size_t fileNameLength)

// append the rest of the filename
wcscat_s(fileName, fileNameLength, logFilename + pidInx + wcslen(pidLit));
return fileName;
}
else
{
return logFilename;
}
}

Expand All @@ -176,9 +181,9 @@ static LPVOID CreateMemoryMappedFile(LPWSTR logFilename, size_t maxBytesTotal)
}

WCHAR fileName[MAX_PATH];
AppendPid(logFilename, fileName, MAX_PATH);
LPCWSTR logFilenameReplaced = ReplacePid(logFilename, fileName, MAX_PATH);

HandleHolder hFile = WszCreateFile(fileName,
HandleHolder hFile = WszCreateFile(logFilenameReplaced,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL, // default security descriptor
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/finalizerthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ VOID FinalizerThread::FinalizerThreadWorker(void *args)

// Writing an empty file to indicate completion
WCHAR outputPath[MAX_PATH];
AppendPid(GENAWARE_COMPLETION_FILE_NAME, outputPath, MAX_PATH);
fclose(_wfopen(outputPath, W("w+")));
LPCWSTR outputPathReplaced = ReplacePid(GENAWARE_COMPLETION_FILE_NAME, outputPath, MAX_PATH);
fclose(_wfopen(outputPathReplaced, W("w+")));
}

if (!bPriorityBoosted)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1702,8 +1702,8 @@ void GCToEEInterface::AnalyzeSurvivorsFinished(size_t gcIndex, int condemnedGene
EX_TRY
{
WCHAR outputPath[MAX_PATH];
AppendPid(GENAWARE_DUMP_FILE_NAME, outputPath, MAX_PATH);
GenerateDump (outputPath, 2, GenerateDumpFlagsNone, nullptr, 0);
LPCWSTR outputPathReplaced = ReplacePid(GENAWARE_DUMP_FILE_NAME, outputPath, MAX_PATH);
GenerateDump (outputPathReplaced, 2, GenerateDumpFlagsNone, nullptr, 0);
}
EX_CATCH {}
EX_END_CATCH(SwallowAllExceptions);
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/genanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool gcGenAnalysisDump = false;
/* static */ void GenAnalysis::EnableGenerationalAwareSession()
{
WCHAR outputPath[MAX_PATH];
AppendPid(GENAWARE_TRACE_FILE_NAME, outputPath, MAX_PATH);
LPCWSTR outputPathReplaced = ReplacePid(GENAWARE_TRACE_FILE_NAME, outputPath, MAX_PATH);

NewArrayHolder<COR_PRF_EVENTPIPE_PROVIDER_CONFIG> pProviders;
int providerCnt = 1;
Expand All @@ -94,7 +94,7 @@ bool gcGenAnalysisDump = false;

EventPipeProviderConfigurationAdapter configAdapter(pProviders, providerCnt);
gcGenAnalysisEventPipeSessionId = EventPipeAdapter::Enable(
outputPath,
outputPathReplaced,
gcGenAnalysisBufferMB,
configAdapter,
EP_SESSION_TYPE_FILE,
Expand Down

0 comments on commit 7c9b252

Please sign in to comment.