This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
437 lines (413 loc) · 16.1 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
use clap::{Parser, Subcommand};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use serde_with::{serde, serde_as};
use std::fs::File;
// Thank you anden3 for helping with this <3
#[derive(Deserialize, Serialize, Debug)]
struct OptionalFloat(pub String);
impl From<OptionalFloat> for Option<f64> {
fn from(val: OptionalFloat) -> Self {
println!("{:?}", val);
match val.0.trim() {
"Error" | "NA" => None,
s => Some(s.parse::<f64>().unwrap()),
}
}
}
#[derive(Deserialize, Serialize)]
struct OptionalU64(pub String);
impl From<OptionalU64> for Option<u64> {
fn from(val: OptionalU64) -> Self {
match val.0.trim() {
"Error" | "NA" => None,
s => Some(s.parse::<u64>().unwrap()),
}
}
}
#[derive(Deserialize, Serialize)]
struct OptionalBool(pub String);
impl From<OptionalBool> for Option<bool> {
fn from(val: OptionalBool) -> Self {
match val.0.trim() {
"1" => Some(true),
"0" => Some(false),
"Error" | "NA" | _ => None,
}
}
}
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
#[clap(propagate_version = true)]
struct Args {
/// Path to FrameView CSV file
#[clap(short = 'i', long = "in", value_name = "PATH", value_hint = clap::ValueHint::DirPath)]
in_file: std::path::PathBuf,
#[clap(subcommand)]
command: Commands,
}
// TODO: Average frame time
// TODO: Average temp(s)
// TODO: Overview command (A nice print out of the averages and stats)
#[derive(Subcommand, Debug)]
enum Commands {
/// Outputs the average FPS
AverageFPS,
}
#[tokio::main]
async fn main() {
let args = Args::parse();
match &args.command {
Commands::AverageFPS => average_fps(args).await,
}
}
async fn average_fps(args: Args) {
let mut entry_vec: Vec<FrameViewCSVEntry> = Vec::new();
let file = File::open(&args.in_file.as_path()).expect("Unable to open file");
let mut reader = csv::Reader::from_reader(file);
for line in reader.deserialize() {
let record: FrameViewCSVEntry = match line {
Ok(l) => l,
Err(e) => panic!("{}", e),
};
// println!("{:?}", record);
entry_vec.push(record);
}
let mut vec_of_frame_times = Vec::new();
for entry in entry_vec {
match entry.ms_between_presents {
None => {}
Some(x) => {
vec_of_frame_times.push(x);
}
}
}
let vec_of_fps: Vec<f64> = vec_of_frame_times.par_iter().map(|x| 1000f64 / x).collect();
let average: f64 = vec_of_fps.par_iter().sum::<f64>() / vec_of_fps.len() as f64;
println!("{:?}", average)
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde_as]
#[serde(rename_all = "camelCase")]
struct FrameViewCSVEntry {
#[serde(rename = "Application")]
pub application: String,
#[serde(rename = "GPU")]
pub gpu: String,
#[serde(rename = "CPU")]
pub cpu: String,
#[serde(rename = "Resolution")]
pub resolution: String,
#[serde(rename = "Runtime")]
pub runtime: String,
#[serde_as(as = "FromInto<OptionalU64>")] // TODO: Fix OptionalBool
#[serde(rename = "AllowsTearing")]
pub allows_tearing: Option<u64>,
#[serde_as(as = "FromInto<OptionalU64>")]
#[serde(rename = "ProcessID")]
pub process_id: Option<u64>,
#[serde(rename = "SwapChainAddress")]
pub swap_chain_address: String,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "SyncInterval")]
pub sync_interval: Option<f64>,
#[serde_as(as = "FromInto<OptionalU64>")]
#[serde(rename = "PresentFlags")]
pub present_flags: Option<u64>,
#[serde(rename = "PresentMode")]
pub present_mode: String,
#[serde_as(as = "FromInto<OptionalU64>")] // TODO: Fix OptionalBool
#[serde(rename = "Dropped")]
pub dropped: Option<u64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "TimeInSeconds")]
pub time_in_seconds: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "MsBetweenPresents")]
pub ms_between_presents: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "MsBetweenDisplayChange")]
pub ms_between_display_change: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "MsInPresentAPI")]
pub ms_in_present_api: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "MsRenderPresentLatency")]
pub ms_render_present_latency: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "MsUntilDisplayed")]
pub ms_until_displayed: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "Render Queue Depth")]
pub render_queue_depth: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "GPU0Clk(MHz)")]
pub gpu0clk_mhz: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "GPU0MemClk(MHz)")]
pub gpu0mem_clk_mhz: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "GPU0Util(%)")]
pub gpu0util: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "GPU0Temp(C)")]
pub gpu0temp_c: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "GPU1Clk(MHz)")]
pub gpu1clk_mhz: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "GPU1MemClk(MHz)")]
pub gpu1mem_clk_mhz: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "GPU1Util(%)")]
pub gpu1util: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "GPU1Temp(C)")]
pub gpu1temp_c: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "PCAT Power Total(W)")]
pub pcat_power_total_w: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "Perf/W Total(F/J) (PCAT)")]
pub perf_w_total_f_j_pcat: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "Perf/W Total(F/J) (API)")]
pub perf_w_total_f_j_apit: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "Perf/W GPUOnly(F/J) (API)")]
pub perf_w_gpu_only_f_j_api: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "Perf/W Total-USBC(F/J) (API)")]
pub perf_w_total_usbc_f_j_api: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "GPUOnlyPwr(W) (API)")]
pub gpuonly_pwr_w_api: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "NV-Total-USBCPwr(W) (API)")]
pub nv_total_usbcpwr_w_api: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "NV Pwr(W) (API)")]
pub nv_pwr_w_api: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "AMDPwr(W) (API)")]
pub amdpwr_w_api: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUClk(MHz)")]
pub cpuclk_mhz: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUUtil(%)")]
pub cpuutil: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPU Package Temp(C)")]
pub cpu_package_temp_c: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPU Package Power(W)")]
pub cpu_package_power_w: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPU TDP (W)")]
pub cpu_tdp_w: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 0]")]
pub cpucore_util_0: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 1]")]
pub cpucore_util_1: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 2]")]
pub cpucore_util_2: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 3]")]
pub cpucore_util_3: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 4]")]
pub cpucore_util_4: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 5]")]
pub cpucore_util_5: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 6]")]
pub cpucore_util_6: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 7]")]
pub cpucore_util_7: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 8]")]
pub cpucore_util_8: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[ 9]")]
pub cpucore_util_9: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[10]")]
pub cpucore_util_10: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[11]")]
pub cpucore_util_11: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[12]")]
pub cpucore_util_12: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[13]")]
pub cpucore_util_13: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[14]")]
pub cpucore_util_14: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[15]")]
pub cpucore_util_15: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[16]")]
pub cpucore_util_16: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[17]")]
pub cpucore_util_17: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[18]")]
pub cpucore_util_18: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[19]")]
pub cpucore_util_19: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[20]")]
pub cpucore_util_20: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[21]")]
pub cpucore_util_21: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[22]")]
pub cpucore_util_22: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[23]")]
pub cpucore_util_23: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[24]")]
pub cpucore_util_24: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[25]")]
pub cpucore_util_25: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[26]")]
pub cpucore_util_26: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[27]")]
pub cpucore_util_27: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[28]")]
pub cpucore_util_28: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[29]")]
pub cpucore_util_29: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[30]")]
pub cpucore_util_30: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[31]")]
pub cpucore_util_31: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[32]")]
pub cpucore_util_32: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[33]")]
pub cpucore_util_33: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[34]")]
pub cpucore_util_34: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[35]")]
pub cpucore_util_35: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[36]")]
pub cpucore_util_36: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[37]")]
pub cpucore_util_37: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[38]")]
pub cpucore_util_38: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[39]")]
pub cpucore_util_39: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[40]")]
pub cpucore_util_40: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[41]")]
pub cpucore_util_41: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[42]")]
pub cpucore_util_42: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[43]")]
pub cpucore_util_43: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[44]")]
pub cpucore_util_44: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[45]")]
pub cpucore_util_45: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[46]")]
pub cpucore_util_46: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[47]")]
pub cpucore_util_47: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[48]")]
pub cpucore_util_48: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[49]")]
pub cpucore_util_49: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[50]")]
pub cpucore_util_50: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[51]")]
pub cpucore_util_51: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[52]")]
pub cpucore_util_52: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[53]")]
pub cpucore_util_53: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[54]")]
pub cpucore_util_54: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[55]")]
pub cpucore_util_55: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[56]")]
pub cpucore_util_56: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[57]")]
pub cpucore_util_57: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[58]")]
pub cpucore_util_58: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[59]")]
pub cpucore_util_59: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[60]")]
pub cpucore_util_60: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[61]")]
pub cpucore_util_61: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[62]")]
pub cpucore_util_62: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "CPUCoreUtil%[63]")]
pub cpucore_util_63: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "Current Battery Capacity(Wh)")]
pub current_battery_capacity_wh: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "Total Battery Capacity(Wh)")]
pub total_battery_capacity_wh: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "Battery Percentage")]
pub battery_percentage: Option<f64>,
#[serde_as(as = "FromInto<OptionalFloat>")]
#[serde(rename = "Battery Drain Rate(W)")]
pub battery_drain_rate_w: Option<f64>,
}