Skip to content

Commit

Permalink
[turbo trace] add ability to filter by value and occurences (#7674)
Browse files Browse the repository at this point in the history
### Description

This adds extra filtering options to the trace server to limit by some concrete value and occurences. There is an accompanying PR for the trace-viewer to add filtering options to the web UI


Closes TURBO-2575
  • Loading branch information
arlyon committed Jun 4, 2024
1 parent 9503a16 commit 517554e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
17 changes: 17 additions & 0 deletions crates/turbopack-trace-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ pub struct SpanViewEvent {
pub id: Option<SpanId>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Filter {
pub op: Op,
pub value: u64,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum Op {
Gt,
Lt,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ViewRect {
Expand All @@ -91,6 +104,8 @@ pub struct ViewRect {
pub query: String,
pub view_mode: String,
pub value_mode: String,
pub value_filter: Option<Filter>,
pub count_filter: Option<Filter>,
}

struct ConnectionState {
Expand Down Expand Up @@ -130,6 +145,8 @@ fn handle_connection(
query: String::new(),
view_mode: "aggregated".to_string(),
value_mode: "duration".to_string(),
count_filter: None,
value_filter: None,
},
last_update_generation: 0,
}));
Expand Down
28 changes: 27 additions & 1 deletion crates/turbopack-trace-server/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ impl Viewer {
start,
placeholder,
view_mode,
filtered,
mut filtered,
}) = queue.pop()
{
let line = get_line(&mut lines, line_index);
Expand Down Expand Up @@ -900,7 +900,33 @@ impl Viewer {
// add children to queue
enqueue_children(children, &mut queue);

// check if we should filter based on width or count
if !skipped_by_focus {
let count = match &span {
QueueItem::Span(_) => 1,
QueueItem::SpanGraph(span_graph) => span_graph.count(),
QueueItem::SpanBottomUp(bottom_up) => bottom_up.count(),
QueueItem::SpanBottomUpSpan(_) => 1,
};

if let Some(false) = view_rect.count_filter.as_ref().map(|filter| match filter
.op
{
crate::server::Op::Gt => count > filter.value as usize,
crate::server::Op::Lt => count < filter.value as usize,
}) {
filtered = Some(FilterMode::SelectedItem)
}

if let Some(false) = view_rect.value_filter.as_ref().map(|filter| match filter
.op
{
crate::server::Op::Gt => width > filter.value,
crate::server::Op::Lt => width < filter.value,
}) {
filtered = Some(FilterMode::SelectedItem)
}

// add span to line
line.push(LineEntry {
start,
Expand Down

0 comments on commit 517554e

Please sign in to comment.