Skip to content

Commit de9b4b2

Browse files
synleclaude
andcommitted
feat: add benchmark telemetry for all data-loading commands
Log timing for each Tauri command in debug log: - get_monitors: sidecar call time + total (or cache hit) - get_dark_mode: sidecar call time (or cache hit) - get_volume: sidecar call time (or cache hit) - get_preferences: in-memory lock time - get_accessibility_trusted: system call time (or cache hit) All logged as "benchmark: <command> — <ms>" when debug logging is on. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c0be77f commit de9b4b2

6 files changed

Lines changed: 77 additions & 11 deletions

File tree

src-tauri/src/config.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,19 @@ pub fn reset_to_defaults() {
612612
/// Use `log::info!` instead.
613613
#[tauri::command]
614614
pub fn get_preferences(state: tauri::State<'_, crate::AppState>) -> Result<Preferences, String> {
615+
let t0 = std::time::Instant::now();
615616
let prefs = state.preferences.lock().map_err(|e| e.to_string())?;
616-
log::info!(
617-
"get_preferences: show_contrast={} min_brightness={} monitors={} profiles={}",
618-
prefs.show_contrast, prefs.min_brightness, prefs.monitor_configs.len(), prefs.profiles.len()
617+
let result = prefs.clone();
618+
write_debug_log(
619+
&state,
620+
&format!(
621+
"benchmark: get_preferences — {:.1}ms (in-memory, {} monitors, {} profiles)",
622+
t0.elapsed().as_secs_f64() * 1000.0,
623+
result.monitor_configs.len(),
624+
result.profiles.len(),
625+
),
619626
);
620-
Ok(prefs.clone())
627+
Ok(result)
621628
}
622629

623630
/// Saves updated preferences from the frontend, syncs autostart with the OS, and persists to disk.

src-tauri/src/dark_mode.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,31 @@ fn base_url() -> String {
1818
pub async fn get_dark_mode(
1919
state: tauri::State<'_, crate::AppState>,
2020
) -> Result<bool, String> {
21+
let t0 = std::time::Instant::now();
22+
2123
if let Some(cached) = state.sidecar_cache.get_dark_mode() {
24+
crate::config::write_debug_log(
25+
&state,
26+
&format!("benchmark: get_dark_mode — {:.1}ms (cache hit)", t0.elapsed().as_secs_f64() * 1000.0),
27+
);
2228
return Ok(cached);
2329
}
2430

2531
let url = format!("{}/theme", base_url());
26-
log::info!("get_dark_mode: GET {}", url);
2732
let resp: ThemeResponse = reqwest::get(&url).await
2833
.map_err(|e| format!("Failed to get theme: {}", e))?
2934
.json().await
3035
.map_err(|e| format!("Failed to parse theme response: {}", e))?;
3136
let is_dark = resp.theme == "dark";
32-
log::info!("get_dark_mode: theme={} is_dark={}", resp.theme, is_dark);
3337
state.sidecar_cache.set_dark_mode(is_dark);
38+
39+
crate::config::write_debug_log(
40+
&state,
41+
&format!(
42+
"benchmark: get_dark_mode — {:.1}ms (sidecar, is_dark={})",
43+
t0.elapsed().as_secs_f64() * 1000.0, is_dark,
44+
),
45+
);
3446
Ok(is_dark)
3547
}
3648

src-tauri/src/display.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,20 @@ fn ensure_metadata_for_monitors(
202202
pub async fn get_monitors(
203203
state: tauri::State<'_, crate::AppState>,
204204
) -> Result<Vec<Monitor>, String> {
205+
let t0 = std::time::Instant::now();
206+
205207
// Return cached monitors if fresh
206208
if let Some(cached) = state.sidecar_cache.get_monitors() {
209+
crate::config::write_debug_log(
210+
&state,
211+
&format!("benchmark: get_monitors — {:.1}ms (cache hit)", t0.elapsed().as_secs_f64() * 1000.0),
212+
);
207213
return Ok(cached);
208214
}
209215

210216
let monitors = detect_monitors().await;
217+
let t_sidecar = t0.elapsed();
218+
211219
let mut prefs = state.preferences.lock().map_err(|e| e.to_string())?;
212220

213221
let mut dirty = reconcile_migrated_configs(&monitors, &mut prefs.monitor_configs);
@@ -218,6 +226,16 @@ pub async fn get_monitors(
218226

219227
let result = merge_with_configs(monitors, &prefs.monitor_configs);
220228
state.sidecar_cache.set_monitors(result.clone());
229+
230+
crate::config::write_debug_log(
231+
&state,
232+
&format!(
233+
"benchmark: get_monitors — {:.1}ms total (sidecar={:.1}ms, {} monitors)",
234+
t0.elapsed().as_secs_f64() * 1000.0,
235+
t_sidecar.as_secs_f64() * 1000.0,
236+
result.len(),
237+
),
238+
);
221239
Ok(result)
222240
}
223241

src-tauri/src/tiling/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,16 @@ pub fn get_tiling_supported() -> bool {
10101010
pub fn get_accessibility_trusted(
10111011
state: tauri::State<'_, crate::AppState>,
10121012
) -> bool {
1013+
let t0 = std::time::Instant::now();
1014+
10131015
if let Some(cached) = state.sidecar_cache.get_accessibility() {
1016+
crate::config::write_debug_log(
1017+
&state,
1018+
&format!(
1019+
"benchmark: get_accessibility_trusted — {:.1}ms (cache hit, trusted={})",
1020+
t0.elapsed().as_secs_f64() * 1000.0, cached,
1021+
),
1022+
);
10141023
return cached;
10151024
}
10161025
let result;
@@ -1020,17 +1029,25 @@ pub fn get_accessibility_trusted(
10201029
}
10211030
#[cfg(target_os = "windows")]
10221031
{
1023-
result = true; // Win32 window management needs no special permissions
1032+
result = true;
10241033
}
10251034
#[cfg(target_os = "linux")]
10261035
{
1027-
result = true; // X11 allows any client to manipulate windows
1036+
result = true;
10281037
}
10291038
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
10301039
{
10311040
result = false;
10321041
}
10331042
state.sidecar_cache.set_accessibility(result);
1043+
1044+
crate::config::write_debug_log(
1045+
&state,
1046+
&format!(
1047+
"benchmark: get_accessibility_trusted — {:.1}ms (system call, trusted={})",
1048+
t0.elapsed().as_secs_f64() * 1000.0, result,
1049+
),
1050+
);
10341051
result
10351052
}
10361053

src-tauri/src/volume.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,30 @@ fn base_url() -> String {
1818
pub async fn get_volume(
1919
state: tauri::State<'_, crate::AppState>,
2020
) -> Result<u32, String> {
21+
let t0 = std::time::Instant::now();
22+
2123
if let Some(cached) = state.sidecar_cache.get_volume() {
24+
crate::config::write_debug_log(
25+
&state,
26+
&format!("benchmark: get_volume — {:.1}ms (cache hit)", t0.elapsed().as_secs_f64() * 1000.0),
27+
);
2228
return Ok(cached);
2329
}
2430

2531
let url = format!("{}/get_volume", base_url());
26-
log::info!("get_volume: GET {}", url);
2732
let resp: VolumeResponse = reqwest::get(&url).await
2833
.map_err(|e| format!("Failed to get volume: {}", e))?
2934
.json().await
3035
.map_err(|e| format!("Failed to parse volume response: {}", e))?;
31-
log::info!("get_volume: volume={}", resp.volume);
3236
state.sidecar_cache.set_volume(resp.volume);
37+
38+
crate::config::write_debug_log(
39+
&state,
40+
&format!(
41+
"benchmark: get_volume — {:.1}ms (sidecar, volume={})",
42+
t0.elapsed().as_secs_f64() * 1000.0, resp.volume,
43+
),
44+
);
3345
Ok(resp.volume)
3446
}
3547

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/nicoverbruggen/tauri-v2-docs/refs/heads/main/schemas/config.schema.json",
33
"productName": "Display DJ",
4-
"version": "6.3.16",
4+
"version": "6.3.17",
55
"identifier": "com.synle.display-dj",
66
"build": {
77
"beforeDevCommand": "npm run dev",

0 commit comments

Comments
 (0)