Run with: cargo run -p magnotia-core --example tuning_log_demo Initialises a tracing-subscriber fmt layer so the inference_thread_count INFO event is rendered to stderr. Exercises all 8 (workload, gpu_offloaded) combos under three power scenarios: AC override, battery override, and the real sysfs probe. Used to validate the heuristic on 2026-05-09 against the spec's 6c12t truth table — all 6 rows match. Adds tracing-subscriber as a [dev-dependencies] for the example. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
51 lines
1.8 KiB
Rust
51 lines
1.8 KiB
Rust
//! Demonstrator: show what the inference_thread_count tracing event
|
|
//! emits in production, across all eight (workload, on_battery,
|
|
//! gpu_offloaded) tuples.
|
|
//!
|
|
//! Run with:
|
|
//! cargo run -p magnotia-core --example tuning_log_demo
|
|
//!
|
|
//! Output is to stderr (tracing's default). Each unique tuple emits
|
|
//! exactly one INFO line; subsequent calls with the same tuple are
|
|
//! silenced by the per-process log-once cache.
|
|
|
|
use magnotia_core::tuning::{inference_thread_count, Workload};
|
|
|
|
fn main() {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter("magnotia_core=info")
|
|
.with_target(true)
|
|
.with_writer(std::io::stderr)
|
|
.init();
|
|
|
|
let cores = num_cpus::get_physical();
|
|
let logical = num_cpus::get();
|
|
eprintln!("Host: {cores} physical / {logical} logical cores\n");
|
|
|
|
for (label, override_value) in [
|
|
("AC override", Some("ac")),
|
|
("Battery override", Some("battery")),
|
|
("No override (real sysfs probe)", None),
|
|
] {
|
|
match override_value {
|
|
Some(v) => std::env::set_var("MAGNOTIA_POWER_STATE_OVERRIDE", v),
|
|
None => std::env::remove_var("MAGNOTIA_POWER_STATE_OVERRIDE"),
|
|
}
|
|
// Cache invalidation so the live probe re-runs each section.
|
|
// Override paths bypass the cache anyway; this is for the
|
|
// no-override block that actually hits sysfs.
|
|
eprintln!("--- {label} ---");
|
|
for &(workload, gpu) in &[
|
|
(Workload::Llm, false),
|
|
(Workload::Llm, true),
|
|
(Workload::Whisper, false),
|
|
(Workload::Whisper, true),
|
|
] {
|
|
let n = inference_thread_count(workload, gpu);
|
|
let w = format!("{workload:?}");
|
|
eprintln!(" {w:>8} gpu_offloaded={gpu:>5} -> {n} threads");
|
|
}
|
|
eprintln!();
|
|
}
|
|
}
|