diff --git a/Cargo.toml b/Cargo.toml index 81584a9..1ffb1cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ chrono = "0.4.31" indexmap = { version = "2.5.0", features = ["serde"] } pretty_assertions = "1.4.0" divan = "0.1" +gtk = { version = "0.9", package = "gtk4" } [profile.release] strip = "symbols" diff --git a/lact-gui/Cargo.toml b/lact-gui/Cargo.toml index d6e1ec6..35111b7 100644 --- a/lact-gui/Cargo.toml +++ b/lact-gui/Cargo.toml @@ -20,8 +20,8 @@ tracing = { workspace = true } anyhow = { workspace = true } tracing-subscriber = { workspace = true } chrono = { workspace = true } +gtk = { workspace = true, features = ["v4_6", "blueprint"] } -gtk = { version = "0.9", package = "gtk4", features = ["v4_6", "blueprint"] } adw = { package = "libadwaita", version = "0.7.1", features = [ "v1_4", ], optional = true } diff --git a/lact-gui/src/app/graphs_window/plot/imp.rs b/lact-gui/src/app/graphs_window/plot/imp.rs index 04864f7..e74fd5d 100644 --- a/lact-gui/src/app/graphs_window/plot/imp.rs +++ b/lact-gui/src/app/graphs_window/plot/imp.rs @@ -193,3 +193,58 @@ impl PlotData { self.line_series.is_empty() && self.secondary_line_series.is_empty() } } + +#[cfg(feature = "bench")] +mod benches { + use crate::app::graphs_window::plot::{ + render_thread::{process_request, RenderRequest}, + PlotData, + }; + use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; + use divan::{counter::ItemsCount, Bencher}; + use std::sync::Mutex; + + #[divan::bench] + fn render_plot(bencher: Bencher) { + let last_texture = &Mutex::new(None); + + bencher + .with_inputs(sample_plot_data) + .input_counter(|_| ItemsCount::new(1usize)) + .bench_values(|data| { + let request = RenderRequest { + title: "bench render".into(), + value_suffix: "%".into(), + secondary_value_suffix: "".into(), + y_label_area_relative_size: 1.0, + secondary_y_label_relative_area_size: 1.0, + data, + width: 1920, + height: 1080, + supersample_factor: 4, + time_period_seconds: 60, + }; + + process_request(request, last_texture) + }); + } + + fn sample_plot_data() -> PlotData { + let mut data = PlotData::default(); + + // Simulate 1 minute plot with 4 values per second + for sec in 0..60 { + for milli in [0, 250, 500, 750] { + let datetime = NaiveDateTime::new( + NaiveDate::from_ymd_opt(2025, 1, 1).unwrap(), + NaiveTime::from_hms_milli_opt(0, 0, sec, milli).unwrap(), + ); + + data.push_line_series_with_time("GPU", 100.0, datetime); + data.push_secondary_line_series_with_time("GPU Secondary", 10.0, datetime); + } + } + + data + } +} diff --git a/lact-gui/src/app/graphs_window/plot/render_thread.rs b/lact-gui/src/app/graphs_window/plot/render_thread.rs index 67dd61e..4e104c0 100644 --- a/lact-gui/src/app/graphs_window/plot/render_thread.rs +++ b/lact-gui/src/app/graphs_window/plot/render_thread.rs @@ -130,7 +130,10 @@ impl RenderThread { } } -fn process_request(render_request: RenderRequest, last_texture: &Mutex>) { +pub(super) fn process_request( + render_request: RenderRequest, + last_texture: &Mutex>, +) { // Create a new ImageSurface for Cairo rendering. let mut surface = ImageSurface::create( cairo::Format::ARgb32, @@ -393,56 +396,3 @@ impl RenderRequest { Ok(()) } } - -#[cfg(feature = "bench")] -mod benches { - use super::{process_request, RenderRequest}; - use crate::app::graphs_window::plot::PlotData; - use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; - use divan::{counter::ItemsCount, Bencher}; - use std::sync::Mutex; - - #[divan::bench] - fn render_plot(bencher: Bencher) { - let last_texture = &Mutex::new(None); - - bencher - .with_inputs(sample_plot_data) - .input_counter(|_| ItemsCount::new(1usize)) - .bench_values(|data| { - let request = RenderRequest { - title: "bench render".into(), - value_suffix: "%".into(), - secondary_value_suffix: "".into(), - y_label_area_relative_size: 1.0, - secondary_y_label_relative_area_size: 1.0, - data, - width: 1920, - height: 1080, - supersample_factor: 4, - time_period_seconds: 60, - }; - - process_request(request, last_texture) - }); - } - - fn sample_plot_data() -> PlotData { - let mut data = PlotData::default(); - - // Simulate 1 minute plot with 4 values per second - for sec in 0..60 { - for milli in [0, 250, 500, 750] { - let datetime = NaiveDateTime::new( - NaiveDate::from_ymd_opt(2025, 1, 1).unwrap(), - NaiveTime::from_hms_milli_opt(0, 0, sec, milli).unwrap(), - ); - - data.push_line_series_with_time("GPU", 100.0, datetime); - data.push_secondary_line_series_with_time("GPU Secondary", 10.0, datetime); - } - } - - data - } -}