Skip to content

ui: build BreakdownTracks counters with INTERVAL FLATTEN - #7787

Open
gignat-dev wants to merge 6 commits into
mainfrom
dev/gignat/interval_flatten_uses
Open

gignat-dev wants to merge 6 commits into
mainfrom
dev/gignat/interval_flatten_uses

Conversation

@gignat-dev

@gignat-dev gignat-dev commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Replaces the interval_self_intersect! macro in BreakdownTracks (binder and memory breakdowns) with one INTERVAL FLATTEN table per hierarchy level. A node's counter is a filter on its level's table, with a 0 appended at the end of each run of segments since FLATTEN emits nothing over uncovered time.

Also turns on sortTracks for the binder breakdowns.

MAX aggregation is unavailable until FLATTEN supports it (no caller uses it).

Replace the interval_self_intersect! segments table (one row per atomic
segment and live interval, joined back on id) with one INTERVAL FLATTEN
table per hierarchy level, partitioned by that level's breakdown
columns. A node's counter is then a filter on its level's table; FLATTEN
emits nothing over uncovered time, so the per-node query appends a 0 at
the end of each run of segments to make the counter drop there.

Intervals with dur = 0 are dropped (dur > 0 instead of >= 0): the macro
counted them as 0, FLATTEN would count them over a zero-width segment.
With that filter the counter step functions are identical to before.

Measured on android_startup_real's slice table with 5 breakdown columns
(314k rows): 32.5 s / 35.5M rows for the macro vs 0.6 s / 0.94M rows for
the six FLATTEN tables. Enabled with PERFETTO PRAGMA pipelines = 1 at the
start of the table-building batch.
Children of each binder counter are now ordered by their peak concurrent
transaction count, busiest first (ties stay alphabetical), like the
memory breakdowns already do. The ordering costs one GROUP BY over the
next level's INTERVAL FLATTEN table per expand, a few ms at most.
Drop the id column from the intervals table: FLATTEN keeps only ts, dur
and the PER columns, and nothing else reads the table, so the column
(and the ROW_NUMBER window pass behind it when no sliceIdColumn is set)
was dead.

Filter ts >= 0 instead of IS NOT NULL: FLATTEN rejects a negative ts,
which would have failed the whole batch and with it every track of the
instance. Document that valueCol must be an integer column, as FLATTEN
only sums integers.
@gignat-dev
gignat-dev marked this pull request as ready for review October 6, 2026 13:57
@gignat-dev
gignat-dev requested a review from a team as a code owner October 6, 2026 13:57
@gignat-dev

Copy link
Copy Markdown
Contributor Author

@LalitMaganti, two things to confirm:

  • This is the first pipe-syntax use outside the stdlib, and MemoryViz is a default plugin, so every Android trace runs INTERVAL FLATTEN at load.
  • PERFETTO PRAGMA pipelines = 1 is run in the table-building batch; it is sticky for the connection.

@gignat-dev
gignat-dev requested a review from zezeozue October 6, 2026 14:43
@gignat-dev gignat-dev changed the title [DNS] ui: build BreakdownTracks counters with INTERVAL FLATTEN ui: build BreakdownTracks counters with INTERVAL FLATTEN Oct 6, 2026
@LalitMaganti

Copy link
Copy Markdown
Member

This is the first pipe-syntax use outside the stdlib, and MemoryViz is a default plugin, so every Android trace runs INTERVAL FLATTEN at load.

That's fine.

PERFETTO PRAGMA pipelines = 1 is run in the table-building batch; it is sticky for the connection.

Please make a UI wide global feature set when you first init trace processor.

Run PERFETTO PRAGMA pipelines = 1 in loadTrace, after notifyEof /
restoreInitialTables, instead of inside BreakdownTracks. The flag is per
connection and restoreInitialTables rebuilds the connection, so this is
the first point where it sticks for both the Wasm and the HTTP RPC
engine. Any plugin can now use pipe syntax without setting it.
@gignat-dev

Copy link
Copy Markdown
Contributor Author

Please make a UI wide global feature set when you first init trace processor.

Done. Put it inside load_trace.ts

@LalitMaganti

Copy link
Copy Markdown
Member

I feel like there's still a lot of complexity here, a lot more than I would ideally like. Why do you still need all the "level" machinery - can you not build it with one query instead of N queries now?

@gignat-dev

Copy link
Copy Markdown
Contributor Author

I feel like there's still a lot of complexity here, a lot more than I would ideally like. Why do you still need all the "level" machinery - can you not build it with one query instead of N queries now?

Each level counts overlaps for a different grouping, so a parent can't be derived from its children's segments (they start and end at different times) — N levels of counters means N FLATTENs.

I can make it one query though: UNION ALL the intervals once per level with a level column and FLATTEN that once.

Same work, one table and one statement instead of N, and level is just a filter per node;

Happy to do that if you prefer.

@LalitMaganti

Copy link
Copy Markdown
Member

Each level counts overlaps for a different grouping, so a parent can't be derived from its children's segments (they start and end at different times) — N levels of counters means N FLATTENs.

Sure but isn't this what PER is for, so you caun run N of these intersections in parallel. I might be missing something.

@gignat-dev

Copy link
Copy Markdown
Contributor Author

Sure but isn't this what PER is for, so you caun run N of these intersections in parallel. I might be missing something.

Yes, you're right. I should've used PER for that. Will do it.

Replace the per-level segments tables with a single one: the intervals
are replicated once per hierarchy level with a level column (deeper
breakdown columns NULL) and flattened once with level as the first PER
column, so every level's segments come out of one pass. A counter node
pins its level as a plain filter next to its breakdown columns.
Every per-node counter query filters on level plus the breakdown
columns above the node. With all levels in one table a plain scan
touches every level's segments, so index on exactly those columns.
@gignat-dev

Copy link
Copy Markdown
Contributor Author

Thank you for the comments.

Let me know if they were addressed correctly.

@LalitMaganti

Copy link
Copy Markdown
Member

Am I missing something? You still seem to be having most of the levels logic etc? Unless I"m wrong, none of that should be necessary. But I feel at this point I am missing something.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants