cros_tracing_analyser: Change the "list" output format to CSV

The current output of the "list" subcommand is like:
```
\#1: create: 1234 usec
\#2: mkdir: 567 usec
```

This output format is not so easy for futher processing.
Also, it doesn't contain how many times a result is sent.
So, this CL update the format to the following one:
```
name,total (us), count
create, 1234, 400
mkdir, 567, 89
```

BUG=none
TEST=cros_trace_analyser list --input trace.dat

Change-Id: Ia0e0d2d9777e8ba7431a8b90e8ec54e65d242166
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5061774
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Morg <morg@google.com>
Reviewed-by: Morg <morg@google.com>
This commit is contained in:
Keiichi Watanabe 2023-11-27 15:18:41 +09:00 committed by crosvm LUCI
parent 24bfd9a07b
commit 6b6edff308

View file

@ -416,15 +416,16 @@ fn main() -> anyhow::Result<()> {
let mut list = Vec::new();
for (name, (latency, count)) in &data {
let sum = latency * count;
list.push((name, sum));
list.push((name, sum, count));
}
list.sort_by(|a, b| b.1.cmp(&a.1));
// print top {count} events of the total value
if list.len() >= count {
list.truncate(count);
}
for i in 0..list.len() {
println!("#{}: {}: {} usec", i + 1, list[i].0, list[i].1);
println!("name, total (us), count");
for (name, sum, cnt) in list {
println!("{name}, {sum}, {cnt}");
}
return Ok(());
}