diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-02-01 11:33:51 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-02-01 11:41:00 +0100 |
commit | 77bd8c4cab67b6df6a09f856534653c7e064d6ec (patch) | |
tree | d178cf918598660ff40bc061c42f00b04008d7db /src/util.cpp | |
parent | 7bfb77045c4b06db3597c023de97411ed287e252 (diff) | |
parent | 29fb311858f098e79ed5334a128f2b0c8c88b235 (diff) | |
download | bitcoin-77bd8c4cab67b6df6a09f856534653c7e064d6ec.tar.xz |
Merge #9625: Increase minimum debug.log size to 10MB after shrink.
29fb311 Increase minimum debug.log size to 10MB after shrink. (Alex Morcos)
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
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); |