From ab7089ad6155ed105e1f29e673133d5f8c056b5b Mon Sep 17 00:00:00 2001 From: Imarok Date: Sat, 9 Sep 2017 13:16:05 +0000 Subject: [PATCH] Command line option for pid+timestamp in OOS dump, mainlog and interestinglog Reviewed by: elexis Fixes #3339 Differential Revision: https://code.wildfiregames.com/D51 This was SVN commit r20141. --- binaries/system/readme.txt | 2 ++ source/main.cpp | 9 +++++++++ source/network/NetClientTurnManager.cpp | 10 ++++++---- source/ps/CLogger.cpp | 8 +++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/binaries/system/readme.txt b/binaries/system/readme.txt index 61203a74f7..cf0720d4b0 100644 --- a/binaries/system/readme.txt +++ b/binaries/system/readme.txt @@ -64,6 +64,8 @@ Advanced / diagnostic: -rejointest=N simulates a rejoin and checks simulation state each turn for serialization errors; this is similar to a serialization test but much faster and less complete. It should be enough for debugging most rejoin OOSes. +-unique-logs adds unix timestamp and process id to the filename of mainlog.html, interestinglog.html + and oos_dump.txt to prevent these files from becoming overwritten by another pyrogenesis process. Windows-specific: -wQpcTscSafe allow timing via QueryPerformanceCounter despite the fact diff --git a/source/main.cpp b/source/main.cpp index 425747ae06..77603aec05 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -83,7 +83,13 @@ that of Atlas depending on commandline parameters. #include // geteuid #endif // OS_UNIX +#if MSC_VERSION +#include +#define getpid _getpid // Use the non-deprecated function name +#endif + extern bool g_GameRestarted; +extern CStrW g_UniqueLogPostfix; void kill_mainloop(); @@ -463,6 +469,9 @@ static void RunGameOrAtlas(int argc, const char* argv[]) return; } + if (args.Has("unique-logs")) + g_UniqueLogPostfix = L"_" + std::to_wstring(std::time(nullptr)) + L"_" + std::to_wstring(getpid()); + const bool isVisualReplay = args.Has("replay-visual"); const bool isNonVisualReplay = args.Has("replay"); const bool isNonVisual = args.Has("autostart-nonvisual"); diff --git a/source/network/NetClientTurnManager.cpp b/source/network/NetClientTurnManager.cpp index 341d27605c..abf785b431 100644 --- a/source/network/NetClientTurnManager.cpp +++ b/source/network/NetClientTurnManager.cpp @@ -33,6 +33,8 @@ #define NETCLIENTTURN_LOG(...) #endif +extern CStrW g_UniqueLogPostfix; + CNetClientTurnManager::CNetClientTurnManager(CSimulation2& simulation, CNetClient& client, int clientId, IReplayLogger& replay) : CTurnManager(simulation, DEFAULT_TURN_LENGTH_MP, clientId, replay), m_NetClient(client) { @@ -116,8 +118,8 @@ void CNetClientTurnManager::OnSyncError(u32 turn, const CStr& expectedHash, cons std::string hash; ENSURE(m_Simulation2.ComputeStateHash(hash, !TurnNeedsFullHash(turn))); - OsPath path = psLogDir() / "oos_dump.txt"; - std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); + OsPath oosdumpPath(psLogDir() / (L"oos_dump" + g_UniqueLogPostfix + L".txt")); + std::ofstream file (OsString(oosdumpPath).c_str(), std::ofstream::out | std::ofstream::trunc); m_Simulation2.DumpDebugState(file); file.close(); @@ -131,7 +133,7 @@ void CNetClientTurnManager::OnSyncError(u32 turn, const CStr& expectedHash, cons playerNamesStrings.push_back(name); } - LOGERROR("Out-Of-Sync on turn %d\nPlayers: %s\nDumping state to %s", turn, playerNamesString.str().c_str(), path.string8()); + LOGERROR("Out-Of-Sync on turn %d\nPlayers: %s\nDumping state to %s", turn, playerNamesString.str().c_str(), oosdumpPath.string8()); ScriptInterface& scriptInterface = m_NetClient.GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); @@ -143,7 +145,7 @@ void CNetClientTurnManager::OnSyncError(u32 turn, const CStr& expectedHash, cons scriptInterface.SetProperty(msg, "players", playerNamesStrings); scriptInterface.SetProperty(msg, "expectedHash", expectedHashHex); scriptInterface.SetProperty(msg, "hash", Hexify(hash)); - scriptInterface.SetProperty(msg, "path_oos_dump", wstring_from_utf8(path.string8())); + scriptInterface.SetProperty(msg, "path_oos_dump", wstring_from_utf8(oosdumpPath.string8())); scriptInterface.SetProperty(msg, "path_replay", wstring_from_utf8(m_Replay.GetDirectory().string8())); m_NetClient.PushGuiMessage(msg); } diff --git a/source/ps/CLogger.cpp b/source/ps/CLogger.cpp index 55b282819c..f854c9c6d8 100644 --- a/source/ps/CLogger.cpp +++ b/source/ps/CLogger.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -34,6 +34,7 @@ #include +CStrW g_UniqueLogPostfix; static const double RENDER_TIMEOUT = 10.0; // seconds before messages are deleted static const double RENDER_TIMEOUT_RATE = 10.0; // number of timed-out messages deleted per second static const size_t RENDER_LIMIT = 20; // maximum messages on screen at once @@ -65,10 +66,11 @@ const char* html_header1 = "\n"; CLogger::CLogger() { - OsPath mainlogPath(psLogDir()/"mainlog.html"); + OsPath mainlogPath(psLogDir() / (L"mainlog" + g_UniqueLogPostfix + L".html")); m_MainLog = new std::ofstream(OsString(mainlogPath).c_str(), std::ofstream::out | std::ofstream::trunc); + debug_printf("Writing the mainlog at %s\n", mainlogPath.string8().c_str()); - OsPath interestinglogPath(psLogDir()/"interestinglog.html"); + OsPath interestinglogPath(psLogDir() / (L"interestinglog" + g_UniqueLogPostfix + L".html")); m_InterestingLog = new std::ofstream(OsString(interestinglogPath).c_str(), std::ofstream::out | std::ofstream::trunc); m_OwnsStreams = true;