]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add and use Counters::increment(const Counters&)
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 11 Sep 2020 07:43:00 +0000 (09:43 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 14 Sep 2020 17:40:06 +0000 (19:40 +0200)
src/Counters.cpp
src/Counters.hpp
src/stats.cpp

index 1ec52e2e050516d51d2e555da5a0e38e8f6dac20..56603a164e6ffa2a22bee100af0667ab542711b5 100644 (file)
@@ -70,6 +70,17 @@ Counters::increment(Statistic statistic, int64_t value)
     std::max(static_cast<int64_t>(0), static_cast<int64_t>(counter + value));
 }
 
+void
+Counters::increment(const Counters& other)
+{
+  m_counters.resize(std::max(size(), other.size()));
+  for (size_t i = 0; i < other.size(); ++i) {
+    auto& counter = m_counters[i];
+    counter = std::max(static_cast<int64_t>(0),
+                       static_cast<int64_t>(counter + other.m_counters[i]));
+  }
+}
+
 size_t
 Counters::size() const
 {
index 44dc0b7265adbfe4e7de0689a48855b46ad8d7fc..d19227b5bffefc63c775a52355dcd81de8a7b996 100644 (file)
@@ -38,6 +38,7 @@ public:
   void set_raw(size_t index, uint64_t value);
 
   void increment(Statistic statistic, int64_t value = 1);
+  void increment(const Counters& other);
 
   size_t size() const;
 
index 133da430f4b7cf62a3625755468a90d796f32aea..5e39f10bb89c71b130f07e7f9841b30e4daa25cc 100644 (file)
@@ -275,10 +275,7 @@ stats_flush_to_file(const Config& config,
     }
 
     stats_read(sfile, counters);
-    for (size_t i = 0; i < static_cast<size_t>(Statistic::END); ++i) {
-      counters.increment(static_cast<Statistic>(i),
-                         updates.get(static_cast<Statistic>(i)));
-    }
+    counters.increment(updates);
     stats_write(sfile, counters);
   }