Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[turbo trace] add ability to filter by value and occurences #7674

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading