From b76aa9d5cc8e1f63b7c6c57be89191e23743bd9c Mon Sep 17 00:00:00 2001 From: Johnnie Birch Date: Fri, 16 Dec 2022 11:41:20 -0800 Subject: [PATCH] Add task_clock as additional counter used with perf counters 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. --- crates/recorder/src/measure/counters.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/recorder/src/measure/counters.rs b/crates/recorder/src/measure/counters.rs index 3ce36e0b..d379c547 100644 --- a/crates/recorder/src/measure/counters.rs +++ b/crates/recorder/src/measure/counters.rs @@ -4,7 +4,10 @@ //! 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; @@ -15,6 +18,7 @@ pub struct CounterMeasure { instructions_retired: Counter, cache_accesses: Counter, cache_misses: Counter, + task_clock: Counter, } impl CounterMeasure { @@ -60,6 +64,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, } } @@ -83,6 +96,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]); } } @@ -102,6 +116,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 for PerfCounters { @@ -112,6 +129,7 @@ impl std::ops::Div 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, } } } @@ -124,6 +142,7 @@ impl std::ops::Add 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, } } }