Repository navigation
feat(profiling): Send Hermes samples as UI profile chunks on Android #6966
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
Merged
+519
−11
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05ca632
feat(profiling): Send Hermes samples as UI profile chunks on Android
alwx 5f441b4
fix(profiling): Don't start the Hermes sampler after the client closes
alwx 142f706
fix(profiling): Send Hermes chunks when profilesSampleRate is 0
alwx 027481c
fix(profiling): Only stop the Hermes sampler when the client closes
alwx 39616cf
fix(profiling): Send the current Hermes chunk when the client flushes
alwx 651e788
fix(profiling): Stop the native UI profiler and stay stopped after close
alwx e63de88
Merge branch 'main' into alwx/feature/6894
alwx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import type { Client, ProfileChunk } from '@sentry/core'; | ||
|
|
||
| import { uuid4 } from '@sentry/core'; | ||
|
|
||
| import type * as Hermes from './hermes'; | ||
|
|
||
| import { getDefaultEnvironment } from '../utils/environment'; | ||
| import { convertToSentryProfile } from './convertHermesProfile'; | ||
| import { getDebugMetadata } from './debugid'; | ||
|
|
||
| /** | ||
| * Thread id of the Hermes samples in a profile chunk. | ||
| * | ||
| * The native profiler also samples the JS thread under its OS thread id. Sentry merges all chunks of | ||
| * a profiler id, so the Hermes samples need their own id. Linux thread ids stay below 2^22. | ||
| */ | ||
| export const HERMES_CHUNK_THREAD_ID = String(2 ** 32); | ||
|
|
||
| /** Relay rejects profile chunks that are longer than 66 seconds. */ | ||
| const MAX_CHUNK_DURATION_NS = 66e9; | ||
|
|
||
| /** | ||
| * Converts a Hermes profile to a profile chunk for the native profiler session `profilerId`. | ||
| * | ||
| * Hermes timestamps use a monotonic clock, so the samples are placed relative to | ||
| * `startTimestampMs`, the Unix time when the Hermes sampler started. | ||
| */ | ||
| export function createHermesProfileChunk( | ||
| hermesProfile: Hermes.Profile, | ||
| startTimestampMs: number, | ||
| profilerId: string, | ||
| client: Client, | ||
| ): ProfileChunk | null { | ||
| const profile = convertToSentryProfile(hermesProfile, MAX_CHUNK_DURATION_NS); | ||
| if (!profile) { | ||
| return null; | ||
| } | ||
|
|
||
| const options = client.getOptions(); | ||
| const sdk = client.getSdkMetadata()?.sdk; | ||
| return { | ||
| chunk_id: uuid4(), | ||
| profiler_id: profilerId, | ||
| client_sdk: { name: sdk?.name ?? '', version: sdk?.version ?? '' }, | ||
| platform: 'javascript', | ||
| version: '2', | ||
| release: options.release ?? '', | ||
| environment: options.environment ?? getDefaultEnvironment(), | ||
| debug_meta: { images: getDebugMetadata() }, | ||
| profile: { | ||
| frames: profile.frames, | ||
| stacks: profile.stacks, | ||
| samples: profile.samples.map(sample => ({ | ||
| stack_id: sample.stack_id, | ||
| thread_id: HERMES_CHUNK_THREAD_ID, | ||
| timestamp: startTimestampMs / 1e3 + Number(sample.elapsed_since_start_ns) / 1e9, | ||
| })), | ||
| thread_metadata: { [HERMES_CHUNK_THREAD_ID]: profile.thread_metadata[profile.active_thread_id] ?? {} }, | ||
| }, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flush handler restarts Hermes during client close
client.on('flush', rotateHermesChunk)restarts the Hermes sampler on close (close flushes first); the close handler then stops and discards that new session. Collect the final chunk on flush without restarting during shutdown so teardown does not callstartProfilingagain.Evidence
rotateHermesChunk()always doescollectHermesChunk()thenstartHermesChunk(profilerId).Client.close()flushes before emit(close); the test expectsstartProfilingtwice andstopProfilingtwice on close.closehandler callsstopHermesSampler()(discard, no send), so the post-flush restart is thrown away.pthread_killSIGABRT (fix(android): Stop Hermes profiler on React instance teardown #6035).Identified by Warden · code-review · LXE-3WQ