Skip to content

Commit

Permalink
Add task_clock as additional counter used with perf counters
Browse files Browse the repository at this point in the history
Currently all of sightglass's measuring units are tied processor events
which is only useful in comparing performance where the cpu remains
constant. This patch adds cpu time software counter as calculated by
the kernel.
  • Loading branch information
jlb6740 committed Dec 16, 2022
1 parent 49f6739 commit 5e26257
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion crates/recorder/src/measure/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! kernel.perf_event_paranoid=0`.
use super::Measure;
use crate::measure::Measurements;
use perf_event::{events::Hardware, Builder, Counter, Group};
use perf_event::{events::{Hardware, Software}, Builder, Counter, Group};
use serde::{Deserialize, Serialize};
use sightglass_data::Phase;

Expand All @@ -15,6 +15,7 @@ pub struct CounterMeasure {
instructions_retired: Counter,
cache_accesses: Counter,
cache_misses: Counter,
task_clock: Counter,
}

impl CounterMeasure {
Expand Down Expand Up @@ -60,6 +61,15 @@ impl CounterMeasure {
have such a counter? If it does, your kernel may not fully support this \
processor.",
),
task_clock: Builder::new()
.group(&mut group)
.kind(Software::TASK_CLOCK)
.build()
.expect(
"Unable to create TASK_CLOCK software counter. Does this system actually \
have such a counter? If it does, your kernel may not fully support this \
processor.",
),
event_group: group,
}
}
Expand All @@ -83,6 +93,7 @@ impl Measure for CounterMeasure {
);
measurements.add(phase, "cache-accesses".into(), counts[&self.cache_accesses]);
measurements.add(phase, "cache-misses".into(), counts[&self.cache_misses]);
measurements.add(phase, "task-clocks".into(), counts[&self.task_clock]);
}
}

Expand All @@ -102,6 +113,9 @@ pub struct PerfCounters {
/// Measured by performance counter. May be 0, in which case the counter is almost certainly
/// disabled.
pub cache_misses: u64,
/// Measured by performance counter. May be 0, in which case the counter is almost certainly
/// disabled.
pub task_clock: u64,
}

impl std::ops::Div<u64> for PerfCounters {
Expand All @@ -112,6 +126,7 @@ impl std::ops::Div<u64> for PerfCounters {
instructions_retired: self.instructions_retired / rhs,
cache_accesses: self.cache_accesses / rhs,
cache_misses: self.cache_misses / rhs,
task_clock: self.task_clock / rhs,
}
}
}
Expand All @@ -124,6 +139,7 @@ impl std::ops::Add<PerfCounters> for PerfCounters {
instructions_retired: self.instructions_retired + rhs.instructions_retired,
cache_accesses: self.cache_accesses + rhs.cache_accesses,
cache_misses: self.cache_misses + rhs.cache_misses,
task_clock: self.task_clock + rhs.task_clock,
}
}
}
Expand Down

0 comments on commit 5e26257

Please sign in to comment.