From 36d120fa71bcdefa17642d930975a2a8eb118151 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Sat, 28 Jan 2017 21:41:59 +0100 Subject: [PATCH] Decouple heaptrack version from file format version. This allows us to set the version again to 1.0.0 in preparation of the first release. The file format is set to version 1 as well. We are still able to read the old data files from profile runs with current versions of heaptrack. --- CMakeLists.txt | 3 ++- src/analyze/accumulatedtracedata.cpp | 22 ++++++++++++++++------ src/track/libheaptrack.cpp | 2 +- src/util/config.h.cmake | 2 ++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a643db6..8cc25bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,10 +14,11 @@ if(NOT CMAKE_BUILD_TYPE) endif() set(HEAPTRACK_VERSION_MAJOR 1) -set(HEAPTRACK_VERSION_MINOR 2) +set(HEAPTRACK_VERSION_MINOR 0) set(HEAPTRACK_VERSION_PATCH 0) set(HEAPTRACK_LIB_VERSION 1.0.0) set(HEAPTRACK_LIB_SOVERSION 1) +set(HEAPTRACK_FILE_FORMAT_VERSION 1) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) diff --git a/src/analyze/accumulatedtracedata.cpp b/src/analyze/accumulatedtracedata.cpp index 32a269b..5a28300 100644 --- a/src/analyze/accumulatedtracedata.cpp +++ b/src/analyze/accumulatedtracedata.cpp @@ -228,7 +228,7 @@ bool AccumulatedTraceData::read(istream& in) } else if (reader.mode() == '+') { AllocationInfo info; AllocationIndex allocationIndex; - if (fileVersion >= 0x010000) { + if (fileVersion >= 1) { if (!(reader >> allocationIndex.index)) { cerr << "failed to parse line: " << reader.line() << endl; continue; @@ -271,7 +271,7 @@ bool AccumulatedTraceData::read(istream& in) } else if (reader.mode() == '-') { AllocationIndex allocationInfoIndex; bool temporary = false; - if (fileVersion >= 0x010000) { + if (fileVersion >= 1) { if (!(reader >> allocationInfoIndex.index)) { cerr << "failed to parse line: " << reader.line() << endl; continue; @@ -334,10 +334,20 @@ bool AccumulatedTraceData::read(istream& in) totalCost = {}; fromAttached = true; } else if (reader.mode() == 'v') { - reader >> fileVersion; - if (fileVersion > HEAPTRACK_VERSION) { - cerr << "The data file was written by a newer heaptrack of version " << hex << fileVersion - << " and is thus not compatible with this build of heaptrack version " << hex << HEAPTRACK_VERSION << '.' << endl; + uint heaptrackVersion = 0; + reader >> heaptrackVersion; + if (!(reader >> fileVersion) && heaptrackVersion == 0x010200) { + // backwards compatibility: before the 1.0.0, I actually + // bumped the version to 0x010200 already and used that + // as file version. This is what we now consider v1 of the + // file format + fileVersion = 1; + } + if (fileVersion > HEAPTRACK_FILE_FORMAT_VERSION) { + cerr << "The data file has version " << hex << fileVersion + << " (written by heaptrack version " << hex << heaptrackVersion << ")\n" + << "This is not compatible with this build of heaptrack (version " << hex << HEAPTRACK_VERSION << ")" + << ", which can read file format version " << hex << HEAPTRACK_FILE_FORMAT_VERSION << " and below" << endl; return false; } } else if (reader.mode() == 'I') { // system information diff --git a/src/track/libheaptrack.cpp b/src/track/libheaptrack.cpp index ba9c03a..077b303 100644 --- a/src/track/libheaptrack.cpp +++ b/src/track/libheaptrack.cpp @@ -114,7 +114,7 @@ thread_local bool RecursionGuard::isActive = false; void writeVersion(FILE* out) { - fprintf(out, "v %x\n", HEAPTRACK_VERSION); + fprintf(out, "v %x %x\n", HEAPTRACK_VERSION, HEAPTRACK_FILE_FORMAT_VERSION); } void writeExe(FILE* out) diff --git a/src/util/config.h.cmake b/src/util/config.h.cmake index bd68bb8..4d03b9f 100644 --- a/src/util/config.h.cmake +++ b/src/util/config.h.cmake @@ -32,6 +32,8 @@ #define HEAPTRACK_VERSION_PATCH @HEAPTRACK_VERSION_PATCH@ #define HEAPTRACK_VERSION ((HEAPTRACK_VERSION_MAJOR<<16)|(HEAPTRACK_VERSION_MINOR<<8)|(HEAPTRACK_VERSION_PATCH)) +#define HEAPTRACK_FILE_FORMAT_VERSION @HEAPTRACK_FILE_FORMAT_VERSION@ + #define HEAPTRACK_DEBUG_BUILD @HEAPTRACK_DEBUG_BUILD@ #endif // HEAPTRACK_CONFIG_H -- 2.7.4