Feldera samply by blp · Pull Request #6052 · feldera/feldera · GitHub
Skip to content

Feldera samply#6052

Merged
blp merged 6 commits intomainfrom
feldera-samply
Apr 16, 2026
Merged

Feldera samply#6052
blp merged 6 commits intomainfrom
feldera-samply

Conversation

@blp
Copy link
Copy Markdown
Member

@blp blp commented Apr 15, 2026

This moves the samply code into a new crate and then adds support for a memory graph (part of #6032).

@blp blp requested a review from gz April 15, 2026 22:13
@blp blp self-assigned this Apr 15, 2026
@blp blp added performance rust Pull requests that update Rust code profiler Issues related to the profiler and it's APIs labels Apr 15, 2026
Comment thread crates/samply/src/lib.rs Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these look like milliseconds to me
why not serialize the nanoseconds?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oops, you are right. I will change the name.

The serialized version must match the specification at https://github.com/firefox-devtools/profiler/blob/main/src/types/profile.ts.

Comment thread crates/samply/src/lib.rs
}

/// Calls `f` and records the span. Returns whatever `f` returned.
pub fn in_scope<F, T>(self, f: F) -> T
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why in_scope? I would call this record_span or record_span_of_function

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is meant to imitate the tracing::Span API at https://docs.rs/tracing/latest/tracing/struct.Span.html#method.in_scope

Comment thread crates/samply/src/lib.rs
/// To start a capture, use [CaptureOptions::start],
/// [CaptureOptions::blocking_start], or [CaptureOptions::try_start].
///
/// Only one `Capture` may exist at one time.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

per process?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Only one anywhere in the universe. If there are two, we must restart from the Big Bang, and we will all have to go get our PhDs again, and then we will have to do postdocs, too, even if we skipped them this time around.

Comment thread crates/samply/src/lib.rs
profile.meta.os_cpu = os_cpu;
}
profile.meta.marker_schema.push(json!({
"name": "FelderaMarker",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Always Feldera?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's an arbitrary name for which we only need uniqueness. I think it's reasonable to use Feldera in the name for that reason.

Comment thread crates/samply/src/lib.rs

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct Profile {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are these structs reverse-engineered from some JSON format of the profile? Or maybe they are documented?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread crates/samply/src/lib.rs
}
}

thread_local! {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is a global variable, it would be nice to document it.

Comment thread crates/samply/src/lib.rs

thread_local! {
static QUEUE: Arc<Queue> = Queue::new();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But if you add more comments, the file won't have exactly 1000 lines anymore, so don't do it.

Comment thread crates/samply/rustfmt.toml Outdated
@@ -0,0 +1 @@
edition = "2024" No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we just make this the workspace default? by moving this one level up?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, if we do one of the following:

  • Migrate all our crates to 2024 edition.
  • Change the crates that are 2021 edition to instead explicitly say so.

The former is probably better, but also more work.

The crates this affects are feldera-macros, iceberg, ir, pipeline-manager, rest-api, and storage-test-compat.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The former is probably better, but also more work.

I thought this is just about formatting, does it involve more than just cargo fmt with this edition set?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, hmm, it seems like all our crates format OK with 2024 edition. They don't format OK with 2021 edition because then cargo fmt chokes on if let ... && let ....

I'll make that change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That sounds like a separate PR

@gz
Copy link
Copy Markdown
Contributor

gz commented Apr 15, 2026

note that because we haven't released v288 for the other crates, ideally we have wait until we release v289 to merge it to not break the release (and adjust the cargo version for it to 289) -- I fear otherwise it might complain during release trying to release someting that's already published

@blp
Copy link
Copy Markdown
Member Author

blp commented Apr 15, 2026

note that because we haven't released v288 for the other crates, ideally we have wait until we release v289 to merge it to not break the release (and adjust the cargo version for it to 289) -- I fear otherwise it might complain during release trying to release someting that's already published

I'll wait to merge this then. No worries.

Copy link
Copy Markdown

@mythical-fred mythical-fred left a comment

Choose a reason for hiding this comment

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

One blocker, see inline.

Comment thread crates/samply/src/lib.rs
}
}

/// Enables or disables recording the amount of memory in use (the resident
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR is not just a crate move: it adds new runtime behavior by recording and emitting the memory graph data into annotated profiles, but I do not see any unit or integration coverage for that new path. Per our test rule, behavior changes need automated coverage. Please add a focused test around the new annotation logic -- e.g. a small synthetic profile/assertion that Annotations::apply() emits the expected memory track when RSS samples are present, plus one no-memory case so this does not silently regress later.

@gz
Copy link
Copy Markdown
Contributor

gz commented Apr 16, 2026

blp added 5 commits April 16, 2026 10:04
Signed-off-by: Ben Pfaff <blp@feldera.com>
Signed-off-by: Ben Pfaff <blp@feldera.com>
Signed-off-by: Ben Pfaff <blp@feldera.com>
Signed-off-by: Ben Pfaff <blp@feldera.com>
We don't define the format; it comes from the Firefox profiler.

Signed-off-by: Ben Pfaff <blp@feldera.com>
@blp blp force-pushed the feldera-samply branch from aecbe70 to 0b51dcd Compare April 16, 2026 18:26
Signed-off-by: feldera-bot <feldera-bot@feldera.com>
@blp blp added this pull request to the merge queue Apr 16, 2026
Merged via the queue into main with commit 529fc03 Apr 16, 2026
1 check passed
@blp blp deleted the feldera-samply branch April 16, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance profiler Issues related to the profiler and it's APIs rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants