Convert more data types to signed integers.
authorMilian Wolff <mail@milianw.de>
Tue, 14 Jun 2016 21:45:36 +0000 (23:45 +0200)
committerMilian Wolff <mail@milianw.de>
Tue, 14 Jun 2016 21:54:43 +0000 (23:54 +0200)
We now also calculate the difference between time, peakRSS and
system info when diffing heaptrack data files.

accumulatedtracedata.cpp
accumulatedtracedata.h
gui/chartmodel.h
gui/parser.cpp
gui/summarydata.h
gui/treemodel.cpp
heaptrack_print.cpp
linereader.h

index 7412425..b008d9a 100644 (file)
@@ -140,7 +140,7 @@ bool AccumulatedTraceData::read(const string& inputFile)
 bool AccumulatedTraceData::read(istream& in)
 {
     LineReader reader;
-    uint64_t timeStamp = 0;
+    int64_t timeStamp = 0;
 
     vector<string> opNewStrings = {
         // 64 bit
@@ -295,15 +295,7 @@ bool AccumulatedTraceData::read(istream& in)
 
             const auto& info = allocationInfos[allocationInfoIndex.index];
             auto& allocation = findAllocation(info.traceIndex);
-            if (!allocation.allocations || static_cast<uint64_t>(allocation.leaked) < info.size) {
-                if (!fromAttached) {
-                    cerr << "inconsistent allocation info, underflowed allocations of " << info.traceIndex << endl;
-                }
-                allocation.leaked = 0;
-                allocation.allocations = 0;
-            } else {
-                allocation.leaked -= info.size;
-            }
+            allocation.leaked -= info.size;
             totalCost.leaked -= info.size;
             if (temporary) {
                 ++allocation.temporary;
@@ -323,7 +315,7 @@ bool AccumulatedTraceData::read(istream& in)
             // comment or empty line
             continue;
         } else if (reader.mode() == 'c') {
-            uint64_t newStamp = 0;
+            int64_t newStamp = 0;
             if (!(reader >> newStamp)) {
                 cerr << "Failed to read time stamp: " << reader.line() << endl;
                 continue;
@@ -331,7 +323,7 @@ bool AccumulatedTraceData::read(istream& in)
             handleTimeStamp(timeStamp, newStamp);
             timeStamp = newStamp;
         } else if (reader.mode() == 'R') { // RSS timestamp
-            uint64_t rss = 0;
+            int64_t rss = 0;
             reader >> rss;
             if (rss > peakRSS) {
                 peakRSS = rss;
@@ -466,6 +458,10 @@ POTENTIALLY_UNUSED void printTrace(const AccumulatedTraceData& data, TraceIndex
 void AccumulatedTraceData::diff(const AccumulatedTraceData& base)
 {
     totalCost -= base.totalCost;
+    totalTime -= base.totalTime;
+    peakRSS -= base.peakRSS;
+    systemInfo.pages -= base.systemInfo.pages;
+    systemInfo.pageSize -= base.systemInfo.pageSize;
 
     // step 0: remap strings and ips
     const auto& stringMap = remapStrings(strings, base.strings);
index bd390aa..885af1d 100644 (file)
@@ -84,7 +84,7 @@ struct AccumulatedTraceData
     AccumulatedTraceData();
     virtual ~AccumulatedTraceData() = default;
 
-    virtual void handleTimeStamp(uint64_t oldStamp, uint64_t newStamp) = 0;
+    virtual void handleTimeStamp(int64_t oldStamp, int64_t newStamp) = 0;
     virtual void handleAllocation(const AllocationInfo& info, const AllocationIndex index) = 0;
     virtual void handleDebuggee(const char* command) = 0;
 
@@ -102,13 +102,13 @@ struct AccumulatedTraceData
 
     std::vector<Allocation> allocations;
     AllocationData totalCost;
-    uint64_t totalTime = 0;
-    uint64_t peakTime = 0;
-    uint64_t peakRSS = 0;
+    int64_t totalTime = 0;
+    int64_t peakTime = 0;
+    int64_t peakRSS = 0;
 
     struct SystemInfo {
-        uint64_t pages = 0;
-        uint64_t pageSize = 0;
+        int64_t pages = 0;
+        int64_t pageSize = 0;
     };
     SystemInfo systemInfo;
 
index b8ac1c3..e8a5e42 100644 (file)
@@ -33,7 +33,8 @@ struct ChartRows
     enum {
         MAX_NUM_COST = 20
     };
-    quint64 timeStamp = 0;
+    // time in ms
+    qint64 timeStamp = 0;
     std::array<qint64, MAX_NUM_COST> cost;
 };
 Q_DECLARE_TYPEINFO(ChartRows, Q_MOVABLE_TYPE);
index b009a31..ed424a1 100644 (file)
@@ -189,13 +189,13 @@ struct ParserData final : public AccumulatedTraceData
         findTopChartEntries(&ChartMergeData::temporary, &LabelIds::temporary, &temporaryChartData);
     }
 
-    void handleTimeStamp(uint64_t /*oldStamp*/, uint64_t newStamp)
+    void handleTimeStamp(int64_t /*oldStamp*/, int64_t newStamp)
     {
         if (!buildCharts) {
             return;
         }
         maxConsumedSinceLastTimeStamp = max(maxConsumedSinceLastTimeStamp, totalCost.leaked);
-        const uint64_t diffBetweenTimeStamps = totalTime / MAX_CHART_DATAPOINTS;
+        const int64_t diffBetweenTimeStamps = totalTime / MAX_CHART_DATAPOINTS;
         if (newStamp != totalTime && newStamp - lastTimeStamp < diffBetweenTimeStamps) {
             return;
         }
@@ -204,7 +204,7 @@ struct ParserData final : public AccumulatedTraceData
         lastTimeStamp = newStamp;
 
         // create the rows
-        auto createRow = [] (uint64_t timeStamp, int64_t totalCost) {
+        auto createRow = [] (int64_t timeStamp, int64_t totalCost) {
             ChartRows row;
             row.timeStamp = timeStamp;
             row.cost[0] = totalCost;
@@ -289,7 +289,7 @@ struct ParserData final : public AccumulatedTraceData
     };
     QHash<IpIndex, LabelIds> labelIds;
     int64_t maxConsumedSinceLastTimeStamp = 0;
-    uint64_t lastTimeStamp = 0;
+    int64_t lastTimeStamp = 0;
 
     StringCache stringCache;
 
index 6f861c7..1f0745b 100644 (file)
@@ -28,10 +28,10 @@ struct SummaryData
 {
     QString debuggee;
     AllocationData cost;
-    uint64_t totalTime;
-    uint64_t peakTime;
-    uint64_t peakRSS;
-    uint64_t totalSystemMemory;
+    int64_t totalTime;
+    int64_t peakTime;
+    int64_t peakRSS;
+    int64_t totalSystemMemory;
 };
 Q_DECLARE_METATYPE(SummaryData);
 
index f7e3a43..38ceee9 100644 (file)
@@ -150,28 +150,28 @@ QVariant TreeModel::data(const QModelIndex& index, int role) const
         switch (static_cast<Columns>(index.column())) {
         case AllocatedColumn:
             if (role == SortRole || role == MaxCostRole) {
-                return static_cast<quint64>(abs(row->cost.allocated));
+                return static_cast<qint64>(abs(row->cost.allocated));
             }
             return m_format.formatByteSize(row->cost.allocated);
         case AllocationsColumn:
             if (role == SortRole || role == MaxCostRole) {
-                return static_cast<quint64>(abs(row->cost.allocations));
+                return static_cast<qint64>(abs(row->cost.allocations));
             }
             return static_cast<qint64>(row->cost.allocations);
         case TemporaryColumn:
             if (role == SortRole || role == MaxCostRole) {
-                return static_cast<quint64>(abs(row->cost.temporary));
+                return static_cast<qint64>(abs(row->cost.temporary));
             }
             return static_cast<qint64>(row->cost.temporary);
         case PeakColumn:
             if (role == SortRole || role == MaxCostRole) {
-                return static_cast<quint64>(abs(row->cost.peak));
+                return static_cast<qint64>(abs(row->cost.peak));
             } else {
                 return m_format.formatByteSize(row->cost.peak);
             }
         case LeakedColumn:
             if (role == SortRole || role == MaxCostRole) {
-                return static_cast<quint64>(abs(row->cost.leaked));
+                return static_cast<qint64>(abs(row->cost.leaked));
             } else {
                 return m_format.formatByteSize(row->cost.leaked);
             }
index 01ef492..36648e8 100644 (file)
@@ -457,7 +457,7 @@ struct Printer final : public AccumulatedTraceData
         }
     }
 
-    void handleTimeStamp(uint64_t /*oldStamp*/, uint64_t newStamp) override
+    void handleTimeStamp(int64_t /*oldStamp*/, int64_t newStamp) override
     {
         if (massifOut.is_open()) {
             writeMassifSnapshot(newStamp, newStamp == totalTime);
index 13ee161..3bbd0ad 100644 (file)
@@ -93,6 +93,11 @@ public:
         return true;
     }
 
+    bool operator>>(int64_t& hex)
+    {
+        return readHex(hex);
+    }
+
     bool operator>>(uint64_t& hex)
     {
         return readHex(hex);