summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmynk <mohit.ritanil@gmail.com>2023-10-06 11:57:48 -0700
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2023-10-06 11:57:48 -0700
commitc2644234f62a98f168e4e24a476937657cdf6403 (patch)
tree002a9036cf83b5d41e19e0232c433b8521426dd2
parent3a1b4dd319a18abf7bb7bbace72ebe9ca953bcaf (diff)
Show per-cpu fields for `system` when `--detail` is set (#8208)
Summary: For `--detail` and `--everything`, `below dump system...` shows aggregated view over all the CPUs. The change is to show per-CPU details when queried with `--detail` or `--everything` flag. Before: ```openmetrics # TYPE system_cpu_softirq_pct gauge system_cpu_softirq_pct{cpu="-1",hostname="ip-172-31-24-129"} 0 1696365681 # TYPE system_cpu_softirq_pct gauge system_cpu_softirq_pct{cpu="-1",hostname="ip-172-31-24-129"} 0 1696365685 ``` After: ```openmetrics # TYPE system_cpus_0_softirq_pct gauge system_cpus_0_softirq_pct{cpu="0",hostname="ip-172-31-24-129"} 0 1696365580 # TYPE system_cpus_1_softirq_pct gauge system_cpus_1_softirq_pct{cpu="1",hostname="ip-172-31-24-129"} 0.199203187250996 1696365580 # TYPE system_cpus_0_softirq_pct gauge system_cpus_0_softirq_pct{cpu="0",hostname="ip-172-31-24-129"} 0 1696365585 # TYPE system_cpus_1_softirq_pct gauge system_cpus_1_softirq_pct{cpu="1",hostname="ip-172-31-24-129"} 0 1696365585 ``` Pull Request resolved: https://github.com/facebookincubator/below/pull/8208 Reviewed By: lnyng Differential Revision: D49920506 Pulled By: brianc118 fbshipit-source-id: c182cc29553af13ae6750a8dcf454d83924d06de
-rw-r--r--Cargo.lock1
-rw-r--r--below/dump/src/system.rs32
2 files changed, 26 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 658c3fed..14f9c39e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -194,7 +194,6 @@ dependencies = [
"anyhow",
"below-btrfs",
"cgroupfs",
- "once_cell",
"serde",
"tempdir",
"toml 0.7.6",
diff --git a/below/dump/src/system.rs b/below/dump/src/system.rs
index 930cdd30..2c0b26d9 100644
--- a/below/dump/src/system.rs
+++ b/below/dump/src/system.rs
@@ -37,12 +37,32 @@ impl Dumper for System {
round: &mut usize,
comma_flag: bool,
) -> Result<IterExecResult> {
+ let mut fields = self.fields.clone();
+
+ if self.opts.detail || self.opts.everything {
+ // If detail is set, add per-cpu fields.
+ // The fields need to be added at runtime because we cannot know the number of CPUs in the model statically.
+ for key in model.system.cpus.keys() {
+ for subquery_id in
+ &enum_iterator::all::<model::SingleCpuModelFieldId>().collect::<Vec<_>>()
+ {
+ let value = subquery_id.clone();
+ fields.push(DumpField::FieldId(model::SystemModelFieldId::Cpus(
+ model::BTreeMapFieldId {
+ key: Some(*key),
+ subquery_id: value,
+ },
+ )));
+ }
+ }
+ }
+
match self.opts.output_format {
Some(OutputFormat::Raw) | None => write!(
output,
"{}",
print::dump_raw(
- &self.fields,
+ &fields,
ctx,
&model.system,
*round,
@@ -55,7 +75,7 @@ impl Dumper for System {
output,
"{}",
print::dump_csv(
- &self.fields,
+ &fields,
ctx,
&model.system,
*round,
@@ -67,7 +87,7 @@ impl Dumper for System {
output,
"{}",
print::dump_tsv(
- &self.fields,
+ &fields,
ctx,
&model.system,
*round,
@@ -78,10 +98,10 @@ impl Dumper for System {
Some(OutputFormat::KeyVal) => write!(
output,
"{}",
- print::dump_kv(&self.fields, ctx, &model.system, self.opts.raw)
+ print::dump_kv(&fields, ctx, &model.system, self.opts.raw)
)?,
Some(OutputFormat::Json) => {
- let par = print::dump_json(&self.fields, ctx, &model.system, self.opts.raw);
+ let par = print::dump_json(&fields, ctx, &model.system, self.opts.raw);
if comma_flag {
write!(output, ",{}", par.to_string())?;
} else {
@@ -91,7 +111,7 @@ impl Dumper for System {
Some(OutputFormat::OpenMetrics) => write!(
output,
"{}",
- print::dump_openmetrics(&self.fields, ctx, &model.system)
+ print::dump_openmetrics(&fields, ctx, &model.system)
)?,
};