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

Add support for logging events and intervals in the macOS profiler #4636

Merged
merged 7 commits into from
May 10, 2023

Conversation

alexkirsz
Copy link
Contributor

@alexkirsz alexkirsz commented Apr 19, 2023

Description

Surprisingly, I couldn't find an adequate out-of-the-box crate for adding signposts to the macOS profiler. I had to dig in to semi-private macOS APIs to add this capability.

Here's what signposts look like in the profiler view:

image

Testing Instructions

N/A

link WEB-931

@vercel
Copy link

vercel bot commented Apr 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo 🔄 Building (Inspect) May 1, 2023 3:36pm
10 Ignored Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) May 1, 2023 3:36pm
examples-cra-web ⬜️ Ignored (Inspect) May 1, 2023 3:36pm
examples-designsystem-docs ⬜️ Ignored (Inspect) May 1, 2023 3:36pm
examples-gatsby-web ⬜️ Ignored (Inspect) May 1, 2023 3:36pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) May 1, 2023 3:36pm
examples-native-web ⬜️ Ignored (Inspect) May 1, 2023 3:36pm
examples-svelte-web ⬜️ Ignored (Inspect) May 1, 2023 3:36pm
examples-tailwind-web ⬜️ Ignored (Inspect) May 1, 2023 3:36pm
examples-vite-web ⬜️ Ignored (Inspect) May 1, 2023 3:36pm
turbo-site ⬜️ Ignored (Inspect) Visit Preview May 1, 2023 3:36pm

@github-actions
Copy link
Contributor

github-actions bot commented Apr 19, 2023

✅ This change can build next-swc

@github-actions
Copy link
Contributor

github-actions bot commented Apr 19, 2023

🟢 CI successful 🟢

Thanks

@mehulkar mehulkar removed their request for review April 19, 2023 21:55
crates/utils/signposter/src/lib.rs Outdated Show resolved Hide resolved
crates/utils/signposter/src/lib.rs Outdated Show resolved Hide resolved
crates/utils/signposter/src/lib.rs Outdated Show resolved Hide resolved
crates/utils/signposter/src/lib.rs Outdated Show resolved Hide resolved
crates/utils/signposter/src/lib.rs Outdated Show resolved Hide resolved
crates/utils/signposter/src/lib.rs Outdated Show resolved Hide resolved
crates/utils/signposter/src/lib.rs Outdated Show resolved Hide resolved
crates/utils/signposter/src/lib.rs Outdated Show resolved Hide resolved
/// Escapes a message for use with signposts, which will try to parse it as a
/// format string.
fn escape_message(message: &str) -> String {
message.replace('%', "%%")
Copy link
Member

Choose a reason for hiding this comment

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

This can be Cow with check for existence of %

impl Log {
/// Create a new log with the given subsystem and category.
pub fn new_with_subsystem_and_category(subsystem: &str, category: LogCategory) -> Self {
let subsystem = CString::new(subsystem).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Same here, the content of subsystem is not dropped while the function returns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you explain what you mean here?

@sokra
Copy link
Member

sokra commented Apr 20, 2023

Is it possible use the https://crates.io/crates/tracing and make signposts a provider for that?

@alexkirsz
Copy link
Contributor Author

@sokra Yes. Right now this implementation is very minimal as the goal was to get it working first and foremost to get some insights fast, but eventually we definitely should integrate it with tracing.

@alexkirsz
Copy link
Contributor Author

Failed to execute xcrun: Os { code: 2, kind: NotFound, message: "No such file or directory" }

https://github.com/vercel/turbo/actions/runs/4745099662/jobs/8426941687?pr=4636

I need to make the whole crate a noop for anything else than macOS.

@alexkirsz
Copy link
Contributor Author

I've added a tracing layer which is now used in turbopack-dev-server instead of using signposter directly.

Be aware that tracing is currently force-disabled in nextpack because some next-swc crates enable max_level_off/max_level_* features, which are applied on the whole workspace. cc @kdy1 could we disable these by default somehow and only enable them for actual releases in CI?

@alexkirsz alexkirsz added the pr: automerge Kodiak will merge these automatically after checks pass label May 1, 2023
@kdy1
Copy link
Member

kdy1 commented May 9, 2023

Yes, it's possible and it can be done using sed. Note that sed behaves bit differently on mac OS.

@alexkirsz alexkirsz enabled auto-merge (squash) May 9, 2023 14:27
@alexkirsz alexkirsz removed the pr: automerge Kodiak will merge these automatically after checks pass label May 9, 2023
@alexkirsz alexkirsz merged commit 14b7fd4 into main May 10, 2023
43 checks passed
@alexkirsz alexkirsz deleted the alexkirsz/web-931-signposts branch May 10, 2023 12:46
alexkirsz added a commit to vercel/next.js that referenced this pull request May 11, 2023
See vercel/turbo#4866

This also updates Turbopack to turbopack-230511.2 with the following
changes:

* vercel/turbo#4636 <!-- Alex Kirszenberg - Add
support for logging events and intervals in the macOS profiler -->
* vercel/turbo#4793 <!-- OJ Kwon - ci(workflow):
enable more test -->
* vercel/turbo#4886 <!-- OJ Kwon -
refactor(ecmascript-plugins): update serverdirective signature -->
* vercel/turbo#4866 <!-- Alex Kirszenberg -
Rename Turbopack/tasks crates to common prefixes -->
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.

None yet

3 participants