-
Notifications
You must be signed in to change notification settings - Fork 450
Improve the import of profiles generated from clang -ftime-trace=file.json #5714
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
+77
−5
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -339,7 +339,8 @@ function getThreadInfo( | |
| if (threadNameEvent) { | ||
| thread.name = threadNameEvent.args.name; | ||
| thread.isMainThread = | ||
| thread.name.startsWith('Cr') && thread.name.endsWith('Main'); | ||
| (thread.name.startsWith('Cr') && thread.name.endsWith('Main')) || | ||
| (!!chunk.pid && chunk.pid === chunk.tid); | ||
| } | ||
|
|
||
| const processNameEvent = findEvent<ProcessNameEvent>( | ||
|
|
@@ -940,6 +941,14 @@ function extractMarkers( | |
| }, | ||
| ]; | ||
|
|
||
| // Map to store begin event detail field for pairing with end events. | ||
| // For async events (b/e), key is "pid:tid:id:name" | ||
| // For duration events (B/E), key is "pid:tid:name" | ||
| const beginEventDetail: Map<string, string> = new Map(); | ||
|
|
||
| // Track whether we've added the EventWithDetail schema | ||
| let hasEventWithDetailSchema = false; | ||
|
|
||
| for (const [name, events] of eventsByName.entries()) { | ||
| if ( | ||
| name === 'Profile' || | ||
|
|
@@ -988,11 +997,35 @@ function extractMarkers( | |
| const { thread } = threadInfo; | ||
| const { markers } = thread; | ||
| let argData: | ||
| | (object & { type2?: unknown; category2?: unknown }) | ||
| | (object & { type2?: unknown; category2?: unknown; detail?: string }) | ||
| | null = null; | ||
| if ('args' in event && event.args && typeof event.args === 'object') { | ||
| argData = event.args.data || null; | ||
| // Some trace events have args.data, but others have args fields directly | ||
| // (e.g., "Source" markers have args.detail). | ||
| if (event.args.data) { | ||
| argData = event.args.data; | ||
| } else if ( | ||
| 'detail' in event.args && | ||
| typeof event.args.detail === 'string' | ||
| ) { | ||
| argData = { detail: event.args.detail }; | ||
| } | ||
| } | ||
|
|
||
| // For end events (E/e), try to use the detail from the corresponding begin event | ||
| if ((event.ph === 'E' || event.ph === 'e') && !argData) { | ||
| // Generate key for looking up the begin event detail | ||
| // For async events (b/e), use id; for duration events (B/E), use name only | ||
| const key = | ||
| event.ph === 'e' && 'id' in event | ||
| ? `${event.pid}:${event.tid}:${event.id}:${name}` | ||
| : `${event.pid}:${event.tid}:${name}`; | ||
|
Comment on lines
+1019
to
+1022
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we extract this key generation logic and use it in all 3 places? |
||
| const detail = beginEventDetail.get(key); | ||
| if (detail) { | ||
| argData = { detail }; | ||
| } | ||
| } | ||
|
|
||
| markers.name.push(stringTable.indexForString(name)); | ||
| markers.category.push(otherCategoryIndex); | ||
|
|
||
|
|
@@ -1003,9 +1036,32 @@ function extractMarkers( | |
| argData.category2 = argData.category; | ||
| } | ||
|
|
||
| // Add EventWithDetail schema the first time we encounter a detail field | ||
| if (argData?.detail && !hasEventWithDetailSchema) { | ||
| profile.meta.markerSchema.push({ | ||
| // Generic schema for Chrome trace event markers with a detail field. | ||
| // This is used when compiling with clang -ftime-trace=file.json, which | ||
| // generates Source markers, ParseDeclarationOrFunctionDefinition markers, | ||
| // and similar compiler events with file paths or location details. | ||
| name: 'EventWithDetail', | ||
| chartLabel: '{marker.data.detail}', | ||
| tooltipLabel: '{marker.name}: {marker.data.detail}', | ||
| tableLabel: '{marker.data.detail}', | ||
| display: ['marker-chart', 'marker-table'], | ||
| fields: [ | ||
| { | ||
| key: 'detail', | ||
| label: 'Details', | ||
| format: 'string', | ||
| }, | ||
| ], | ||
| }); | ||
| hasEventWithDetailSchema = true; | ||
| } | ||
|
|
||
| const newData = { | ||
| ...argData, | ||
| type: name, | ||
| type: argData?.detail ? 'EventWithDetail' : name, | ||
| category: event.cat, | ||
| }; | ||
|
|
||
|
|
@@ -1026,13 +1082,29 @@ function extractMarkers( | |
| markers.startTime.push(time); | ||
| markers.endTime.push(null); | ||
| markers.phase.push(INTERVAL_START); | ||
|
|
||
| // Store the detail field from begin event so it can be used for the corresponding end event | ||
| if (argData?.detail) { | ||
| const key = | ||
| event.ph === 'b' && 'id' in event | ||
| ? `${event.pid}:${event.tid}:${event.id}:${name}` | ||
| : `${event.pid}:${event.tid}:${name}`; | ||
| beginEventDetail.set(key, argData.detail); | ||
| } | ||
| } else if (event.ph === 'E' || event.ph === 'e') { | ||
| // Duration or Async Event End | ||
| // https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.nso4gcezn7n1 | ||
| // The 'E' and 'e' phase stand for "end", and is the Chrome equivalent of IntervalEnd. | ||
| markers.startTime.push(null); | ||
| markers.endTime.push(time); | ||
| markers.phase.push(INTERVAL_END); | ||
|
|
||
| // Clean up the stored begin event detail | ||
| const key = | ||
| event.ph === 'e' && 'id' in event | ||
| ? `${event.pid}:${event.tid}:${event.id}:${name}` | ||
| : `${event.pid}:${event.tid}:${name}`; | ||
| beginEventDetail.delete(key); | ||
| } else { | ||
| // Instant Event | ||
| // https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.lenwiilchoxp | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
I was very surprised that we needed a map here, because normally we merge the payloads of start and end markers:
profiler/src/profile-logic/marker-data.ts
Lines 588 to 604 in 2ce8ab6
And this should have been enough. So locally I tried to remove it and noticed that it actually regressed the state.
Then I accidentally opened a can of worms, because it looks like even though we don't have marker payloads in a chrome event, we still assign a dummy payload to it here:
profiler/src/profile-logic/import/chrome.ts
Lines 1006 to 1010 in 2ce8ab6
It looks like it's just for the category, but wait, we don't actually show the category anywhere in the UI since we don't have a marker schema!
And the marker category itself is assigned to Other by default!
So because of the fact that we always assign a payload even when it doesn't have a payload is breaking this marker payload merge logic...
So even though I don't like this
beginEventDetailmap, since the chrome importer was broken before this PR, it's unfair to ask for a bigger change from you. I will merge this PR and then I will follow-up myself with proper fixes that:beginEventDetailall together with all the logic around it.Another issue I had with this map is that it wouldn't work well with the nested markers. I don't know if it's possible to have any from clang or any other tool, but I think that's a source of bugs too. But considering that this map will go away, we shouldn't really spend a lot of time on it.