Skip to content

Commit

Permalink
Merge pull request #1268 from hodgesds/scxtop-trace-init-fixes
Browse files Browse the repository at this point in the history
scxtop: Add trace options
  • Loading branch information
hodgesds authored Jan 30, 2025
2 parents ed4e223 + f7b8406 commit f007d19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tools/scxtop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub struct App<'a> {
// trace releated
trace_manager: PerfettoTraceManager<'a>,
trace_tick: usize,
trace_tick_warmup: usize,
max_trace_ticks: usize,
prev_bpf_sample_rate: u32,
}
Expand All @@ -114,6 +115,8 @@ impl<'a> App<'a> {
keymap: KeyMap,
max_cpu_events: usize,
tick_rate_ms: usize,
trace_ticks: usize,
trace_tick_warmup: usize,
action_tx: UnboundedSender<Action>,
skel: BpfSkel<'a>,
) -> Result<Self> {
Expand Down Expand Up @@ -208,7 +211,8 @@ impl<'a> App<'a> {
non_hw_event_active: false,
prev_bpf_sample_rate: sample_rate,
trace_tick: 0,
max_trace_ticks: 5,
trace_tick_warmup: trace_tick_warmup,
max_trace_ticks: trace_ticks,
trace_manager: PerfettoTraceManager::new(&trace_file_prefix, None),
};

Expand Down Expand Up @@ -429,7 +433,7 @@ impl<'a> App<'a> {
AppState::Tracing => {
self.trace_tick += 1;
// trace for max ticks and then exit tracing mode
if self.trace_tick == self.max_trace_ticks {
if self.trace_tick > self.max_trace_ticks + self.trace_tick_warmup {
return self.record_trace();
}
}
Expand Down Expand Up @@ -1808,7 +1812,7 @@ impl<'a> App<'a> {
let gauge = Gauge::default()
.block(block)
.gauge_style(self.theme.text_important_color())
.ratio(self.trace_tick as f64 / self.max_trace_ticks as f64)
.ratio(self.trace_tick as f64 / (self.max_trace_ticks + self.trace_tick_warmup) as f64)
.label(label);
frame.render_widget(gauge, frame.area());

Expand Down Expand Up @@ -1999,7 +2003,9 @@ impl<'a> App<'a> {
..
} => {
if self.state == AppState::Tracing {
self.trace_manager.on_sched_switch(action);
if self.trace_tick > self.trace_tick_warmup {
self.trace_manager.on_sched_switch(action);
}
return;
}
if self.scheduler.is_empty() {
Expand Down
9 changes: 9 additions & 0 deletions tools/scxtop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ struct Args {
/// Trace file prefix for perfetto traces
#[arg(short, long, default_value_t = TRACE_FILE_PREFIX.to_string())]
trace_file_prefix: String,
/// Number of ticks for traces.
#[arg(long, default_value_t = 5)]
trace_ticks: usize,
/// Number of ticks to warmup before collecting traces.
#[arg(long, default_value_t = 3)]
trace_tick_warmup: usize,
}

fn get_action(_app: &App, keymap: &KeyMap, event: Event) -> Action {
Expand All @@ -75,6 +81,7 @@ async fn run() -> Result<()> {
if args.debug {
builder.obj_builder.debug(true);
}

let open_skel = builder.open(&mut open_object)?;
let skel = open_skel.load()?;

Expand Down Expand Up @@ -212,6 +219,8 @@ async fn run() -> Result<()> {
keymap.clone(),
100,
args.tick_rate_ms,
args.trace_ticks,
args.trace_tick_warmup,
action_tx.clone(),
skel,
)?;
Expand Down

0 comments on commit f007d19

Please sign in to comment.