Skip to content

Commit

Permalink
Add Pid support for all genaware analysis files
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung committed Aug 6, 2022
1 parent 529bfb6 commit 4b843da
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 45 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/inc/stresslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@
#define STRESS_LOG_GC_STACK
#endif //_DEBUG

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

class ThreadStressLog;

struct StressLogMsg;
Expand Down
32 changes: 18 additions & 14 deletions src/coreclr/utilcode/stresslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,38 +143,42 @@ void StressLog::Leave(CRITSEC_COOKIE) {
DecCantAllocCount();
}

#ifdef MEMORY_MAPPED_STRESSLOG
static LPVOID CreateMemoryMappedFile(LPWSTR logFilename, size_t maxBytesTotal)
void AppendPid(LPCWSTR logFilename, LPWSTR fileName, size_t fileNameLength)
{
if (maxBytesTotal < sizeof(StressLog::StressLogHeader))
{
return nullptr;
}
WCHAR fileName[MAX_PATH];

// if the string "{pid}" occurs in the logFilename,
// replace it by the PID of our process
// only the first occurrence will be replaced
const WCHAR* pidLit = W("{pid}");
WCHAR* pidPtr = wcsstr(logFilename, pidLit);
const WCHAR* pidPtr = wcsstr(logFilename, pidLit);
if (pidPtr != nullptr)
{
// copy the file name up to the "{pid}" occurrence
ptrdiff_t pidInx = pidPtr - logFilename;
wcsncpy_s(fileName, MAX_PATH, logFilename, pidInx);
wcsncpy_s(fileName, fileNameLength, logFilename, pidInx);

// append the string representation of the PID
DWORD pid = GetCurrentProcessId();
WCHAR pidStr[20];
_itow_s(pid, pidStr, ARRAY_SIZE(pidStr), 10);
wcscat_s(fileName, MAX_PATH, pidStr);
wcscat_s(fileName, fileNameLength, pidStr);

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

logFilename = fileName;
#ifdef MEMORY_MAPPED_STRESSLOG
static LPVOID CreateMemoryMappedFile(LPWSTR logFilename, size_t maxBytesTotal)
{
if (maxBytesTotal < sizeof(StressLog::StressLogHeader))
{
return nullptr;
}
HandleHolder hFile = WszCreateFile(logFilename,

WCHAR fileName[MAX_PATH];
AppendPid(logFilename, fileName, MAX_PATH);

HandleHolder hFile = WszCreateFile(fileName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL, // default security descriptor
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/vm/finalizerthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@ VOID FinalizerThread::FinalizerThreadWorker(void *args)
GenAnalysis::EnableGenerationalAwareSession();
#endif
}

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

if (!bPriorityBoosted)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/vm/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,9 @@ void GCToEEInterface::AnalyzeSurvivorsFinished(size_t gcIndex, int condemnedGene
{
EX_TRY
{
GenerateDump (GENAWARE_DUMP_FILE_NAME, 2, GenerateDumpFlagsNone, nullptr, 0);
WCHAR outputPath[MAX_PATH];
AppendPid(GENAWARE_DUMP_FILE_NAME, outputPath, MAX_PATH);
GenerateDump (outputPath, 2, GenerateDumpFlagsNone, nullptr, 0);
}
EX_CATCH {}
EX_END_CATCH(SwallowAllExceptions);
Expand Down
29 changes: 2 additions & 27 deletions src/coreclr/vm/genanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,8 @@ bool gcGenAnalysisDump = false;

/* static */ void GenAnalysis::EnableGenerationalAwareSession()
{
LPCWSTR outputPath = nullptr;
outputPath = GENAWARE_TRACE_FILE_NAME;

// if the string "{pid}" occurs in the logFilename,
// replace it by the PID of our process
// only the first occurrence will be replaced

WCHAR fileName[MAX_PATH];
const WCHAR* pidLit = W("{pid}");
const WCHAR* pidPtr = wcsstr(outputPath, pidLit);
if (pidPtr != nullptr)
{
// copy the file name up to the "{pid}" occurrence
ptrdiff_t pidInx = pidPtr - outputPath;
wcsncpy_s(fileName, MAX_PATH, outputPath, pidInx);

// append the string representation of the PID
DWORD pid = GetCurrentProcessId();
WCHAR pidStr[20];
_itow_s(pid, pidStr, ARRAY_SIZE(pidStr), 10);
wcscat_s(fileName, MAX_PATH, pidStr);

// append the rest of the filename
wcscat_s(fileName, MAX_PATH, outputPath + pidInx + wcslen(pidLit));

outputPath = fileName;
}
WCHAR outputPath[MAX_PATH];
AppendPid(GENAWARE_TRACE_FILE_NAME, outputPath, MAX_PATH);

NewArrayHolder<COR_PRF_EVENTPIPE_PROVIDER_CONFIG> pProviders;
int providerCnt = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/genanalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ enum GcGenAnalysisState
};

#define GENAWARE_TRACE_FILE_NAME W("gcgenaware.{pid}.nettrace")
#define GENAWARE_DUMP_FILE_NAME W("gcgenaware.dmp")
#define GENAWARE_COMPLETION_FILE_NAME "gcgenaware.nettrace.completed"
#define GENAWARE_DUMP_FILE_NAME W("gcgenaware.{pid}.dmp")
#define GENAWARE_COMPLETION_FILE_NAME W("gcgenaware.{pid}.nettrace.completed")

extern bool s_forcedGCInProgress;
extern GcGenAnalysisState gcGenAnalysisState;
Expand Down

0 comments on commit 4b843da

Please sign in to comment.