Skip to content

Commit 29e2d84

Browse files
committed
ref
1 parent d87f7a0 commit 29e2d84

File tree

3 files changed

+125
-13
lines changed

3 files changed

+125
-13
lines changed

Cargo.lock

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workflows/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ log.workspace = true
3131
eyre.workspace = true
3232

3333
sysinfo = { version = "0.32.0", optional = true }
34+
prettytable = { version = "0.10.0", optional = true }
3435

3536
[features]
36-
profiling = ["sysinfo"]
37+
profiling = ["sysinfo", "prettytable"]
3738

3839
[dev-dependencies]
3940
# only used for tests

workflows/src/bin/tps.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod profile {
77
Ollama,
88
};
99
pub use ollama_workflows::Model;
10+
pub use prettytable::{Cell, Row, Table};
1011
pub use sysinfo::{CpuRefreshKind, RefreshKind, System, MINIMUM_CPU_UPDATE_INTERVAL};
1112
}
1213

@@ -76,6 +77,18 @@ async fn main() {
7677
let total_memory = system.total_memory();
7778
let used_memory = system.used_memory();
7879
let mut tps = 0 as f64;
80+
let mut table = Table::new();
81+
82+
// Add a row with the headers
83+
table.add_row(Row::new(vec![
84+
Cell::new("Model"),
85+
Cell::new("TPS"),
86+
Cell::new("OS"),
87+
Cell::new("Version"),
88+
Cell::new("CPU Usage (%)"),
89+
Cell::new("Total Memory (KB)"),
90+
Cell::new("Used Memory (KB)"),
91+
]));
7992

8093
for (_, model) in cfg.models {
8194
debug!("Pulling model: {}", model);
@@ -107,28 +120,29 @@ async fn main() {
107120
match ollama.generate(generation_request).await {
108121
Ok(response) => {
109122
debug!("Got response for model {}", model);
123+
110124
// compute TPS
111125
tps = (response.eval_count.unwrap_or_default() as f64)
112126
/ (response.eval_duration.unwrap_or(1) as f64)
113127
* 1_000_000_000f64;
114-
// report machine info
128+
129+
// add row to table
130+
table.add_row(Row::new(vec![
131+
Cell::new(&model.to_string()),
132+
Cell::new(&tps.to_string()),
133+
Cell::new(&format!("{} {}", brand, os_name)),
134+
Cell::new(&os_version),
135+
Cell::new(&cpu_usage.to_string()),
136+
Cell::new(&total_memory.to_string()),
137+
Cell::new(&used_memory.to_string()),
138+
]));
115139
}
116140
Err(e) => {
117141
warn!("Ignoring model {}: Workflow failed with error {}", model, e);
118142
}
119143
}
144+
table.printstd();
120145
// print system info
121-
println!(
122-
"\n Model: {} \n TPS: {} \n OS: {} {} \n Version: {} \n CPU Usage: % {} \n Total Memory: {} KB \n Used Memory: {} KB ",
123-
model,
124-
tps,
125-
brand,
126-
os_name,
127-
os_version,
128-
cpu_usage,
129-
total_memory,
130-
used_memory,
131-
);
132146
// refresh CPU usage (https://docs.rs/sysinfo/latest/sysinfo/struct.Cpu.html#method.cpu_usage)
133147
system = System::new_with_specifics(
134148
RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
@@ -138,6 +152,8 @@ async fn main() {
138152
// refresh CPUs again to get actual value
139153
system.refresh_cpu_usage();
140154
}
155+
// print system info
156+
table.printstd();
141157
debug!("Finished");
142158
}
143159
}

0 commit comments

Comments
 (0)