Skip to content

Commit

Permalink
Disable by default unused code
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan Jowett committed Nov 11, 2024
1 parent bd55b33 commit 1552c93
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/crab_utils/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,13 @@ void CrabStats::reset() {
sw.clear();
}

void CrabStats::count(const std::string& name) { ++(*counters)[name]; }
void CrabStats::count_max(const std::string& name, const unsigned v) {
(*counters)[name] = std::max((*counters)[name], v);
}

unsigned CrabStats::uset(const std::string& n, const unsigned v) { return (*counters)[n] = v; }
unsigned CrabStats::get(const std::string& n) { return (*counters)[n]; }

void CrabStats::start(const std::string& name) { (*sw)[name].start(); }
void CrabStats::stop(const std::string& name) { (*sw)[name].stop(); }
void CrabStats::resume(const std::string& name) { (*sw)[name].resume(); }

/** Outputs all statistics to std output */
void CrabStats::Print(std::ostream& OS) {
Expand Down
25 changes: 21 additions & 4 deletions src/crab_utils/stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ inline std::ostream& operator<<(std::ostream& OS, const Stopwatch& sw) {
}

class CrabStats {
static const bool enabled = true;
static thread_local lazy_allocator<std::map<std::string, unsigned>> counters;
static thread_local lazy_allocator<std::map<std::string, Stopwatch>> sw;

Expand All @@ -44,13 +45,29 @@ class CrabStats {
/* counters */
static unsigned get(const std::string& n);
static unsigned uset(const std::string& n, unsigned v);
static void count(const std::string& name);
static void count(const std::string& name) {
if (enabled) {
++(*counters)[name];
}
}
static void count_max(const std::string& name, unsigned v);

/* stop watch */
static void start(const std::string& name);
static void stop(const std::string& name);
static void resume(const std::string& name);
static void start(const std::string& name) {
if (enabled) {
(*sw)[name].start();
}
}
static void stop(const std::string& name) {
if (enabled) {
(*sw)[name].stop();
}
}
static void resume(const std::string& name) {
if (enabled) {
(*sw)[name].resume();
}
}

/** Outputs all statistics to std output */
static void Print(std::ostream& OS);
Expand Down

0 comments on commit 1552c93

Please sign in to comment.