diff --git a/src/coreclr/inc/stresslog.h b/src/coreclr/inc/stresslog.h index ab84311792e4c3..58e1ba9660d3d5 100644 --- a/src/coreclr/inc/stresslog.h +++ b/src/coreclr/inc/stresslog.h @@ -259,6 +259,8 @@ #define STRESS_LOG_GC_STACK #endif //_DEBUG +void AppendPid(LPCWSTR logFilename, LPWSTR fileName, size_t fileNameLength); + class ThreadStressLog; struct StressLogMsg; diff --git a/src/coreclr/utilcode/stresslog.cpp b/src/coreclr/utilcode/stresslog.cpp index 6bb8229d8048d7..861f56da000310 100644 --- a/src/coreclr/utilcode/stresslog.cpp +++ b/src/coreclr/utilcode/stresslog.cpp @@ -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 diff --git a/src/coreclr/vm/ceemain.cpp b/src/coreclr/vm/ceemain.cpp index 36d63aa9e771dc..a45a6996c86bc9 100644 --- a/src/coreclr/vm/ceemain.cpp +++ b/src/coreclr/vm/ceemain.cpp @@ -651,7 +651,6 @@ void EEStartupHelper() // Initialize the event pipe. EventPipeAdapter::Initialize(); #endif // FEATURE_PERFTRACING - GenAnalysis::Initialize(); #ifdef TARGET_UNIX PAL_SetShutdownCallback(EESocketCleanupHelper); @@ -877,6 +876,7 @@ void EEStartupHelper() // EventPipe initialization, so this is done after the GC has been fully initialized. EventPipeAdapter::FinishInitialize(); #endif // FEATURE_PERFTRACING + GenAnalysis::Initialize(); // This isn't done as part of InitializeGarbageCollector() above because thread // creation requires AppDomains to have been set up. diff --git a/src/coreclr/vm/finalizerthread.cpp b/src/coreclr/vm/finalizerthread.cpp index e8370315e66651..9fce6cc34941b3 100644 --- a/src/coreclr/vm/finalizerthread.cpp +++ b/src/coreclr/vm/finalizerthread.cpp @@ -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) diff --git a/src/coreclr/vm/gcenv.ee.cpp b/src/coreclr/vm/gcenv.ee.cpp index 02537f0dd7f545..42c85aa788770c 100644 --- a/src/coreclr/vm/gcenv.ee.cpp +++ b/src/coreclr/vm/gcenv.ee.cpp @@ -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); diff --git a/src/coreclr/vm/genanalysis.cpp b/src/coreclr/vm/genanalysis.cpp index aa1248b4e56a39..358d0f0270138c 100644 --- a/src/coreclr/vm/genanalysis.cpp +++ b/src/coreclr/vm/genanalysis.cpp @@ -76,8 +76,9 @@ bool gcGenAnalysisDump = false; /* static */ void GenAnalysis::EnableGenerationalAwareSession() { - LPCWSTR outputPath = nullptr; - outputPath = GENAWARE_TRACE_FILE_NAME; + WCHAR outputPath[MAX_PATH]; + AppendPid(GENAWARE_TRACE_FILE_NAME, outputPath, MAX_PATH); + NewArrayHolder pProviders; int providerCnt = 1; pProviders = new COR_PRF_EVENTPIPE_PROVIDER_CONFIG[providerCnt]; @@ -110,4 +111,8 @@ bool gcGenAnalysisDump = false; EventPipeAdapter::StartStreaming(gcGenAnalysisEventPipeSessionId); gcGenAnalysisState = GcGenAnalysisState::Enabled; } + else + { + gcGenAnalysisTrace = false; + } } diff --git a/src/coreclr/vm/genanalysis.h b/src/coreclr/vm/genanalysis.h index aca019ff3837b9..ab24a61c9befb4 100644 --- a/src/coreclr/vm/genanalysis.h +++ b/src/coreclr/vm/genanalysis.h @@ -18,9 +18,9 @@ enum GcGenAnalysisState Done = 3, }; -#define GENAWARE_TRACE_FILE_NAME W("gcgenaware.nettrace") -#define GENAWARE_DUMP_FILE_NAME W("gcgenaware.dmp") -#define GENAWARE_COMPLETION_FILE_NAME "gcgenaware.nettrace.completed" +#define GENAWARE_TRACE_FILE_NAME W("gcgenaware.{pid}.nettrace") +#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; diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 6f16f990d0e71e..2dc9f624b6cc15 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -180,6 +180,7 @@ ep_session_alloc ( case EP_SESSION_TYPE_FILESTREAM : if (output_path) { file_stream_writer = ep_file_stream_writer_alloc (output_path); + ep_raise_error_if_nok (file_stream_writer != NULL); instance->file = ep_file_alloc (ep_file_stream_writer_get_stream_writer_ref (file_stream_writer), format); ep_raise_error_if_nok (instance->file != NULL); file_stream_writer = NULL;