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

Fix bug in selectQueueToTakeFromNext for trace profiles #450

Merged
merged 7 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sample/profiles/trace-event/simultaneous-anonymous-calls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{"pid": 0, "tid": 0, "ph": "B", "name": "anonymous", "ts": 0},
{"pid": 0, "tid": 0, "ph": "B", "name": "anonymous", "ts": 1, "args": { "parent": 1 }},
{"pid": 0, "tid": 0, "ph": "B", "name": "function1", "ts": 1, "args": { "parent": 2 }},
{"pid": 0, "tid": 0, "ph": "B", "name": "anonymous", "ts": 1, "args": { "parent": 3 }},
{"pid": 0, "tid": 0, "ph": "E", "name": "anonymous", "ts": 3, "args": { "parent": 3 }},
{"pid": 0, "tid": 0, "ph": "E", "name": "function1", "ts": 3, "args": { "parent": 2 }},
{"pid": 0, "tid": 0, "ph": "E", "name": "anonymous", "ts": 3, "args": { "parent": 1 }},
{"pid": 0, "tid": 0, "ph": "B", "name": "anonymous", "ts": 3, "args": { "parent": 1 }},
{"pid": 0, "tid": 0, "ph": "B", "name": "anonymous", "ts": 3, "args": { "parent": 8 }},
{"pid": 0, "tid": 0, "ph": "E", "name": "anonymous", "ts": 5, "args": { "parent": 8 }},
{"pid": 0, "tid": 0, "ph": "E", "name": "anonymous", "ts": 5, "args": { "parent": 1 }},
{"pid": 0, "tid": 0, "ph": "E", "name": "anonymous", "ts": 5}
]
62 changes: 62 additions & 0 deletions src/import/__snapshots__/trace-event.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,68 @@ exports[`importTraceEvents bad E events: indexToView 1`] = `0`;

exports[`importTraceEvents bad E events: profileGroup.name 1`] = `"too-many-end-events.json"`;

exports[`importTraceEvents different number of start and end calls to same function at same timestamp 1`] = `
Object {
"frames": Array [
Frame {
"col": undefined,
"file": undefined,
"key": "anonymous",
"line": undefined,
"name": "anonymous",
"selfWeight": 1,
"totalWeight": 5,
},
Frame {
"col": undefined,
"file": undefined,
"key": "anonymous {\\"parent\\":1}",
"line": undefined,
"name": "anonymous {\\"parent\\":1}",
"selfWeight": 0,
"totalWeight": 4,
},
Frame {
"col": undefined,
"file": undefined,
"key": "function1 {\\"parent\\":2}",
"line": undefined,
"name": "function1 {\\"parent\\":2}",
"selfWeight": 0,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "anonymous {\\"parent\\":3}",
"line": undefined,
"name": "anonymous {\\"parent\\":3}",
"selfWeight": 2,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "anonymous {\\"parent\\":8}",
"line": undefined,
"name": "anonymous {\\"parent\\":8}",
"selfWeight": 2,
"totalWeight": 2,
},
],
"name": "pid 0, tid 0",
"stacks": Array [
"anonymous 1.00µs",
"anonymous;anonymous {\\"parent\\":1};function1 {\\"parent\\":2};anonymous {\\"parent\\":3} 2.00µs",
"anonymous;anonymous {\\"parent\\":1};anonymous {\\"parent\\":8} 2.00µs",
],
}
`;

exports[`importTraceEvents different number of start and end calls to same function at same timestamp: indexToView 1`] = `0`;

exports[`importTraceEvents different number of start and end calls to same function at same timestamp: profileGroup.name 1`] = `"simultaneous-anonymous-calls.json"`;

exports[`importTraceEvents end event with empty stack 1`] = `
Object {
"frames": Array [
Expand Down
4 changes: 4 additions & 0 deletions src/import/trace-event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ test('importTraceEvents bad E events', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/too-many-end-events.json')
})

test('importTraceEvents different number of start and end calls to same function at same timestamp', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/simultaneous-anonymous-calls.json')
})

test('importTraceEvents event re-ordering', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/must-retain-original-order.json')
})
Expand Down
4 changes: 2 additions & 2 deletions src/import/trace-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ function selectQueueToTakeFromNext(
// If we got here, the 'B' event queue and the 'E' event queue have events at
// the front with equal timestamps.

// If the front of the 'E' queue matches the front of the 'B' queue by name,
// If the front of the 'E' queue matches the front of the 'B' queue by key,
// then it means we have a zero duration event. Process the 'B' queue first
// to ensure it opens before we try to close it.
//
// Otherwise, process the 'E' queue first.
return bFront.name === eFront.name ? 'B' : 'E'
return frameInfoForEvent(bFront).key === frameInfoForEvent(eFront).key ? 'B' : 'E'
}

function convertToEventQueues(events: ImportableTraceEvent[]): [BTraceEvent[], ETraceEvent[]] {
Expand Down
Loading