Skip to content

Commit

Permalink
[HACK] dump total instructions-minus-irqs:u for statistics.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Oct 23, 2020
1 parent d556f1e commit 451373a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
39 changes: 29 additions & 10 deletions measureme/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@ macro_rules! really_warn {
}

pub enum Counter {
WallTime(WallTime),
Instructions(Instructions),
Zero(InstructionsMinusIrqs),
WallTime(InstructionsMinusIrqs, WallTime),
Instructions(InstructionsMinusIrqs, Instructions),
InstructionsMinusIrqs(InstructionsMinusIrqs),
InstructionsMinusRaw0420(InstructionsMinusRaw0420),
}

impl Counter {
pub fn by_name(name: &str) -> Result<Self, Box<dyn Error + Send + Sync>> {
Ok(match name {
WallTime::NAME => Counter::WallTime(WallTime::new()),
Instructions::NAME => Counter::Instructions(Instructions::new()?),
InstructionsMinusIrqs::NAME => {
"0" => Counter::Zero(InstructionsMinusIrqs::new()?),
"t" | WallTime::NAME => {
Counter::WallTime(InstructionsMinusIrqs::new()?, WallTime::new())
}
"i" | Instructions::NAME => {
Counter::Instructions(InstructionsMinusIrqs::new()?, Instructions::new()?)
}
"I" | InstructionsMinusIrqs::NAME => {
Counter::InstructionsMinusIrqs(InstructionsMinusIrqs::new()?)
}
InstructionsMinusRaw0420::NAME => {
"r" | InstructionsMinusRaw0420::NAME => {
Counter::InstructionsMinusRaw0420(InstructionsMinusRaw0420::new()?)
}
_ => return Err(format!("{:?} is not a valid counter name", name).into()),
Expand All @@ -34,11 +40,12 @@ impl Counter {

pub(super) fn describe_as_json(&self) -> String {
let (name, units) = match self {
Counter::WallTime(_) => (
Counter::Zero(_) => ("zero", "[]"),
Counter::WallTime(..) => (
WallTime::NAME,
r#"[["ns", 1], ["μs", 1000], ["ms", 1000000], ["s", 1000000000]]"#,
),
Counter::Instructions(_) => (Instructions::NAME, r#"[["instructions", 1]]"#),
Counter::Instructions(..) => (Instructions::NAME, r#"[["instructions", 1]]"#),
Counter::InstructionsMinusIrqs(_) => {
(InstructionsMinusIrqs::NAME, r#"[["instructions", 1]]"#)
}
Expand All @@ -52,8 +59,9 @@ impl Counter {
#[inline]
pub(super) fn since_start(&self) -> u64 {
match self {
Counter::WallTime(counter) => counter.since_start(),
Counter::Instructions(counter) => counter.since_start(),
Counter::Zero(_) => 0,
Counter::WallTime(_, counter) => counter.since_start(),
Counter::Instructions(_, counter) => counter.since_start(),
Counter::InstructionsMinusIrqs(counter) => counter.since_start(),
Counter::InstructionsMinusRaw0420(counter) => counter.since_start(),
}
Expand Down Expand Up @@ -132,6 +140,17 @@ impl InstructionsMinusIrqs {
}
}

// HACK(eddyb) dump total `instructions-minus-irqs:u` for statistics.
impl Drop for InstructionsMinusIrqs {
fn drop(&mut self) {
eprintln!(
"pid={:06} instructions-minus-irqs:u={}",
std::process::id(),
self.since_start(),
);
}
}

// HACK(eddyb) this is a variant of `instructions-minus-irqs:u`, where `r0420`
// is subtracted, instead of the usual "hardware interrupts" (aka IRQs).
// `r0420` is an undocumented counter on AMD Zen CPUs which appears to count
Expand Down
5 changes: 4 additions & 1 deletion measureme/src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ impl Profiler {
pub fn new<P: AsRef<Path>>(path_stem: P) -> Result<Profiler, Box<dyn Error + Send + Sync>> {
Self::with_counter(
path_stem,
Counter::WallTime(crate::counters::WallTime::new()),
Counter::WallTime(
crate::counters::InstructionsMinusIrqs::new()?,
crate::counters::WallTime::new(),
),
)
}

Expand Down

0 comments on commit 451373a

Please sign in to comment.