diff --git a/sample/profiles/trace-event/simultaneous-anonymous-calls.json b/sample/profiles/trace-event/simultaneous-anonymous-calls.json new file mode 100644 index 000000000..4f878de53 --- /dev/null +++ b/sample/profiles/trace-event/simultaneous-anonymous-calls.json @@ -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} +] \ No newline at end of file diff --git a/src/import/__snapshots__/trace-event.test.ts.snap b/src/import/__snapshots__/trace-event.test.ts.snap index b5c3d4c4e..efc317ad3 100644 --- a/src/import/__snapshots__/trace-event.test.ts.snap +++ b/src/import/__snapshots__/trace-event.test.ts.snap @@ -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 [ diff --git a/src/import/trace-event.test.ts b/src/import/trace-event.test.ts index 1fdd5f9b1..6a8e956c6 100644 --- a/src/import/trace-event.test.ts +++ b/src/import/trace-event.test.ts @@ -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') }) diff --git a/src/import/trace-event.ts b/src/import/trace-event.ts index 0fa5ff573..642707075 100644 --- a/src/import/trace-event.ts +++ b/src/import/trace-event.ts @@ -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[]] {