Commit 3e497725 authored by Matthias Vallentin's avatar Matthias Vallentin

Add missing initialization and improve naming

In addition to initializing two previously default-constructed duration
values, this patch also renames measurement::time to
measurement::runtime to avoid the obvious but confusing association that
we're dealing with a time point.
parent e4e02863
...@@ -70,7 +70,7 @@ public: ...@@ -70,7 +70,7 @@ public:
static measurement take() { static measurement take() {
auto now = clock_type::now().time_since_epoch(); auto now = clock_type::now().time_since_epoch();
measurement m; measurement m;
m.time = std::chrono::duration_cast<usec>(now); m.runtime = std::chrono::duration_cast<usec>(now);
# if defined(CAF_MACOS) || defined(CAF_IOS) # if defined(CAF_MACOS) || defined(CAF_IOS)
auto tself = ::mach_thread_self(); auto tself = ::mach_thread_self();
::thread_basic_info info; ::thread_basic_info info;
...@@ -94,7 +94,7 @@ public: ...@@ -94,7 +94,7 @@ public:
} }
measurement& operator+=(const measurement& other) { measurement& operator+=(const measurement& other) {
time += other.time; runtime += other.runtime;
usr += other.usr; usr += other.usr;
sys += other.sys; sys += other.sys;
mem += other.mem; mem += other.mem;
...@@ -102,7 +102,7 @@ public: ...@@ -102,7 +102,7 @@ public:
} }
measurement& operator-=(const measurement& other) { measurement& operator-=(const measurement& other) {
time -= other.time; runtime -= other.runtime;
usr -= other.usr; usr -= other.usr;
sys -= other.sys; sys -= other.sys;
mem -= other.mem; mem -= other.mem;
...@@ -123,14 +123,14 @@ public: ...@@ -123,14 +123,14 @@ public:
friend std::ostream& operator<<(std::ostream& out, const measurement& m) { friend std::ostream& operator<<(std::ostream& out, const measurement& m) {
using std::setw; using std::setw;
out << setw(15) << m.time.count() out << setw(15) << m.runtime.count()
<< setw(15) << m.usr.count() << setw(15) << m.usr.count()
<< setw(15) << m.sys.count() << setw(15) << m.sys.count()
<< m.mem; << m.mem;
return out; return out;
} }
usec time = usec::zero(); usec runtime = usec::zero();
usec usr = usec::zero(); usec usr = usec::zero();
usec sys = usec::zero(); usec sys = usec::zero();
long mem = 0; long mem = 0;
...@@ -140,7 +140,7 @@ public: ...@@ -140,7 +140,7 @@ public:
actor_id current; actor_id current;
measurement job; measurement job;
measurement worker; measurement worker;
clock_type::duration last_flush; clock_type::duration last_flush = clock_type::duration::zero();
}; };
profiled_coordinator(const std::string& filename, profiled_coordinator(const std::string& filename,
...@@ -199,14 +199,14 @@ public: ...@@ -199,14 +199,14 @@ public:
// the system timers, this may appear to be the case sometimes. We "fix" // the system timers, this may appear to be the case sometimes. We "fix"
// this by adjusting the wallclock to the sum of user and system time, so // this by adjusting the wallclock to the sum of user and system time, so
// that utilization never exceeds 100%. // that utilization never exceeds 100%.
if (delta.time < delta.usr + delta.sys) { if (delta.runtime < delta.usr + delta.sys) {
delta.time = delta.usr + delta.sys; delta.runtime = delta.usr + delta.sys;
} }
w.worker += delta; w.worker += delta;
report(job, delta); report(job, delta);
if (m.time - w.last_flush >= resolution_) { if (m.runtime - w.last_flush >= resolution_) {
w.last_flush = m.time; w.last_flush = m.runtime;
auto wallclock = system_start_ + (m.time - clock_start_); auto wallclock = system_start_ + (m.runtime - clock_start_);
std::lock_guard<std::mutex> file_guard{file_mtx_}; std::lock_guard<std::mutex> file_guard{file_mtx_};
record(wallclock, "worker", worker, w.worker); record(wallclock, "worker", worker, w.worker);
w.worker = {}; w.worker = {};
...@@ -240,8 +240,8 @@ public: ...@@ -240,8 +240,8 @@ public:
void report(const actor_id& job, const measurement& m) { void report(const actor_id& job, const measurement& m) {
std::lock_guard<std::mutex> job_guard{job_mtx_}; std::lock_guard<std::mutex> job_guard{job_mtx_};
jobs_[job] += m; jobs_[job] += m;
if (m.time - last_flush_ >= resolution_) { if (m.runtime - last_flush_ >= resolution_) {
last_flush_ = m.time; last_flush_ = m.runtime;
auto now = clock_type::now().time_since_epoch(); auto now = clock_type::now().time_since_epoch();
auto wallclock = system_start_ + (now - clock_start_); auto wallclock = system_start_ + (now - clock_start_);
std::lock_guard<std::mutex> file_guard{file_mtx_}; std::lock_guard<std::mutex> file_guard{file_mtx_};
...@@ -260,7 +260,7 @@ public: ...@@ -260,7 +260,7 @@ public:
clock_type::duration clock_start_; clock_type::duration clock_start_;
std::vector<worker_state> worker_states_; std::vector<worker_state> worker_states_;
std::unordered_map<actor_id, measurement> jobs_; std::unordered_map<actor_id, measurement> jobs_;
clock_type::duration last_flush_; clock_type::duration last_flush_ = clock_type::duration::zero();
}; };
} // namespace scheduler } // namespace scheduler
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment