-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathwriter_encode_iai.rs
More file actions
105 lines (91 loc) · 3.27 KB
/
writer_encode_iai.rs
File metadata and controls
105 lines (91 loc) · 3.27 KB
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
//! IAI callgrind micro-benchmark for encoder-only throughput.
//!
//! Measures the pure encode path: RawEvent → Encoder → Vec<u8>. No
//! RotatingWriter, no syscalls — instruction count reflects encoder work
//! only. Builds anywhere; only runs on Linux (valgrind dependency).
//!
//! Usage:
//! cargo bench --bench writer_encode_iai
//!
//! Gated on `--cfg iai_enabled` so plain `cargo test --all-targets`
//! compiles to a no-op stub `fn main()` instead of spawning
//! `iai-callgrind-runner`. CI iai jobs set RUSTFLAGS to enable.
#![cfg_attr(not(iai_enabled), allow(unused))]
#[cfg(not(iai_enabled))]
fn main() {}
use dial9_tokio_telemetry::telemetry::{
PollEndEvent, PollStartEvent, TaskId, TaskSpawnEvent, WakeEventEvent, WorkerId,
WorkerParkEvent, WorkerUnparkEvent,
};
use dial9_trace_format::encoder::Encoder;
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
use std::hint::black_box;
fn workers(num_batches: usize) -> Vec<usize> {
(0..num_batches).map(|i| i % 8).collect()
}
fn encode(workers: Vec<usize>) -> Vec<u8> {
let mut enc = Encoder::new();
let loc = enc.intern_string_infallible("src/main.rs:42");
for &worker in &workers {
let wid = WorkerId::from(worker);
let task = TaskId::from_u32(1);
for cycle in 0..3u64 {
let base = cycle * 10_000;
enc.write_infallible(&WorkerUnparkEvent {
timestamp_ns: base + 100,
worker_id: wid,
local_queue: 5,
cpu_time_ns: 500_000,
sched_wait_ns: 1_000,
tid: 0,
});
for i in 0..170u64 {
enc.write_infallible(&PollStartEvent {
timestamp_ns: base + 200 + i * 10,
worker_id: wid,
local_queue: 3,
task_id: task,
spawn_loc: loc,
});
enc.write_infallible(&PollEndEvent {
timestamp_ns: base + 205 + i * 10,
worker_id: wid,
});
}
for _ in 0..3 {
enc.write_infallible(&TaskSpawnEvent {
timestamp_ns: base + 2000,
task_id: task,
spawn_loc: loc,
instrumented: true,
});
}
for _ in 0..5 {
enc.write_infallible(&WakeEventEvent {
timestamp_ns: base + 2500,
waker_task_id: task,
woken_task_id: task,
target_worker: worker as u8,
});
}
enc.write_infallible(&WorkerParkEvent {
timestamp_ns: base + 3000,
worker_id: wid,
local_queue: 0,
cpu_time_ns: 600_000,
tid: 0,
});
}
}
enc.reset_to_infallible(Vec::new())
}
#[library_benchmark]
#[bench::batches_1(workers(1))]
#[bench::batches_10(workers(10))]
#[bench::batches_100(workers(100))]
fn writer_encode(workers: Vec<usize>) -> Vec<u8> {
black_box(encode(black_box(workers)))
}
library_benchmark_group!(name = encode_group; benchmarks = writer_encode);
#[cfg(iai_enabled)]
main!(library_benchmark_groups = encode_group);