Skip to content

Commit

Permalink
Remove clock for std::chrono (#2408)
Browse files Browse the repository at this point in the history
`clock.hpp` has become redundant over `std::chrono` and was replaced
with `monotonic_clock`.
  • Loading branch information
thorstenhater authored Sep 18, 2024
1 parent 047550d commit 617434a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 78 deletions.
1 change: 0 additions & 1 deletion arbor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ set(arbor_sources
network_impl.cpp
simulation.cpp
partition_load_balance.cpp
profile/clock.cpp
profile/memory_meter.cpp
profile/meter_manager.cpp
profile/power_meter.cpp
Expand Down
26 changes: 0 additions & 26 deletions arbor/include/arbor/profile/clock.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion arbor/include/arbor/profile/meter_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ARB_ARBOR_API meter_manager {
private:
bool started_ = false;

tick_type start_time_ = 0;
tick_type start_time_ = {};
std::vector<double> times_;

std::vector<std::unique_ptr<meter>> meters_;
Expand Down
3 changes: 0 additions & 3 deletions arbor/include/arbor/profile/profiler.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#pragma once

#include <cstdint>
#include <ostream>
#include <unordered_map>
#include <vector>

#include <arbor/export.hpp>
#include <arbor/context.hpp>
#include <arbor/profile/timer.hpp>

namespace arb {

Expand Down
19 changes: 10 additions & 9 deletions arbor/include/arbor/profile/timer.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#pragma once

#include <arbor/profile/clock.hpp>
#include <chrono>

// NOTE This is only in the public API as meter_manager is and has a private
// member of tick_type.

namespace arb {
namespace profile {

template <typename Clock = default_clock>
struct timer {
static inline tick_type tic() {
return Clock::now();
}
using clock_type = std::chrono::steady_clock;
using tick_type = clock_type::time_point;

static inline double toc(tick_type t) {
return (Clock::now()-t)*Clock::seconds_per_tick();
}
struct timer {
constexpr static double scale = 1e-9; // ns -> s
static inline tick_type tic() { return clock_type::now(); }
static inline double toc(tick_type t) { return scale*std::chrono::duration_cast<std::chrono::nanoseconds>(clock_type::now() - t).count(); }
};

} // namespace profile
Expand Down
31 changes: 0 additions & 31 deletions arbor/profile/clock.cpp

This file was deleted.

7 changes: 3 additions & 4 deletions arbor/profile/meter_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace arb {
namespace profile {

using timer_type = timer<>;
using util::strprintf;

template <typename C>
Expand Down Expand Up @@ -69,14 +68,14 @@ void meter_manager::start(context ctx) {
arb::threading::task_group(ctx->thread_pool.get()).wait();
ctx->distributed->barrier();

start_time_ = timer_type::tic();
start_time_ = timer::tic();
};

void meter_manager::checkpoint(std::string name, context ctx) {
arb_assert(started_);

// Record the time taken on this domain since the last checkpoint
times_.push_back(timer<>::toc(start_time_));
times_.push_back(timer::toc(start_time_));

// Update meters
checkpoint_names_.push_back(std::move(name));
Expand All @@ -88,7 +87,7 @@ void meter_manager::checkpoint(std::string name, context ctx) {
ctx->gpu->synchronize();
arb::threading::task_group(ctx->thread_pool.get()).wait();
ctx->distributed->barrier();
start_time_ = timer<>::tic();
start_time_ = timer::tic();
}

const std::vector<std::unique_ptr<meter>>& meter_manager::meters() const {
Expand Down
7 changes: 4 additions & 3 deletions arbor/profile/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

#include <arbor/context.hpp>
#include <arbor/profile/profiler.hpp>
#include <arbor/profile/timer.hpp>

#include "execution_context.hpp"
#include "threading/threading.hpp"
#include "util/span.hpp"
#include "util/rangeutil.hpp"


namespace arb {
namespace profile {

using timer_type = timer<>;
using util::make_span;

#ifdef ARB_HAVE_PROFILING
Expand Down Expand Up @@ -150,12 +151,12 @@ void recorder::enter(region_id_type index) {
accumulators_.resize(index+1);
}
index_ = index;
start_time_ = timer_type::tic();
start_time_ = timer::tic();
}

void recorder::leave() {
// calculate the elapsed time before any other steps, to increase accuracy.
auto delta = timer_type::toc(start_time_);
auto delta = timer::toc(start_time_);

if (index_==npos) {
throw std::runtime_error("recorder::leave without matching recorder::enter");
Expand Down

0 comments on commit 617434a

Please sign in to comment.