]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Move Statistic to core
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 21 Jul 2021 16:19:04 +0000 (18:19 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 22 Jul 2021 18:55:26 +0000 (20:55 +0200)
15 files changed:
src/Counters.cpp
src/Counters.hpp
src/Result.cpp
src/Statistics.cpp
src/argprocessing.cpp
src/argprocessing.hpp
src/ccache.cpp
src/core/Statistic.hpp [moved from src/Statistic.hpp with 97% similarity]
src/storage/primary/PrimaryStorage.cpp
src/storage/primary/PrimaryStorage.hpp
src/storage/primary/PrimaryStorage_cleanup.cpp
src/storage/primary/PrimaryStorage_compress.cpp
unittest/test_Counters.cpp
unittest/test_Statistics.cpp
unittest/test_argprocessing.cpp

index 1263d9da39b2ed719c1f157a80757674a95244f6..be80485afe59e2019b1368584b0e8bd1bc11ab9b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2010-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #include "Counters.hpp"
 
-#include "Statistic.hpp"
 #include "assertions.hpp"
 
+#include <core/Statistic.hpp>
+
 #include <algorithm>
 
-Counters::Counters() : m_counters(static_cast<size_t>(Statistic::END))
+Counters::Counters() : m_counters(static_cast<size_t>(core::Statistic::END))
 {
 }
 
 uint64_t
-Counters::get(Statistic statistic) const
+Counters::get(core::Statistic statistic) const
 {
   const auto index = static_cast<size_t>(statistic);
-  ASSERT(index < static_cast<size_t>(Statistic::END));
+  ASSERT(index < static_cast<size_t>(core::Statistic::END));
   return index < m_counters.size() ? m_counters[index] : 0;
 }
 
 void
-Counters::set(Statistic statistic, uint64_t value)
+Counters::set(core::Statistic statistic, uint64_t value)
 {
   const auto index = static_cast<size_t>(statistic);
-  ASSERT(index < static_cast<size_t>(Statistic::END));
+  ASSERT(index < static_cast<size_t>(core::Statistic::END));
   m_counters[index] = value;
 }
 
@@ -60,7 +61,7 @@ Counters::set_raw(size_t index, uint64_t value)
 }
 
 void
-Counters::increment(Statistic statistic, int64_t value)
+Counters::increment(core::Statistic statistic, int64_t value)
 {
   const auto i = static_cast<size_t>(statistic);
   if (i >= m_counters.size()) {
index cb2837fbbf051bbae330ea2be346cb4d51eca452..5afabb564feea5d017ad8e72a817a75f0ad95e36 100644 (file)
@@ -18,7 +18,7 @@
 
 #pragma once
 
-#include "Statistic.hpp"
+#include <core/Statistic.hpp>
 
 #include <cstddef>
 #include <cstdint>
@@ -31,13 +31,13 @@ class Counters
 public:
   Counters();
 
-  uint64_t get(Statistic statistic) const;
-  void set(Statistic statistic, uint64_t value);
+  uint64_t get(core::Statistic statistic) const;
+  void set(core::Statistic statistic, uint64_t value);
 
   uint64_t get_raw(size_t index) const;
   void set_raw(size_t index, uint64_t value);
 
-  void increment(Statistic statistic, int64_t value = 1);
+  void increment(core::Statistic statistic, int64_t value = 1);
   void increment(const Counters& other);
 
   size_t size() const;
index 000eb546071c94eb165fe2c65dbc4216a5a6bb1d..99bf34febcd22257b09e419da123d13a0f1d68d6 100644 (file)
 #include "File.hpp"
 #include "Logging.hpp"
 #include "Stat.hpp"
-#include "Statistic.hpp"
 #include "Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/Statistic.hpp>
 #include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <util/path.hpp>
index c454ff744bd6ca7931ee431f35fdc02c62c17ffb..b9a1676e3a4dc3077b7558186639925597421325 100644 (file)
@@ -37,6 +37,7 @@ const unsigned FLAG_ALWAYS = 2;     // always show, even if zero
 const unsigned FLAG_NEVER = 4;      // never show
 const unsigned FLAG_NOSTATSLOG = 8; // don't show for statslog
 
+using core::Statistic;
 using nonstd::nullopt;
 using nonstd::optional;
 
index a52a4f6a1849500b73ed83ca36f5b60d5bbd50d9..e5b6f9cea2f8a84de2ca4b247c04bad9c7915ba3 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <cassert>
 
+using core::Statistic;
 using nonstd::nullopt;
 using nonstd::optional;
 using nonstd::string_view;
index a8e8f3aee358839c789dc4ed3674f76d6a1b92aa..54671e8f944c0eb25641a1e25de075feed0060ea 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -19,7 +19,8 @@
 #pragma once
 
 #include "Args.hpp"
-#include "Statistic.hpp"
+
+#include <core/Statistic.hpp>
 
 #include "third_party/nonstd/optional.hpp"
 
@@ -27,14 +28,14 @@ class Context;
 
 struct ProcessArgsResult
 {
-  ProcessArgsResult(Statistic error_);
+  ProcessArgsResult(core::Statistic error_);
   ProcessArgsResult(const Args& preprocessor_args_,
                     const Args& extra_args_to_hash_,
                     const Args& compiler_args_);
 
   // nullopt on success, otherwise the statistics counter that should be
   // incremented.
-  nonstd::optional<Statistic> error;
+  nonstd::optional<core::Statistic> error;
 
   // Arguments (except -E) to send to the preprocessor.
   Args preprocessor_args;
@@ -46,7 +47,8 @@ struct ProcessArgsResult
   Args compiler_args;
 };
 
-inline ProcessArgsResult::ProcessArgsResult(Statistic error_) : error(error_)
+inline ProcessArgsResult::ProcessArgsResult(core::Statistic error_)
+  : error(error_)
 {
 }
 
index e1803916aa8566f6f05412cae386f63444943023..f13cfca7c5f2daf55c5f2e4f0fd42ca9a91db2ba 100644 (file)
@@ -90,6 +90,7 @@ extern "C" {
 #endif
 const char CCACHE_NAME[] = MYNAME;
 
+using core::Statistic;
 using nonstd::nullopt;
 using nonstd::optional;
 using nonstd::string_view;
similarity index 97%
rename from src/Statistic.hpp
rename to src/core/Statistic.hpp
index cd6cda6298467c2096250dd3f1a66e08c7a56524..2ad3cd7b0b031e4c3c3803e823dc36eeb0f3e7cc 100644 (file)
@@ -18,6 +18,8 @@
 
 #pragma once
 
+namespace core {
+
 // Statistics fields in storage order.
 enum class Statistic {
   none = 0,
@@ -56,3 +58,5 @@ enum class Statistic {
 
   END
 };
+
+} // namespace core
index dcacb333fb7e5471be8f06d5f6e4765630e28d8d..b53ae0a7f32767796daaff10b43a1733a3d64161 100644 (file)
 #include <Counters.hpp>
 #include <Logging.hpp>
 #include <MiniTrace.hpp>
-#include <Statistic.hpp>
 #include <Statistics.hpp>
 #include <Util.hpp>
 #include <assertions.hpp>
+#include <core/Statistic.hpp>
 #include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <fmtmacros.hpp>
@@ -35,6 +35,8 @@
 #  include <unistd.h>
 #endif
 
+using core::Statistic;
+
 namespace storage {
 namespace primary {
 
index 3263fdc2cea80c681f68962bb50e85b516b6886a..675adf03657fcb7f54da8f59cff87a05bd9f6eda 100644 (file)
@@ -55,7 +55,7 @@ public:
 
   // --- Statistics ---
 
-  void increment_statistic(Statistic statistic, int64_t value = 1);
+  void increment_statistic(core::Statistic statistic, int64_t value = 1);
 
   // Return a machine-readable string representing the final ccache result, or
   // nullopt if there was no result.
index f39c96bb2dcc4035a0e0fd23881cbd8093cdccea..51aeab16d35aa15780cd3532ce3ba183e1abfb0c 100644 (file)
@@ -34,6 +34,8 @@
 
 #include <algorithm>
 
+using core::Statistic;
+
 namespace storage {
 namespace primary {
 
index 40ac213e8ad4f5de04bb102af8872dc6256d2702..400d1e5a913f83761efb255618d9d77367291937 100644 (file)
@@ -210,7 +210,7 @@ recompress_file(RecompressionStatistics& statistics,
   const auto new_stat = Stat::stat(cache_file.path(), Stat::OnError::log);
 
   Statistics::update(stats_file, [=](auto& cs) {
-    cs.increment(Statistic::cache_size_kibibyte,
+    cs.increment(core::Statistic::cache_size_kibibyte,
                  Util::size_change_kibibyte(old_stat, new_stat));
   });
 
index b4d3be3239964150e94384ff4fa62ed4b46f7a99..e56710877c75327d8b5cd590e54e3c89849a110f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 #include "../src/Counters.hpp"
-#include "../src/Statistic.hpp"
 #include "TestUtil.hpp"
 
+#include <core/Statistic.hpp>
+
 #include "third_party/doctest.h"
 
+using core::Statistic;
 using TestUtil::TestContext;
 
 TEST_SUITE_BEGIN("Counters");
index 07d752759814b0e39dbc7cef8ee8e9c731637ad3..21af4b4a4c18782e2b1372fb5ea9d3b3b9f3fd35 100644 (file)
 // this program; if not, write to the Free Software Foundation, Inc., 51
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
-#include "../src/Statistic.hpp"
 #include "../src/Statistics.hpp"
 #include "../src/Util.hpp"
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"
 
+#include <core/Statistic.hpp>
+
 #include "third_party/doctest.h"
 
+using core::Statistic;
 using TestUtil::TestContext;
 
 TEST_SUITE_BEGIN("Statistics");
index 8ac228b5ec692c6b6d0f9e4f82c3c9dfc079039c..09c27b946900f1394d8eb2503d74e018f695d25f 100644 (file)
 #include "../src/Args.hpp"
 #include "../src/Config.hpp"
 #include "../src/Context.hpp"
-#include "../src/Statistic.hpp"
 #include "../src/Util.hpp"
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"
 #include "argprocessing.hpp"
 
+#include <core/Statistic.hpp>
 #include <core/wincompat.hpp>
 
 #include "third_party/doctest.h"
 
 #include <algorithm>
 
+using core::Statistic;
 using TestUtil::TestContext;
 
 namespace {