From a0f85a4fdf7ca87e39159e054a17d0fe7d50a3bd Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sun, 28 Nov 2021 13:46:38 +0000 Subject: [PATCH] Find dashboard files in the user's config path --- Cargo.lock | 89 ++++++++++++++++++++++++++++------ bare-metrics-gui/Cargo.toml | 5 +- bare-metrics-gui/src/config.rs | 13 +++++ bare-metrics-gui/src/main.rs | 32 ++++++++++-- 4 files changed, 117 insertions(+), 22 deletions(-) create mode 100644 bare-metrics-gui/src/config.rs diff --git a/Cargo.lock b/Cargo.lock index b3eb0d5..7d62c7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,6 +78,17 @@ version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62e1f47f7dc0422027a4e370dd4548d4d66b26782e513e98dca1e689e058a80e" +[[package]] +name = "appdirs" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d512b3e61196d27562dcc71446a58ba8a93d3bed2a03a87f96101b9a17f1d378" +dependencies = [ + "ole32-sys", + "shell32-sys", + "winapi 0.2.8", +] + [[package]] name = "atk-sys" version = "0.14.0" @@ -104,7 +115,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -142,6 +153,7 @@ name = "bare-metrics-gui" version = "0.1.0" dependencies = [ "anyhow", + "appdirs", "bare-metrics-core", "bare-metrics-reader", "eframe", @@ -151,6 +163,8 @@ dependencies = [ "hdrhistogram", "log", "rfd", + "ron", + "serde", ] [[package]] @@ -274,7 +288,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fdf5e01086b6be750428ba4a40619f847eb2e95756eee84b18e06e5f0b50342" dependencies = [ "lazy-bytes-cast", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -560,7 +574,7 @@ checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" dependencies = [ "libc", "redox_users", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -802,7 +816,7 @@ dependencies = [ "gobject-sys", "libc", "system-deps", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -865,7 +879,7 @@ dependencies = [ "parking_lot", "wayland-client 0.28.6", "wayland-egl", - "winapi", + "winapi 0.3.9", "winit", ] @@ -876,7 +890,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2abb6aa55523480c4adc5a56bbaa249992e2dddb2fc63dc96e04a3355364c211" dependencies = [ "gl_generator", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1051,7 +1065,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" dependencies = [ "cfg-if 1.0.0", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1061,7 +1075,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afe203d669ec979b7128619bae5a63b7b42e9203c1b29146079ee05e2f604b52" dependencies = [ "cfg-if 1.0.0", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1175,7 +1189,7 @@ dependencies = [ "log", "miow", "ntapi", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1196,7 +1210,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1304,7 +1318,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1386,6 +1400,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "ole32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d2c49021782e5233cd243168edfa8037574afed4eba4bbaf538b3d8d1789d8c" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "once_cell" version = "1.8.0" @@ -1453,7 +1477,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1597,6 +1621,17 @@ dependencies = [ "windows", ] +[[package]] +name = "ron" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b861ecaade43ac97886a512b360d01d66be9f41f3c61088b42cedf92e03d678" +dependencies = [ + "base64", + "bitflags", + "serde", +] + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -1673,6 +1708,16 @@ dependencies = [ "libc", ] +[[package]] +name = "shell32-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee04b46101f57121c9da2b151988283b6beb79b34f5bb29a58ee48cb695122c" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "smallvec" version = "1.7.0" @@ -1866,7 +1911,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", - "winapi", + "winapi 0.3.9", "winapi-util", ] @@ -2116,7 +2161,7 @@ checksum = "ecad156490d6b620308ed411cfee90d280b3cbd13e189ea0d3fada8acc89158a" dependencies = [ "web-sys", "widestring", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2125,6 +2170,12 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -2135,6 +2186,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -2147,7 +2204,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2236,7 +2293,7 @@ dependencies = [ "scopeguard", "smithay-client-toolkit 0.12.3", "wayland-client 0.28.6", - "winapi", + "winapi 0.3.9", "x11-dl", ] diff --git a/bare-metrics-gui/Cargo.toml b/bare-metrics-gui/Cargo.toml index cfb49ee..fe1f156 100644 --- a/bare-metrics-gui/Cargo.toml +++ b/bare-metrics-gui/Cargo.toml @@ -17,4 +17,7 @@ env_logger = "0.9.0" anyhow = "1.0.48" hdrhistogram = "7.4.0" # Rusty File Dialogue -rfd = "0.6.1" \ No newline at end of file +rfd = "0.6.1" +ron = "0.7.0" +serde = { version = "1.0.130", features = ["derive"] } +appdirs = "0.2.0" diff --git a/bare-metrics-gui/src/config.rs b/bare-metrics-gui/src/config.rs new file mode 100644 index 0000000..a223496 --- /dev/null +++ b/bare-metrics-gui/src/config.rs @@ -0,0 +1,13 @@ +use bare_metrics_core::structures::MetricKind; +use serde::Deserialize; + +#[derive(Deserialize, Default, Clone)] +pub struct DashboardConfig { + graphs: Vec, +} + +#[derive(Deserialize, Clone)] +pub struct GraphConfig { + name: String, + kind: MetricKind, +} diff --git a/bare-metrics-gui/src/main.rs b/bare-metrics-gui/src/main.rs index a639fe5..3095241 100644 --- a/bare-metrics-gui/src/main.rs +++ b/bare-metrics-gui/src/main.rs @@ -1,3 +1,4 @@ +use crate::config::DashboardConfig; use crate::graph::{Graph, MetricsLogReaderMessage, MetricsLogReadingRequester}; use bare_metrics_core::structures::MetricId; use bare_metrics_reader::MetricsLogReader; @@ -6,13 +7,14 @@ use eframe::epi::{App, Frame, Storage}; use eframe::NativeOptions; use env_logger::Env; use std::fs::File; -use std::path::PathBuf; -use std::str::FromStr; +pub mod config; pub mod graph; pub struct MetricsGui { requester: MetricsLogReadingRequester, + + dashboard: Option, } impl App for MetricsGui { @@ -40,7 +42,7 @@ impl App for MetricsGui { } } -fn main() { +fn main() -> anyhow::Result<()> { env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); let path = rfd::FileDialog::new() @@ -53,9 +55,29 @@ fn main() { let file = File::open(path).unwrap(); - let requester = MetricsLogReadingRequester::new_manager(MetricsLogReader::new(file).unwrap()); + let reader = MetricsLogReader::new(file).unwrap(); + let log_app_name = reader.header.application_name.clone(); + let requester = MetricsLogReadingRequester::new_manager(reader); - let app = MetricsGui { requester }; + let dashboard_dir = appdirs::user_data_dir(Some("baremetrics"), Some("rei"), true) + .unwrap() + .join("gui/dashboards"); + + let filtered_log_app_name = log_app_name.to_lowercase().replace(' ', "_"); + let dashboard_file = dashboard_dir.join(filtered_log_app_name + ".ron"); + eprintln!("Looking for dashboard file at {:?}", dashboard_file); + + let dashboard = if dashboard_file.exists() { + let rules_data: DashboardConfig = ron::de::from_reader(File::open(dashboard_file)?)?; + Some(rules_data) + } else { + None + }; + + let app = MetricsGui { + requester, + dashboard, + }; let native_options = NativeOptions::default();