diff options
author | Alex Morcos <morcos@chaincode.com> | 2017-01-24 12:46:01 -0500 |
---|---|---|
committer | Alex Morcos <morcos@chaincode.com> | 2017-01-24 20:28:00 -0500 |
commit | 29fb311858f098e79ed5334a128f2b0c8c88b235 (patch) | |
tree | 36c7743b6c30b57f74fcf39b5ad08ab1c6d39327 | |
parent | 1ac878ace623d43993894b6de02fc83ef1df7093 (diff) |
Increase minimum debug.log size to 10MB after shrink.
-rw-r--r-- | src/init.cpp | 5 | ||||
-rw-r--r-- | src/util.cpp | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/init.cpp b/src/init.cpp index 5be011f944..c3ceb22953 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1149,8 +1149,11 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) #ifndef WIN32 CreatePidFile(GetPidFile(), getpid()); #endif - if (GetBoolArg("-shrinkdebugfile", !fDebug)) + if (GetBoolArg("-shrinkdebugfile", !fDebug)) { + // Do this first since it both loads a bunch of debug.log into memory, + // and because this needs to happen before any other debug.log printing ShrinkDebugFile(); + } if (fPrintToDebugLog) OpenDebugLog(); diff --git a/src/util.cpp b/src/util.cpp index 08ee6b8b87..ba157625d8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -723,13 +723,17 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) { void ShrinkDebugFile() { + // Amount of debug.log to save at end when shrinking (must fit in memory) + constexpr size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000; // Scroll debug.log if it's getting too big boost::filesystem::path pathLog = GetDataDir() / "debug.log"; FILE* file = fopen(pathLog.string().c_str(), "r"); - if (file && boost::filesystem::file_size(pathLog) > 10 * 1000000) + // If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE + // trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes + if (file && boost::filesystem::file_size(pathLog) > 11 * (RECENT_DEBUG_HISTORY_SIZE / 10)) { // Restart the file with some of the end - std::vector <char> vch(200000,0); + std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0); fseek(file, -((long)vch.size()), SEEK_END); int nBytes = fread(vch.data(), 1, vch.size(), file); fclose(file); |