Skip to content

Add Perfetto tracing (on basic operator execution) - #2777

Open
PATH242 wants to merge 2 commits into
masterfrom
path242/perfetto-basic
Open

PATH242 wants to merge 2 commits into
masterfrom
path242/perfetto-basic

Conversation

@PATH242

@PATH242 PATH242 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds optional tracing with Perfetto. Traces can be explored in the Perfetto UI as a timeline across worker threads. This first step records operator executions only. More detailed tracing will follow in separate PRs.

Changes

  • Adds the Perfetto SDK to third_party. It is only compiled and linked with -DENABLE_PERFETTO=ON (default: OFF).
  • Adds utils/tracing.{hpp,cpp} with HYRISE_TRACE_EVENT* macros. Without Perfetto, they expand to nothing.
  • Traces each operator execution in AbstractOperator::execute() as one slice. The slice carries the operator's description and its input/output row counts as arguments.
  • The trace is streamed during the run, so long benchmarks do not lose events. It's finalized at process exit.

Usage

cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_PERFETTO=ON ..
HYRISE_PERFETTO_TRACE_FILE=tpch.perfetto-trace ./hyriseBenchmarkTPCH -s 1 -r 10 --scheduler

Open the resulting file at https://ui.perfetto.dev

Example: TPC-H Q9, SF 1

Single-threaded:
image

With scheduler --cores 8:
image

Next steps

  • Trace benchmark item runs, SQL pipeline stages, and individual optimizer rules, so that operators can be related to the query they belong to.
  • Trace scheduler/task wait times.
  • Detailed tracing of each operator's major functions

@PATH242
PATH242 force-pushed the path242/perfetto-basic branch from 44e75be to 4fb4652 Compare September 27, 2026 13:57
@PATH242
PATH242 marked this pull request as ready for review September 27, 2026 14:32
@PATH242
PATH242 requested a review from Bouncner September 27, 2026 14:32
Comment thread src/lib/utils/perfetto_tracing.cpp
Comment thread src/lib/utils/perfetto_tracing.cpp Outdated
Comment thread src/lib/utils/perfetto_tracing.hpp Outdated
} // namespace hyrise

// Traces until the end of the current scope {} as one slice, and calls trace_event_end automatically.
#define HYRISE_TRACE_EVENT(category, ...) \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to avoid macros as much as possible. And this looks like something doable with modern C++. Can you please try to rewrite?

@PATH242 PATH242 Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure we can have wrapper functions on Perfetto's macros. But "TRACE_EVENT" specifically needs to remain a macro however way it's wrapped, as its "end" is triggered by leaving a scope. We don't need it in this PR so we can remove it, but other use cases might benefit from it.

We can also use Perfetto's macros directly... (they don't have an alternative API).

Comment thread src/lib/utils/perfetto_tracing.cpp Outdated
Comment thread src/lib/operators/abstract_operator.cpp Outdated
Comment thread src/lib/operators/abstract_operator.cpp Outdated
@PATH242

PATH242 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

I replaced our macros with plain functions, but I'm not sure macros are a bad fit here. Perfetto's API is macro-based by design, and Hyrise does the same in assert.hpp. Happy to switch back to minimal macros if it fits~

@Bouncner Bouncner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, looking good. Thanks.

Can you run a TPC-H benchmark on a proper machine (not sidon please) to check the overhead? Just curious.

./hyriseBenchmarkTPCH --scheduler --time 1200 --mode=Shuffled --clients=16 -o output.json or so.
Once with, once without perfette. Release build.

Then you can run ./scripts/compare_benchmark.py with.json without.json

static auto session = TracingSession{};
}

void trace_event_begin(std::string_view category, std::string_view name) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-wise, I like those function now much more. Yes, we have some in Hyrise (asserts) but at least back when we introduced them, they were necessary (e.g., to obtain the code line of the failed assert).

If we can avoid them, we should.
Now the question is, can we really avoid them? I am not sure. The macro previously passed __VA_ARGS__. I don't see any variadics in the C++ part?

Comment thread src/lib/utils/perfetto_tracing.cpp
Comment thread src/lib/utils/perfetto_tracing.hpp
@Bouncner

Bouncner commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Oh, and I think we should add the phases for one exemplary operator. Can you please have a look at the "operator steps" we have in the hash join? I'd like to see those in the perfetto traces.

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