//! Raw counters: the sccache stats exactly as the server read them. use eframe::egui::{self, RichText, Ui}; use sccache_dash_api::View; use crate::style; pub fn section(ui: &mut Ui, view: &View) { style::section(ui, "raw", "Raw counters", |ui| match &view.raw { serde_json::Value::Null => { ui.label("sccache's raw counters could not be read."); } value => tree(ui, value, "raw"), }); } /// A tree: one collapsible line per group, `name value` per counter. fn tree(ui: &mut Ui, value: &serde_json::Value, path: &str) { match value { serde_json::Value::Object(fields) => { for (name, value) in fields { branch(ui, name, value, path); } } serde_json::Value::Array(items) => { for (index, value) in items.iter().enumerate() { branch(ui, &index.to_string(), value, path); } } leaf => counter(ui, "", leaf), } } fn branch(ui: &mut Ui, name: &str, value: &serde_json::Value, path: &str) { let path = format!("{path}/{name}"); if value.is_object() || value.is_array() { egui::CollapsingHeader::new(RichText::new(name).strong()) .id_salt(path.clone()) .default_open(true) .show(ui, |ui| tree(ui, value, &path)); } else { counter(ui, name, value); } } /// One counter as sccache prints its value. fn counter(ui: &mut Ui, name: &str, value: &serde_json::Value) { let text = match value { serde_json::Value::String(text) => text.clone(), serde_json::Value::Null => "null".to_owned(), number => number.to_string(), }; ui.horizontal_wrapped(|ui| { if !name.is_empty() { ui.label(name); } ui.label(RichText::new(text).weak()); }); }