@paulirish/trace_engine 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analyze-trace.mjs +24 -16
- package/generated/protocol.d.ts +26 -3
- package/models/cpu_profile/CPUProfileDataModel.d.ts +1 -1
- package/models/cpu_profile/CPUProfileDataModel.js +6 -6
- package/models/cpu_profile/CPUProfileDataModel.js.map +1 -1
- package/models/trace/ModelImpl.d.ts +0 -6
- package/models/trace/ModelImpl.js +1 -10
- package/models/trace/ModelImpl.js.map +1 -1
- package/models/trace/Processor.d.ts +0 -1
- package/models/trace/Processor.js +13 -14
- package/models/trace/Processor.js.map +1 -1
- package/models/trace/TracingManager.js.map +1 -1
- package/models/trace/handlers/AuctionWorkletsHandler.js +1 -0
- package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -1
- package/models/trace/handlers/ExtensionTraceDataHandler.js +18 -5
- package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
- package/models/trace/handlers/LayoutShiftsHandler.js +1 -0
- package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
- package/models/trace/handlers/NetworkRequestsHandler.d.ts +1 -1
- package/models/trace/handlers/NetworkRequestsHandler.js +6 -8
- package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
- package/models/trace/handlers/PageLoadMetricsHandler.js +1 -1
- package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
- package/models/trace/handlers/RendererHandler.js +17 -7
- package/models/trace/handlers/RendererHandler.js.map +1 -1
- package/models/trace/handlers/SamplesHandler.d.ts +1 -0
- package/models/trace/handlers/SamplesHandler.js +11 -5
- package/models/trace/handlers/SamplesHandler.js.map +1 -1
- package/models/trace/handlers/ScreenshotsHandler.js +1 -0
- package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
- package/models/trace/handlers/Threads.js +2 -2
- package/models/trace/handlers/Threads.js.map +1 -1
- package/models/trace/handlers/UserInteractionsHandler.js +1 -0
- package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
- package/models/trace/handlers/WarningsHandler.js +0 -1
- package/models/trace/handlers/WarningsHandler.js.map +1 -1
- package/models/trace/helpers/Extensions.js +4 -0
- package/models/trace/helpers/Extensions.js.map +1 -1
- package/models/trace/helpers/SamplesIntegrator.d.ts +6 -1
- package/models/trace/helpers/SamplesIntegrator.js +36 -8
- package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
- package/models/trace/helpers/Trace.d.ts +80 -7
- package/models/trace/helpers/Trace.js +190 -24
- package/models/trace/helpers/Trace.js.map +1 -1
- package/models/trace/helpers/TreeHelpers.d.ts +20 -0
- package/models/trace/helpers/TreeHelpers.js +50 -0
- package/models/trace/helpers/TreeHelpers.js.map +1 -1
- package/models/trace/insights/CumulativeLayoutShift.d.ts +29 -0
- package/models/trace/insights/CumulativeLayoutShift.js +81 -0
- package/models/trace/insights/CumulativeLayoutShift.js.map +1 -0
- package/models/trace/insights/InsightRunners.d.ts +1 -0
- package/models/trace/insights/InsightRunners.js +1 -0
- package/models/trace/insights/InsightRunners.js.map +1 -1
- package/models/trace/insights/RenderBlocking.js +14 -0
- package/models/trace/insights/RenderBlocking.js.map +1 -1
- package/models/trace/insights/insights-tsconfig.json +1 -0
- package/models/trace/trace-tsconfig.json +0 -1
- package/models/trace/trace.d.ts +1 -2
- package/models/trace/trace.js +1 -4
- package/models/trace/trace.js.map +1 -1
- package/models/trace/types/Configuration.d.ts +16 -28
- package/models/trace/types/Configuration.js +7 -27
- package/models/trace/types/Configuration.js.map +1 -1
- package/models/trace/types/TraceEvents.d.ts +84 -19
- package/models/trace/types/TraceEvents.js +22 -1
- package/models/trace/types/TraceEvents.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SamplesIntegrator.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/SamplesIntegrator.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;A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AY,CAAC,WAAW,CAAC,qBAAqB,CAAC;QACrE,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QACD,IAAI,uBAAuB,GAAgB,IAAI,CAAC;QAChD,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YACtC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACjC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;YACzE,IAAI,kBAAkB;gBAClB,CAAC,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,YAAY,EAAE,YAAY,CAAC,WAAW,CAAC,0BAA0B,CAAC,EAAE,CAAC;gBAC/G,SAAS;YACX,CAAC;YACD,MAAM,eAAe,GAAG,kBAAkB,CAAC,CAAC,CAAC,iBAAiB,CAAC,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACtG,IAAI,uBAAuB,IAAI,uBAAuB,KAAK,eAAe,EAAE,CAAC;gBAC3E,SAAS;YACX,CAAC;YACD,uBAAuB,GAAG,eAAe,CAAC;YAC1C,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;QACD,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport type * as Protocol from '../../../generated/protocol.js';\nimport type * as CPUProfile from '../../cpu_profile/cpu_profile.js';\nimport * as Types from '../types/types.js';\n\nimport {millisecondsToMicroseconds} from './Timing.js';\nimport {makeProfileCall, mergeEventsInOrder} from './Trace.js';\n\n/**\n * This is a helper that integrates CPU profiling data coming in the\n * shape of samples, with trace events. Samples indicate what the JS\n * stack trace looked at a given point in time, but they don't have\n * duration. The SamplesIntegrator task is to make an approximation\n * of what the duration of each JS call was, given the sample data and\n * given the trace events profiled during that time. At the end of its\n * execution, the SamplesIntegrator returns an array of ProfileCalls\n * (under SamplesIntegrator::buildProfileCalls()), which\n * represent JS calls, with a call frame and duration. These calls have\n * the shape of a complete trace events and can be treated as flame\n * chart entries in the timeline.\n *\n * The approach to build the profile calls consists in tracking the\n * current stack as the following events happen (in order):\n * 1. A sample was done.\n * 2. A trace event started.\n * 3. A trace event ended.\n * Depending on the event and on the data that's coming with it the\n * stack is updated by adding or removing JS calls to it and updating\n * the duration of the calls in the tracking stack.\n *\n * note: Although this approach has been implemented since long ago, and\n * is relatively efficent (adds a complexity over the trace parsing of\n * O(n) where n is the number of samples) it has proven to be faulty.\n * It might be worthwhile experimenting with improvements or with a\n * completely different approach. Improving the approach is tracked in\n * crbug.com/1417439\n */\nexport class SamplesIntegrator {\n /**\n * The result of runing the samples integrator. Holds the JS calls\n * with their approximated duration after integrating samples into the\n * trace event tree.\n */\n #constructedProfileCalls: Types.TraceEvents.SyntheticProfileCall[] = [];\n /**\n * tracks the state of the JS stack at each point in time to update\n * the profile call durations as new events arrive. This doesn't only\n * happen with new profile calls (in which case we would compare the\n * stack in them) but also with trace events (in which case we would\n * update the duration of the events we are tracking at the moment).\n */\n #currentJSStack: Types.TraceEvents.SyntheticProfileCall[] = [];\n /**\n * Process holding the CPU profile and trace events.\n */\n #processId: Types.TraceEvents.ProcessID;\n /**\n * Thread holding the CPU profile and trace events.\n */\n #threadId: Types.TraceEvents.ThreadID;\n /**\n * Tracks the depth of the JS stack at the moment a trace event starts\n * or ends. It is assumed that for the duration of a trace event, the\n * JS stack's depth cannot decrease, since JS calls that started\n * before a trace event cannot end during the trace event. So as trace\n * events arrive, we store the \"locked\" amount of JS frames that were\n * in the stack before the event came.\n */\n #lockedJsStackDepth: number[] = [];\n /**\n * Used to keep track when samples should be integrated even if they\n * are not children of invocation trace events. This is useful in\n * cases where we can be missing the start of JS invocation events if\n * we start tracing half-way through.\n */\n #fakeJSInvocation = false;\n /**\n * The parsed CPU profile, holding the tree hierarchy of JS frames and\n * the sample data.\n */\n #profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel;\n /**\n * Because GC nodes don't have a stack, we artificially add a stack to\n * them which corresponds to that of the previous sample. This map\n * tracks which node is used for the stack of a GC call.\n * Note that GC samples are not shown in the flamechart, however they\n * are used during the construction of for profile calls, as we can\n * infer information about the duration of the executed code when a\n * GC node is sampled.\n */\n #nodeForGC = new Map<Types.TraceEvents.SyntheticProfileCall, CPUProfile.ProfileTreeModel.ProfileNode>();\n\n #engineConfig: Types.Configuration.Configuration;\n\n constructor(\n profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel, pid: Types.TraceEvents.ProcessID,\n tid: Types.TraceEvents.ThreadID, configuration?: Types.Configuration.Configuration) {\n this.#profileModel = profileModel;\n this.#threadId = tid;\n this.#processId = pid;\n this.#engineConfig = configuration || Types.Configuration.DEFAULT;\n }\n\n buildProfileCalls(traceEvents: Types.TraceEvents.TraceEventData[]): Types.TraceEvents.SyntheticProfileCall[] {\n const mergedEvents = mergeEventsInOrder(traceEvents, this.callsFromProfileSamples());\n const stack = [];\n for (let i = 0; i < mergedEvents.length; i++) {\n const event = mergedEvents[i];\n // Because instant trace events have no duration, they don't provide\n // useful information for possible changes in the duration of calls\n // in the JS stack.\n if (event.ph === Types.TraceEvents.Phase.INSTANT) {\n continue;\n }\n if (stack.length === 0) {\n if (Types.TraceEvents.isProfileCall(event)) {\n this.#onProfileCall(event);\n continue;\n }\n stack.push(event);\n this.#onTraceEventStart(event);\n continue;\n }\n\n const parentEvent = stack.at(-1);\n if (parentEvent === undefined) {\n continue;\n }\n const begin = event.ts;\n const parentBegin = parentEvent.ts;\n const parentDuration = parentEvent.dur || 0;\n const parentEnd = parentBegin + parentDuration;\n\n const startsAfterParent = begin >= parentEnd;\n if (startsAfterParent) {\n this.#onTraceEventEnd(parentEvent);\n stack.pop();\n i--;\n continue;\n }\n if (Types.TraceEvents.isProfileCall(event)) {\n this.#onProfileCall(event, parentEvent);\n continue;\n }\n this.#onTraceEventStart(event);\n stack.push(event);\n }\n while (stack.length) {\n const last = stack.pop();\n if (last) {\n this.#onTraceEventEnd(last);\n }\n }\n return this.#constructedProfileCalls;\n }\n\n #onTraceEventStart(event: Types.TraceEvents.TraceEventData): void {\n // Top level events cannot be nested into JS frames so we reset\n // the stack when we find one.\n if (event.name === Types.TraceEvents.KnownEventName.RunMicrotasks ||\n event.name === Types.TraceEvents.KnownEventName.RunTask) {\n this.#lockedJsStackDepth = [];\n this.#truncateJSStack(0, event.ts);\n this.#fakeJSInvocation = false;\n }\n\n if (this.#fakeJSInvocation) {\n this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, event.ts);\n this.#fakeJSInvocation = false;\n }\n this.#extractStackTrace(event);\n // Keep track of the call frames in the stack before the event\n // happened. For the duration of this event, these frames cannot\n // change (none can be terminated before this event finishes).\n //\n // Also, every frame that is opened after this event, is considered\n // to be a descendant of the event. So once the event finishes, the\n // frames that were opened after it, need to be closed (see\n // onEndEvent).\n //\n // TODO(crbug.com/1417439):\n // The assumption that every frame opened after an event is a\n // descendant of the event is incorrect. For example, a JS call that\n // parents a trace event might have been sampled after the event was\n // dispatched. In this case the JS call would be discarded if this\n // event isn't an invocation event, otherwise the call will be\n // considered a child of the event. In both cases, the result would\n // be incorrect.\n this.#lockedJsStackDepth.push(this.#currentJSStack.length);\n }\n\n #onProfileCall(event: Types.TraceEvents.SyntheticProfileCall, parent?: Types.TraceEvents.TraceEventData): void {\n if ((parent && Types.TraceEvents.isJSInvocationEvent(parent)) || this.#fakeJSInvocation) {\n this.#extractStackTrace(event);\n } else if (Types.TraceEvents.isProfileCall(event) && this.#currentJSStack.length === 0) {\n // Force JS Samples to show up even if we are not inside a JS\n // invocation event, because we can be missing the start of JS\n // invocation events if we start tracing half-way through. Pretend\n // we have a top-level JS invocation event.\n this.#fakeJSInvocation = true;\n const stackDepthBefore = this.#currentJSStack.length;\n this.#extractStackTrace(event);\n this.#lockedJsStackDepth.push(stackDepthBefore);\n }\n }\n\n #onTraceEventEnd(event: Types.TraceEvents.TraceEventData): void {\n // Because the event has ended, any frames that happened after\n // this event are terminated. Frames that are ancestors to this\n // event are extended to cover its ending.\n const endTime = Types.Timing.MicroSeconds(event.ts + (event.dur || 0));\n this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, endTime);\n }\n\n /**\n * Builds the initial calls with no duration from samples. Their\n * purpose is to be merged with the trace event array being parsed so\n * that they can be traversed in order with them and their duration\n * can be updated as the SampleIntegrator callbacks are invoked.\n */\n callsFromProfileSamples(): Types.TraceEvents.SyntheticProfileCall[] {\n const samples = this.#profileModel.samples;\n const timestamps = this.#profileModel.timestamps;\n if (!samples) {\n return [];\n }\n const calls: Types.TraceEvents.SyntheticProfileCall[] = [];\n let prevNode;\n for (let i = 0; i < samples.length; i++) {\n const node = this.#profileModel.nodeByIndex(i);\n const timestamp = millisecondsToMicroseconds(Types.Timing.MilliSeconds(timestamps[i]));\n if (!node) {\n continue;\n }\n const call = makeProfileCall(node, timestamp, this.#processId, this.#threadId);\n calls.push(call);\n if (node.id === this.#profileModel.gcNode?.id && prevNode) {\n // GC samples have no stack, so we just put GC node on top of the\n // last recorded sample. Cache the previous sample for future\n // reference.\n this.#nodeForGC.set(call, prevNode);\n continue;\n }\n prevNode = node;\n }\n return calls;\n }\n\n #getStackTraceFromProfileCall(profileCall: Types.TraceEvents.SyntheticProfileCall):\n Types.TraceEvents.SyntheticProfileCall[] {\n let node = this.#profileModel.nodeById(profileCall.nodeId);\n const isGarbageCollection = node?.id === this.#profileModel.gcNode?.id;\n if (isGarbageCollection) {\n // Because GC don't have a stack, we use the stack of the previous\n // sample.\n node = this.#nodeForGC.get(profileCall) || null;\n }\n if (!node) {\n return [];\n }\n // `node.depth` is 0 based, so to set the size of the array we need\n // to add 1 to its value.\n const callFrames = new Array<Types.TraceEvents.SyntheticProfileCall>(node.depth + 1 + Number(isGarbageCollection));\n // Add the stack trace in reverse order (bottom first).\n let i = callFrames.length - 1;\n if (isGarbageCollection) {\n // Place the garbage collection call frame on top of the stack.\n callFrames[i--] = profileCall;\n }\n while (node) {\n callFrames[i--] = makeProfileCall(node, profileCall.ts, this.#processId, this.#threadId);\n node = node.parent;\n }\n return callFrames;\n }\n\n /**\n * Update tracked stack using this event's call stack.\n */\n #extractStackTrace(event: Types.TraceEvents.TraceEventData): void {\n const stackTrace =\n Types.TraceEvents.isProfileCall(event) ? this.#getStackTraceFromProfileCall(event) : this.#currentJSStack;\n SamplesIntegrator.filterStackFrames(stackTrace, this.#engineConfig);\n\n const endTime = event.ts + (event.dur || 0);\n const minFrames = Math.min(stackTrace.length, this.#currentJSStack.length);\n let i;\n // Merge a sample's stack frames with the stack frames we have\n // so far if we detect they are equivalent.\n // Graphically\n // This:\n // Current stack trace Sample\n // [-------A------] [A]\n // [-------B------] [B]\n // [-------C------] [C]\n // ^ t = x1 ^ t = x2\n\n // Becomes this:\n // New stack trace after merge\n // [--------A-------]\n // [--------B-------]\n // [--------C-------]\n // ^ t = x2\n for (i = this.#lockedJsStackDepth.at(-1) || 0; i < minFrames; ++i) {\n const newFrame = stackTrace[i].callFrame;\n const oldFrame = this.#currentJSStack[i].callFrame;\n if (!SamplesIntegrator.framesAreEqual(newFrame, oldFrame)) {\n break;\n }\n // Scoot the right edge of this callFrame to the right\n this.#currentJSStack[i].dur =\n Types.Timing.MicroSeconds(Math.max(this.#currentJSStack[i].dur || 0, endTime - this.#currentJSStack[i].ts));\n }\n\n // If there are call frames in the sample that differ with the stack\n // we have, update the stack, but keeping the common frames in place\n // Graphically\n // This:\n // Current stack trace Sample\n // [-------A------] [A]\n // [-------B------] [B]\n // [-------C------] [C]\n // [-------D------] [E]\n // ^ t = x1 ^ t = x2\n // Becomes this:\n // New stack trace after merge\n // [--------A-------]\n // [--------B-------]\n // [--------C-------]\n // [E]\n // ^ t = x2\n this.#truncateJSStack(i, event.ts);\n\n for (; i < stackTrace.length; ++i) {\n const call = stackTrace[i];\n if (call.nodeId === this.#profileModel.programNode?.id || call.nodeId === this.#profileModel.root?.id ||\n call.nodeId === this.#profileModel.idleNode?.id || call.nodeId === this.#profileModel.gcNode?.id) {\n // Skip (root), (program) and (idle) frames, since this are not\n // relevant for web profiling and we don't want to show them in\n // the timeline.\n continue;\n }\n this.#currentJSStack.push(call);\n this.#constructedProfileCalls.push(call);\n }\n }\n\n /**\n * When a call stack that differs from the one we are tracking has\n * been detected in the samples, the latter is \"truncated\" by\n * setting the ending time of its call frames and removing the top\n * call frames that aren't shared with the new call stack. This way,\n * we can update the tracked stack with the new call frames on top.\n * @param depth the amount of call frames from bottom to top that\n * should be kept in the tracking stack trace. AKA amount of shared\n * call frames between two stacks.\n * @param time the new end of the call frames in the stack.\n */\n #truncateJSStack(depth: number, time: Types.Timing.MicroSeconds): void {\n if (this.#lockedJsStackDepth.length) {\n const lockedDepth = this.#lockedJsStackDepth.at(-1);\n if (lockedDepth && depth < lockedDepth) {\n console.error(`Child stack is shallower (${depth}) than the parent stack (${lockedDepth}) at ${time}`);\n depth = lockedDepth;\n }\n }\n if (this.#currentJSStack.length < depth) {\n console.error(`Trying to truncate higher than the current stack size at ${time}`);\n depth = this.#currentJSStack.length;\n }\n for (let k = 0; k < this.#currentJSStack.length; ++k) {\n this.#currentJSStack[k].dur = Types.Timing.MicroSeconds(Math.max(time - this.#currentJSStack[k].ts, 0));\n }\n this.#currentJSStack.length = depth;\n }\n\n static framesAreEqual(frame1: Protocol.Runtime.CallFrame, frame2: Protocol.Runtime.CallFrame): boolean {\n return frame1.scriptId === frame2.scriptId && frame1.functionName === frame2.functionName &&\n frame1.lineNumber === frame2.lineNumber;\n }\n\n static showNativeName(name: string, runtimeCallStatsEnabled: boolean): boolean {\n return runtimeCallStatsEnabled && Boolean(SamplesIntegrator.nativeGroup(name));\n }\n\n static nativeGroup(nativeName: string): 'Parse'|'Compile'|null {\n if (nativeName.startsWith('Parse')) {\n return 'Parse';\n }\n if (nativeName.startsWith('Compile') || nativeName.startsWith('Recompile')) {\n return 'Compile';\n }\n return null;\n }\n\n static isNativeRuntimeFrame(frame: Protocol.Runtime.CallFrame): boolean {\n return frame.url === 'native V8Runtime';\n }\n\n static filterStackFrames(\n stack: Types.TraceEvents.SyntheticProfileCall[], engineConfig: Types.Configuration.Configuration): void {\n const showAllEvents = engineConfig.experiments.timelineShowAllEvents;\n if (showAllEvents) {\n return;\n }\n let previousNativeFrameName: string|null = null;\n let j = 0;\n for (let i = 0; i < stack.length; ++i) {\n const frame = stack[i].callFrame;\n const nativeRuntimeFrame = SamplesIntegrator.isNativeRuntimeFrame(frame);\n if (nativeRuntimeFrame &&\n !SamplesIntegrator.showNativeName(frame.functionName, engineConfig.experiments.timelineV8RuntimeCallStats)) {\n continue;\n }\n const nativeFrameName = nativeRuntimeFrame ? SamplesIntegrator.nativeGroup(frame.functionName) : null;\n if (previousNativeFrameName && previousNativeFrameName === nativeFrameName) {\n continue;\n }\n previousNativeFrameName = nativeFrameName;\n stack[j++] = stack[i];\n }\n stack.length = j;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SamplesIntegrator.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/SamplesIntegrator.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAI7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,0BAA0B,EAAC,MAAM,aAAa,CAAC;AACvD,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAC,MAAM,YAAY,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,iBAAiB;IAC5B;;;;OAIG;IACH,wBAAwB,GAA6C,EAAE,CAAC;IACxE;;;;;;OAMG;IACH,eAAe,GAA6C,EAAE,CAAC;IA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AC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACtG,IAAI,uBAAuB,IAAI,uBAAuB,KAAK,eAAe,EAAE,CAAC;gBAC3E,SAAS;YACX,CAAC;YACD,uBAAuB,GAAG,eAAe,CAAC;YAC1C,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;QACD,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport type * as Protocol from '../../../generated/protocol.js';\nimport type * as CPUProfile from '../../cpu_profile/cpu_profile.js';\nimport * as Types from '../types/types.js';\n\nimport {millisecondsToMicroseconds} from './Timing.js';\nimport {makeProfileCall, mergeEventsInOrder} from './Trace.js';\n\n/**\n * This is a helper that integrates CPU profiling data coming in the\n * shape of samples, with trace events. Samples indicate what the JS\n * stack trace looked at a given point in time, but they don't have\n * duration. The SamplesIntegrator task is to make an approximation\n * of what the duration of each JS call was, given the sample data and\n * given the trace events profiled during that time. At the end of its\n * execution, the SamplesIntegrator returns an array of ProfileCalls\n * (under SamplesIntegrator::buildProfileCalls()), which\n * represent JS calls, with a call frame and duration. These calls have\n * the shape of a complete trace events and can be treated as flame\n * chart entries in the timeline.\n *\n * The approach to build the profile calls consists in tracking the\n * current stack as the following events happen (in order):\n * 1. A sample was done.\n * 2. A trace event started.\n * 3. A trace event ended.\n * Depending on the event and on the data that's coming with it the\n * stack is updated by adding or removing JS calls to it and updating\n * the duration of the calls in the tracking stack.\n *\n * note: Although this approach has been implemented since long ago, and\n * is relatively efficent (adds a complexity over the trace parsing of\n * O(n) where n is the number of samples) it has proven to be faulty.\n * It might be worthwhile experimenting with improvements or with a\n * completely different approach. Improving the approach is tracked in\n * crbug.com/1417439\n */\nexport class SamplesIntegrator {\n /**\n * The result of runing the samples integrator. Holds the JS calls\n * with their approximated duration after integrating samples into the\n * trace event tree.\n */\n #constructedProfileCalls: Types.TraceEvents.SyntheticProfileCall[] = [];\n /**\n * tracks the state of the JS stack at each point in time to update\n * the profile call durations as new events arrive. This doesn't only\n * happen with new profile calls (in which case we would compare the\n * stack in them) but also with trace events (in which case we would\n * update the duration of the events we are tracking at the moment).\n */\n #currentJSStack: Types.TraceEvents.SyntheticProfileCall[] = [];\n /**\n * Process holding the CPU profile and trace events.\n */\n #processId: Types.TraceEvents.ProcessID;\n /**\n * Thread holding the CPU profile and trace events.\n */\n #threadId: Types.TraceEvents.ThreadID;\n /**\n * Tracks the depth of the JS stack at the moment a trace event starts\n * or ends. It is assumed that for the duration of a trace event, the\n * JS stack's depth cannot decrease, since JS calls that started\n * before a trace event cannot end during the trace event. So as trace\n * events arrive, we store the \"locked\" amount of JS frames that were\n * in the stack before the event came.\n */\n #lockedJsStackDepth: number[] = [];\n /**\n * Used to keep track when samples should be integrated even if they\n * are not children of invocation trace events. This is useful in\n * cases where we can be missing the start of JS invocation events if\n * we start tracing half-way through.\n */\n #fakeJSInvocation = false;\n /**\n * The parsed CPU profile, holding the tree hierarchy of JS frames and\n * the sample data.\n */\n #profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel;\n /**\n * Because GC nodes don't have a stack, we artificially add a stack to\n * them which corresponds to that of the previous sample. This map\n * tracks which node is used for the stack of a GC call.\n * Note that GC samples are not shown in the flamechart, however they\n * are used during the construction of for profile calls, as we can\n * infer information about the duration of the executed code when a\n * GC node is sampled.\n */\n #nodeForGC = new Map<Types.TraceEvents.SyntheticProfileCall, CPUProfile.ProfileTreeModel.ProfileNode>();\n\n #engineConfig: Types.Configuration.Configuration;\n #profileId: Types.TraceEvents.ProfileID;\n\n /**\n * Keeps track of the individual samples from the CPU Profile.\n * Only used with Debug Mode experiment enabled.\n */\n jsSampleEvents: Types.TraceEvents.SyntheticJSSample[] = [];\n\n constructor(\n profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel, profileId: Types.TraceEvents.ProfileID,\n pid: Types.TraceEvents.ProcessID, tid: Types.TraceEvents.ThreadID,\n configuration?: Types.Configuration.Configuration) {\n this.#profileModel = profileModel;\n this.#threadId = tid;\n this.#processId = pid;\n this.#engineConfig = configuration || Types.Configuration.defaults();\n this.#profileId = profileId;\n }\n\n buildProfileCalls(traceEvents: Types.TraceEvents.TraceEventData[]): Types.TraceEvents.SyntheticProfileCall[] {\n const mergedEvents = mergeEventsInOrder(traceEvents, this.callsFromProfileSamples());\n const stack = [];\n for (let i = 0; i < mergedEvents.length; i++) {\n const event = mergedEvents[i];\n // Because instant trace events have no duration, they don't provide\n // useful information for possible changes in the duration of calls\n // in the JS stack.\n if (event.ph === Types.TraceEvents.Phase.INSTANT) {\n continue;\n }\n if (stack.length === 0) {\n if (Types.TraceEvents.isProfileCall(event)) {\n this.#onProfileCall(event);\n continue;\n }\n stack.push(event);\n this.#onTraceEventStart(event);\n continue;\n }\n\n const parentEvent = stack.at(-1);\n if (parentEvent === undefined) {\n continue;\n }\n const begin = event.ts;\n const parentBegin = parentEvent.ts;\n const parentDuration = parentEvent.dur || 0;\n const parentEnd = parentBegin + parentDuration;\n\n const startsAfterParent = begin >= parentEnd;\n if (startsAfterParent) {\n this.#onTraceEventEnd(parentEvent);\n stack.pop();\n i--;\n continue;\n }\n if (Types.TraceEvents.isProfileCall(event)) {\n this.#onProfileCall(event, parentEvent);\n continue;\n }\n this.#onTraceEventStart(event);\n stack.push(event);\n }\n while (stack.length) {\n const last = stack.pop();\n if (last) {\n this.#onTraceEventEnd(last);\n }\n }\n return this.#constructedProfileCalls;\n }\n\n #onTraceEventStart(event: Types.TraceEvents.TraceEventData): void {\n // Top level events cannot be nested into JS frames so we reset\n // the stack when we find one.\n if (event.name === Types.TraceEvents.KnownEventName.RunMicrotasks ||\n event.name === Types.TraceEvents.KnownEventName.RunTask) {\n this.#lockedJsStackDepth = [];\n this.#truncateJSStack(0, event.ts);\n this.#fakeJSInvocation = false;\n }\n\n if (this.#fakeJSInvocation) {\n this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, event.ts);\n this.#fakeJSInvocation = false;\n }\n this.#extractStackTrace(event);\n // Keep track of the call frames in the stack before the event\n // happened. For the duration of this event, these frames cannot\n // change (none can be terminated before this event finishes).\n //\n // Also, every frame that is opened after this event, is considered\n // to be a descendant of the event. So once the event finishes, the\n // frames that were opened after it, need to be closed (see\n // onEndEvent).\n //\n // TODO(crbug.com/1417439):\n // The assumption that every frame opened after an event is a\n // descendant of the event is incorrect. For example, a JS call that\n // parents a trace event might have been sampled after the event was\n // dispatched. In this case the JS call would be discarded if this\n // event isn't an invocation event, otherwise the call will be\n // considered a child of the event. In both cases, the result would\n // be incorrect.\n this.#lockedJsStackDepth.push(this.#currentJSStack.length);\n }\n\n #onProfileCall(event: Types.TraceEvents.SyntheticProfileCall, parent?: Types.TraceEvents.TraceEventData): void {\n if ((parent && Types.TraceEvents.isJSInvocationEvent(parent)) || this.#fakeJSInvocation) {\n this.#extractStackTrace(event);\n } else if (Types.TraceEvents.isProfileCall(event) && this.#currentJSStack.length === 0) {\n // Force JS Samples to show up even if we are not inside a JS\n // invocation event, because we can be missing the start of JS\n // invocation events if we start tracing half-way through. Pretend\n // we have a top-level JS invocation event.\n this.#fakeJSInvocation = true;\n const stackDepthBefore = this.#currentJSStack.length;\n this.#extractStackTrace(event);\n this.#lockedJsStackDepth.push(stackDepthBefore);\n }\n }\n\n #onTraceEventEnd(event: Types.TraceEvents.TraceEventData): void {\n // Because the event has ended, any frames that happened after\n // this event are terminated. Frames that are ancestors to this\n // event are extended to cover its ending.\n const endTime = Types.Timing.MicroSeconds(event.ts + (event.dur || 0));\n this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, endTime);\n }\n\n /**\n * Builds the initial calls with no duration from samples. Their\n * purpose is to be merged with the trace event array being parsed so\n * that they can be traversed in order with them and their duration\n * can be updated as the SampleIntegrator callbacks are invoked.\n */\n callsFromProfileSamples(): Types.TraceEvents.SyntheticProfileCall[] {\n const samples = this.#profileModel.samples;\n const timestamps = this.#profileModel.timestamps;\n const debugModeEnabled = this.#engineConfig.debugMode;\n if (!samples) {\n return [];\n }\n const calls: Types.TraceEvents.SyntheticProfileCall[] = [];\n let prevNode;\n for (let i = 0; i < samples.length; i++) {\n const node = this.#profileModel.nodeByIndex(i);\n const timestamp = millisecondsToMicroseconds(Types.Timing.MilliSeconds(timestamps[i]));\n if (!node) {\n continue;\n }\n const call = makeProfileCall(node, this.#profileId, i, timestamp, this.#processId, this.#threadId);\n calls.push(call);\n\n if (debugModeEnabled) {\n this.jsSampleEvents.push(this.#makeJSSampleEvent(call, timestamp));\n }\n if (node.id === this.#profileModel.gcNode?.id && prevNode) {\n // GC samples have no stack, so we just put GC node on top of the\n // last recorded sample. Cache the previous sample for future\n // reference.\n this.#nodeForGC.set(call, prevNode);\n continue;\n }\n prevNode = node;\n }\n return calls;\n }\n\n #makeProfileCallsForStack(profileCall: Types.TraceEvents.SyntheticProfileCall):\n Types.TraceEvents.SyntheticProfileCall[] {\n let node = this.#profileModel.nodeById(profileCall.nodeId);\n const isGarbageCollection = node?.id === this.#profileModel.gcNode?.id;\n if (isGarbageCollection) {\n // Because GC don't have a stack, we use the stack of the previous\n // sample.\n node = this.#nodeForGC.get(profileCall) || null;\n }\n if (!node) {\n return [];\n }\n // `node.depth` is 0 based, so to set the size of the array we need\n // to add 1 to its value.\n const callFrames = new Array<Types.TraceEvents.SyntheticProfileCall>(node.depth + 1 + Number(isGarbageCollection));\n // Add the stack trace in reverse order (bottom first).\n let i = callFrames.length - 1;\n if (isGarbageCollection) {\n // Place the garbage collection call frame on top of the stack.\n callFrames[i--] = profileCall;\n }\n\n // Many of these ProfileCalls will be GC'd later when we estimate the frame\n // durations\n while (node) {\n callFrames[i--] = makeProfileCall(\n node, profileCall.profileId, profileCall.sampleIndex, profileCall.ts, this.#processId, this.#threadId);\n node = node.parent;\n }\n return callFrames;\n }\n\n /**\n * Update tracked stack using this event's call stack.\n */\n #extractStackTrace(event: Types.TraceEvents.TraceEventData): void {\n const stackTrace =\n Types.TraceEvents.isProfileCall(event) ? this.#makeProfileCallsForStack(event) : this.#currentJSStack;\n SamplesIntegrator.filterStackFrames(stackTrace, this.#engineConfig);\n\n const endTime = event.ts + (event.dur || 0);\n const minFrames = Math.min(stackTrace.length, this.#currentJSStack.length);\n let i;\n // Merge a sample's stack frames with the stack frames we have\n // so far if we detect they are equivalent.\n // Graphically\n // This:\n // Current stack trace Sample\n // [-------A------] [A]\n // [-------B------] [B]\n // [-------C------] [C]\n // ^ t = x1 ^ t = x2\n\n // Becomes this:\n // New stack trace after merge\n // [--------A-------]\n // [--------B-------]\n // [--------C-------]\n // ^ t = x2\n for (i = this.#lockedJsStackDepth.at(-1) || 0; i < minFrames; ++i) {\n const newFrame = stackTrace[i].callFrame;\n const oldFrame = this.#currentJSStack[i].callFrame;\n if (!SamplesIntegrator.framesAreEqual(newFrame, oldFrame)) {\n break;\n }\n // Scoot the right edge of this callFrame to the right\n this.#currentJSStack[i].dur =\n Types.Timing.MicroSeconds(Math.max(this.#currentJSStack[i].dur || 0, endTime - this.#currentJSStack[i].ts));\n }\n\n // If there are call frames in the sample that differ with the stack\n // we have, update the stack, but keeping the common frames in place\n // Graphically\n // This:\n // Current stack trace Sample\n // [-------A------] [A]\n // [-------B------] [B]\n // [-------C------] [C]\n // [-------D------] [E]\n // ^ t = x1 ^ t = x2\n // Becomes this:\n // New stack trace after merge\n // [--------A-------]\n // [--------B-------]\n // [--------C-------]\n // [E]\n // ^ t = x2\n this.#truncateJSStack(i, event.ts);\n\n for (; i < stackTrace.length; ++i) {\n const call = stackTrace[i];\n if (call.nodeId === this.#profileModel.programNode?.id || call.nodeId === this.#profileModel.root?.id ||\n call.nodeId === this.#profileModel.idleNode?.id || call.nodeId === this.#profileModel.gcNode?.id) {\n // Skip (root), (program) and (idle) frames, since this are not\n // relevant for web profiling and we don't want to show them in\n // the timeline.\n continue;\n }\n this.#currentJSStack.push(call);\n this.#constructedProfileCalls.push(call);\n }\n }\n\n /**\n * When a call stack that differs from the one we are tracking has\n * been detected in the samples, the latter is \"truncated\" by\n * setting the ending time of its call frames and removing the top\n * call frames that aren't shared with the new call stack. This way,\n * we can update the tracked stack with the new call frames on top.\n * @param depth the amount of call frames from bottom to top that\n * should be kept in the tracking stack trace. AKA amount of shared\n * call frames between two stacks.\n * @param time the new end of the call frames in the stack.\n */\n #truncateJSStack(depth: number, time: Types.Timing.MicroSeconds): void {\n if (this.#lockedJsStackDepth.length) {\n const lockedDepth = this.#lockedJsStackDepth.at(-1);\n if (lockedDepth && depth < lockedDepth) {\n console.error(`Child stack is shallower (${depth}) than the parent stack (${lockedDepth}) at ${time}`);\n depth = lockedDepth;\n }\n }\n if (this.#currentJSStack.length < depth) {\n console.error(`Trying to truncate higher than the current stack size at ${time}`);\n depth = this.#currentJSStack.length;\n }\n for (let k = 0; k < this.#currentJSStack.length; ++k) {\n this.#currentJSStack[k].dur = Types.Timing.MicroSeconds(Math.max(time - this.#currentJSStack[k].ts, 0));\n }\n this.#currentJSStack.length = depth;\n }\n\n #makeJSSampleEvent(call: Types.TraceEvents.SyntheticProfileCall, timestamp: Types.Timing.MicroSeconds):\n Types.TraceEvents.SyntheticJSSample {\n const JSSampleEvent: Types.TraceEvents.SyntheticJSSample = {\n name: Types.TraceEvents.KnownEventName.JSSample,\n cat: 'devtools.timeline',\n args: {\n data: {stackTrace: this.#makeProfileCallsForStack(call).map(e => e.callFrame)},\n },\n ph: Types.TraceEvents.Phase.INSTANT,\n ts: timestamp,\n dur: Types.Timing.MicroSeconds(0),\n pid: this.#processId,\n tid: this.#threadId,\n };\n return JSSampleEvent;\n }\n\n static framesAreEqual(frame1: Protocol.Runtime.CallFrame, frame2: Protocol.Runtime.CallFrame): boolean {\n return frame1.scriptId === frame2.scriptId && frame1.functionName === frame2.functionName &&\n frame1.lineNumber === frame2.lineNumber;\n }\n\n static showNativeName(name: string, runtimeCallStatsEnabled: boolean): boolean {\n return runtimeCallStatsEnabled && Boolean(SamplesIntegrator.nativeGroup(name));\n }\n\n static nativeGroup(nativeName: string): 'Parse'|'Compile'|null {\n if (nativeName.startsWith('Parse')) {\n return 'Parse';\n }\n if (nativeName.startsWith('Compile') || nativeName.startsWith('Recompile')) {\n return 'Compile';\n }\n return null;\n }\n\n static isNativeRuntimeFrame(frame: Protocol.Runtime.CallFrame): boolean {\n return frame.url === 'native V8Runtime';\n }\n\n static filterStackFrames(\n stack: Types.TraceEvents.SyntheticProfileCall[], engineConfig: Types.Configuration.Configuration): void {\n const showAllEvents = engineConfig.showAllEvents;\n if (showAllEvents) {\n return;\n }\n let previousNativeFrameName: string|null = null;\n let j = 0;\n for (let i = 0; i < stack.length; ++i) {\n const frame = stack[i].callFrame;\n const nativeRuntimeFrame = SamplesIntegrator.isNativeRuntimeFrame(frame);\n if (nativeRuntimeFrame &&\n !SamplesIntegrator.showNativeName(frame.functionName, engineConfig.includeRuntimeCallStats)) {\n continue;\n }\n const nativeFrameName = nativeRuntimeFrame ? SamplesIntegrator.nativeGroup(frame.functionName) : null;\n if (previousNativeFrameName && previousNativeFrameName === nativeFrameName) {\n continue;\n }\n previousNativeFrameName = nativeFrameName;\n stack[j++] = stack[i];\n }\n stack.length = j;\n }\n}\n"]}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import type * as CPUProfile from '../../cpu_profile/cpu_profile.js';
|
|
2
2
|
import * as Types from '../types/types.js';
|
|
3
3
|
type MatchedPairType<T extends Types.TraceEvents.TraceEventPairableAsync> = Types.TraceEvents.SyntheticEventPair<T>;
|
|
4
|
-
|
|
4
|
+
type MatchingPairableAsyncEvents = {
|
|
5
|
+
begin: Types.TraceEvents.TraceEventPairableAsyncBegin | null;
|
|
6
|
+
end: Types.TraceEvents.TraceEventPairableAsyncEnd | null;
|
|
7
|
+
instant?: Types.TraceEvents.TraceEventPairableAsyncInstant[];
|
|
8
|
+
};
|
|
5
9
|
export declare function extractOriginFromTrace(firstNavigationURL: string): string | null;
|
|
6
10
|
export type EventsInThread<T extends Types.TraceEvents.TraceEventData> = Map<Types.TraceEvents.ThreadID, T[]>;
|
|
7
11
|
export declare function addEventToProcessThread<T extends Types.TraceEvents.TraceEventData>(event: T, eventsInProcessThread: Map<Types.TraceEvents.ProcessID, EventsInThread<T>>): void;
|
|
12
|
+
type TimeSpan = {
|
|
13
|
+
ts: Types.Timing.MicroSeconds;
|
|
14
|
+
dur?: Types.Timing.MicroSeconds;
|
|
15
|
+
};
|
|
16
|
+
export declare function eventTimeComparator(a: TimeSpan, b: TimeSpan): -1 | 0 | 1;
|
|
8
17
|
/**
|
|
9
18
|
* Sorts all the events in place, in order, by their start time. If they have
|
|
10
19
|
* the same start time, orders them by longest first.
|
|
@@ -24,15 +33,30 @@ export declare function activeURLForFrameAtTime(frameId: string, time: Types.Tim
|
|
|
24
33
|
frame: Types.TraceEvents.TraceFrame;
|
|
25
34
|
window: Types.Timing.TraceWindowMicroSeconds;
|
|
26
35
|
}[]>>): string | null;
|
|
27
|
-
|
|
36
|
+
/**
|
|
37
|
+
* @param node the node attached to the profile call. Here a node represents a function in the call tree.
|
|
38
|
+
* @param profileId the profile ID that the sample came from that backs this call.
|
|
39
|
+
* @param sampleIndex the index of the sample in the given profile that this call was created from
|
|
40
|
+
* @param ts the timestamp of the profile call
|
|
41
|
+
* @param pid the process ID of the profile call
|
|
42
|
+
* @param tid the thread ID of the profile call
|
|
43
|
+
*
|
|
44
|
+
* See `panels/timeline/docs/profile_calls.md` for more context on how these events are created.
|
|
45
|
+
*/
|
|
46
|
+
export declare function makeProfileCall(node: CPUProfile.ProfileTreeModel.ProfileNode, profileId: Types.TraceEvents.ProfileID, sampleIndex: number, ts: Types.Timing.MicroSeconds, pid: Types.TraceEvents.ProcessID, tid: Types.TraceEvents.ThreadID): Types.TraceEvents.SyntheticProfileCall;
|
|
28
47
|
export declare function makeSyntheticTraceEntry(name: string, ts: Types.Timing.MicroSeconds, pid: Types.TraceEvents.ProcessID, tid: Types.TraceEvents.ThreadID): Types.TraceEvents.SyntheticTraceEntry;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Matches beginning events with TraceEventPairableAsyncEnd and TraceEventPairableAsyncInstant (ASYNC_NESTABLE_INSTANT)
|
|
50
|
+
* if provided, though currently only coming from Animations. Traces may contain multiple instant events so we need to
|
|
51
|
+
* account for that.
|
|
52
|
+
*
|
|
53
|
+
* @returns {Map<string, MatchingPairableAsyncEvents>} Map of the animation's ID to it's matching events.
|
|
54
|
+
*/
|
|
55
|
+
export declare function matchEvents(unpairedEvents: Types.TraceEvents.TraceEventPairableAsync[]): Map<string, MatchingPairableAsyncEvents>;
|
|
33
56
|
export declare function createSortedSyntheticEvents<T extends Types.TraceEvents.TraceEventPairableAsync>(matchedPairs: Map<string, {
|
|
34
57
|
begin: Types.TraceEvents.TraceEventPairableAsyncBegin | null;
|
|
35
58
|
end: Types.TraceEvents.TraceEventPairableAsyncEnd | null;
|
|
59
|
+
instant?: Types.TraceEvents.TraceEventPairableAsyncInstant[];
|
|
36
60
|
}>, syntheticEventCallback?: (syntheticEvent: MatchedPairType<T>) => void): MatchedPairType<T>[];
|
|
37
61
|
export declare function createMatchedSortedSyntheticEvents<T extends Types.TraceEvents.TraceEventPairableAsync>(unpairedAsyncEvents: T[], syntheticEventCallback?: (syntheticEvent: MatchedPairType<T>) => void): MatchedPairType<T>[];
|
|
38
62
|
/**
|
|
@@ -40,10 +64,59 @@ export declare function createMatchedSortedSyntheticEvents<T extends Types.Trace
|
|
|
40
64
|
* This function knows which events return 1 indexed numbers and normalizes
|
|
41
65
|
* them. The UI expects 0 indexed line numbers, so that is what we return.
|
|
42
66
|
*/
|
|
43
|
-
export declare function
|
|
67
|
+
export declare function getZeroIndexedLineAndColumnForEvent(event: Types.TraceEvents.TraceEventData): {
|
|
44
68
|
lineNumber?: number;
|
|
45
69
|
columnNumber?: number;
|
|
46
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* Different trace events contain stack traces with line/column numbers
|
|
73
|
+
* that are 1 or 0 indexed.
|
|
74
|
+
* This function knows which events return 1 indexed numbers and normalizes
|
|
75
|
+
* them. The UI expects 0 indexed line numbers, so that is what we return.
|
|
76
|
+
*/
|
|
77
|
+
export declare function getZeroIndexedStackTraceForEvent(event: Types.TraceEvents.TraceEventData): Types.TraceEvents.TraceEventCallFrame[] | null;
|
|
47
78
|
export declare function frameIDForEvent(event: Types.TraceEvents.TraceEventData): string | null;
|
|
79
|
+
export declare function isTopLevelEvent(event: Types.TraceEvents.TraceEventData): boolean;
|
|
48
80
|
export declare function findUpdateLayoutTreeEvents(events: Types.TraceEvents.TraceEventData[], startTime: Types.Timing.MicroSeconds, endTime?: Types.Timing.MicroSeconds): Types.TraceEvents.TraceEventUpdateLayoutTree[];
|
|
81
|
+
export interface ForEachEventConfig {
|
|
82
|
+
onStartEvent: (event: Types.TraceEvents.TraceEventData) => void;
|
|
83
|
+
onEndEvent: (event: Types.TraceEvents.TraceEventData) => void;
|
|
84
|
+
onInstantEvent?: (event: Types.TraceEvents.TraceEventData) => void;
|
|
85
|
+
eventFilter?: (event: Types.TraceEvents.TraceEventData) => boolean;
|
|
86
|
+
startTime?: Types.Timing.MicroSeconds;
|
|
87
|
+
endTime?: Types.Timing.MicroSeconds;
|
|
88
|
+
ignoreAsyncEvents?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Iterates events in a tree hierarchically, from top to bottom,
|
|
92
|
+
* calling back on every event's start and end in the order
|
|
93
|
+
* dictated by the corresponding timestamp.
|
|
94
|
+
*
|
|
95
|
+
* Events are assumed to be in ascendent order by timestamp.
|
|
96
|
+
*
|
|
97
|
+
* Events with 0 duration are treated as instant events. These do not have a
|
|
98
|
+
* begin and end, but will be passed to the config.onInstantEvent callback as
|
|
99
|
+
* they are discovered. Do not provide this callback if you are not interested
|
|
100
|
+
* in them.
|
|
101
|
+
*
|
|
102
|
+
* For example, given this tree, the following callbacks
|
|
103
|
+
* are expected to be made in the following order
|
|
104
|
+
* |---------------A---------------|
|
|
105
|
+
* |------B------||-------D------|
|
|
106
|
+
* |---C---|
|
|
107
|
+
*
|
|
108
|
+
* 1. Start A
|
|
109
|
+
* 3. Start B
|
|
110
|
+
* 4. Start C
|
|
111
|
+
* 5. End C
|
|
112
|
+
* 6. End B
|
|
113
|
+
* 7. Start D
|
|
114
|
+
* 8. End D
|
|
115
|
+
* 9. End A
|
|
116
|
+
*
|
|
117
|
+
* By default, async events are skipped. This behaviour can be
|
|
118
|
+
* overriden making use of the config.ignoreAsyncEvents parameter.
|
|
119
|
+
*/
|
|
120
|
+
export declare function forEachEvent(events: Types.TraceEvents.TraceEventData[], config: ForEachEventConfig): void;
|
|
121
|
+
export declare function eventHasCategory(event: Types.TraceEvents.TraceEventData, category: string): boolean;
|
|
49
122
|
export {};
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
// found in the LICENSE file.
|
|
4
4
|
import * as Platform from '../../../core/platform/platform.js';
|
|
5
5
|
import * as Types from '../types/types.js';
|
|
6
|
-
|
|
6
|
+
import { eventTimingsMicroSeconds } from './Timing.js';
|
|
7
|
+
/**
|
|
8
|
+
* Extracts the raw stack trace of known trace events. Most likely than
|
|
9
|
+
* not you want to use `getZeroIndexedStackTraceForEvent`, which returns
|
|
10
|
+
* the stack with zero based numbering. Since some trace events are
|
|
11
|
+
* one based this function can yield unexpected results when used
|
|
12
|
+
* indiscriminately.
|
|
13
|
+
*/
|
|
14
|
+
function stackTraceForEvent(event) {
|
|
7
15
|
if (Types.TraceEvents.isSyntheticInvalidation(event)) {
|
|
8
16
|
return event.stackTrace || null;
|
|
9
17
|
}
|
|
@@ -43,7 +51,7 @@ export function addEventToProcessThread(event, eventsInProcessThread) {
|
|
|
43
51
|
eventsInThread.set(event.tid, events);
|
|
44
52
|
eventsInProcessThread.set(event.pid, eventsInThread);
|
|
45
53
|
}
|
|
46
|
-
function eventTimeComparator(a, b) {
|
|
54
|
+
export function eventTimeComparator(a, b) {
|
|
47
55
|
const aBeginTime = a.ts;
|
|
48
56
|
const bBeginTime = b.ts;
|
|
49
57
|
if (aBeginTime < bBeginTime) {
|
|
@@ -132,7 +140,17 @@ export function activeURLForFrameAtTime(frameId, time, rendererProcessesByFrame)
|
|
|
132
140
|
}
|
|
133
141
|
return null;
|
|
134
142
|
}
|
|
135
|
-
|
|
143
|
+
/**
|
|
144
|
+
* @param node the node attached to the profile call. Here a node represents a function in the call tree.
|
|
145
|
+
* @param profileId the profile ID that the sample came from that backs this call.
|
|
146
|
+
* @param sampleIndex the index of the sample in the given profile that this call was created from
|
|
147
|
+
* @param ts the timestamp of the profile call
|
|
148
|
+
* @param pid the process ID of the profile call
|
|
149
|
+
* @param tid the thread ID of the profile call
|
|
150
|
+
*
|
|
151
|
+
* See `panels/timeline/docs/profile_calls.md` for more context on how these events are created.
|
|
152
|
+
*/
|
|
153
|
+
export function makeProfileCall(node, profileId, sampleIndex, ts, pid, tid) {
|
|
136
154
|
return {
|
|
137
155
|
cat: '',
|
|
138
156
|
name: 'ProfileCall',
|
|
@@ -145,6 +163,8 @@ export function makeProfileCall(node, ts, pid, tid) {
|
|
|
145
163
|
dur: Types.Timing.MicroSeconds(0),
|
|
146
164
|
selfTime: Types.Timing.MicroSeconds(0),
|
|
147
165
|
callFrame: node.callFrame,
|
|
166
|
+
sampleIndex,
|
|
167
|
+
profileId,
|
|
148
168
|
};
|
|
149
169
|
}
|
|
150
170
|
export function makeSyntheticTraceEntry(name, ts, pid, tid) {
|
|
@@ -160,7 +180,14 @@ export function makeSyntheticTraceEntry(name, ts, pid, tid) {
|
|
|
160
180
|
selfTime: Types.Timing.MicroSeconds(0),
|
|
161
181
|
};
|
|
162
182
|
}
|
|
163
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Matches beginning events with TraceEventPairableAsyncEnd and TraceEventPairableAsyncInstant (ASYNC_NESTABLE_INSTANT)
|
|
185
|
+
* if provided, though currently only coming from Animations. Traces may contain multiple instant events so we need to
|
|
186
|
+
* account for that.
|
|
187
|
+
*
|
|
188
|
+
* @returns {Map<string, MatchingPairableAsyncEvents>} Map of the animation's ID to it's matching events.
|
|
189
|
+
*/
|
|
190
|
+
export function matchEvents(unpairedEvents) {
|
|
164
191
|
// map to store begin and end of the event
|
|
165
192
|
const matchedPairs = new Map();
|
|
166
193
|
// looking for start and end
|
|
@@ -173,16 +200,23 @@ export function matchBeginningAndEndEvents(unpairedEvents) {
|
|
|
173
200
|
// Console timings can be dispatched with the same id, so use the
|
|
174
201
|
// event name as well to generate unique ids.
|
|
175
202
|
const otherEventsWithID = Platform.MapUtilities.getWithDefault(matchedPairs, syntheticId, () => {
|
|
176
|
-
return { begin: null, end: null };
|
|
203
|
+
return { begin: null, end: null, instant: [] };
|
|
177
204
|
});
|
|
178
205
|
const isStartEvent = event.ph === "b" /* Types.TraceEvents.Phase.ASYNC_NESTABLE_START */;
|
|
179
206
|
const isEndEvent = event.ph === "e" /* Types.TraceEvents.Phase.ASYNC_NESTABLE_END */;
|
|
207
|
+
const isInstantEvent = event.ph === "n" /* Types.TraceEvents.Phase.ASYNC_NESTABLE_INSTANT */;
|
|
180
208
|
if (isStartEvent) {
|
|
181
209
|
otherEventsWithID.begin = event;
|
|
182
210
|
}
|
|
183
211
|
else if (isEndEvent) {
|
|
184
212
|
otherEventsWithID.end = event;
|
|
185
213
|
}
|
|
214
|
+
else if (isInstantEvent) {
|
|
215
|
+
if (!otherEventsWithID.instant) {
|
|
216
|
+
otherEventsWithID.instant = [];
|
|
217
|
+
}
|
|
218
|
+
otherEventsWithID.instant.push(event);
|
|
219
|
+
}
|
|
186
220
|
}
|
|
187
221
|
return matchedPairs;
|
|
188
222
|
}
|
|
@@ -192,36 +226,45 @@ function getSyntheticId(event) {
|
|
|
192
226
|
}
|
|
193
227
|
export function createSortedSyntheticEvents(matchedPairs, syntheticEventCallback) {
|
|
194
228
|
const syntheticEvents = [];
|
|
195
|
-
for (const [id,
|
|
196
|
-
const beginEvent =
|
|
197
|
-
const endEvent =
|
|
198
|
-
|
|
229
|
+
for (const [id, eventsTriplet] of matchedPairs.entries()) {
|
|
230
|
+
const beginEvent = eventsTriplet.begin;
|
|
231
|
+
const endEvent = eventsTriplet.end;
|
|
232
|
+
const instantEvents = eventsTriplet.instant;
|
|
233
|
+
if (!beginEvent || !(endEvent || instantEvents)) {
|
|
199
234
|
// This should never happen, the backend only creates the events once it
|
|
200
|
-
// has them both, so we should never get into this state.
|
|
235
|
+
// has them both (beginEvent & endEvent/instantEvents), so we should never get into this state.
|
|
201
236
|
// If we do, something is very wrong, so let's just drop that problematic event.
|
|
202
237
|
continue;
|
|
203
238
|
}
|
|
204
|
-
const
|
|
239
|
+
const triplet = { beginEvent, endEvent, instantEvents };
|
|
240
|
+
/**
|
|
241
|
+
* When trying to pair events with instant events present, there are times when these
|
|
242
|
+
* ASYNC_NESTABLE_INSTANT ('n') don't have a corresponding ASYNC_NESTABLE_END ('e') event.
|
|
243
|
+
* In these cases, pair without needing the endEvent.
|
|
244
|
+
*/
|
|
205
245
|
function eventsArePairable(data) {
|
|
206
|
-
|
|
207
|
-
|
|
246
|
+
const instantEventsMatch = data.instantEvents ? data.instantEvents.some(e => id === getSyntheticId(e)) : false;
|
|
247
|
+
const endEventMatch = data.endEvent ? id === getSyntheticId(data.endEvent) : false;
|
|
248
|
+
return Boolean(id) && (instantEventsMatch || endEventMatch);
|
|
208
249
|
}
|
|
209
|
-
if (!eventsArePairable(
|
|
250
|
+
if (!eventsArePairable(triplet)) {
|
|
210
251
|
continue;
|
|
211
252
|
}
|
|
253
|
+
const targetEvent = endEvent || beginEvent;
|
|
212
254
|
const event = {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
255
|
+
rawSourceEvent: beginEvent,
|
|
256
|
+
cat: targetEvent.cat,
|
|
257
|
+
ph: targetEvent.ph,
|
|
258
|
+
pid: targetEvent.pid,
|
|
259
|
+
tid: targetEvent.tid,
|
|
217
260
|
id,
|
|
218
261
|
// Both events have the same name, so it doesn't matter which we pick to
|
|
219
262
|
// use as the description
|
|
220
263
|
name: beginEvent.name,
|
|
221
|
-
dur: Types.Timing.MicroSeconds(
|
|
264
|
+
dur: Types.Timing.MicroSeconds(targetEvent.ts - beginEvent.ts),
|
|
222
265
|
ts: beginEvent.ts,
|
|
223
266
|
args: {
|
|
224
|
-
data:
|
|
267
|
+
data: triplet,
|
|
225
268
|
},
|
|
226
269
|
};
|
|
227
270
|
if (event.dur < 0) {
|
|
@@ -237,7 +280,7 @@ export function createSortedSyntheticEvents(matchedPairs, syntheticEventCallback
|
|
|
237
280
|
return syntheticEvents.sort((a, b) => a.ts - b.ts);
|
|
238
281
|
}
|
|
239
282
|
export function createMatchedSortedSyntheticEvents(unpairedAsyncEvents, syntheticEventCallback) {
|
|
240
|
-
const matchedPairs =
|
|
283
|
+
const matchedPairs = matchEvents(unpairedAsyncEvents);
|
|
241
284
|
const syntheticEvents = createSortedSyntheticEvents(matchedPairs, syntheticEventCallback);
|
|
242
285
|
return syntheticEvents;
|
|
243
286
|
}
|
|
@@ -246,7 +289,7 @@ export function createMatchedSortedSyntheticEvents(unpairedAsyncEvents, syntheti
|
|
|
246
289
|
* This function knows which events return 1 indexed numbers and normalizes
|
|
247
290
|
* them. The UI expects 0 indexed line numbers, so that is what we return.
|
|
248
291
|
*/
|
|
249
|
-
export function
|
|
292
|
+
export function getZeroIndexedLineAndColumnForEvent(event) {
|
|
250
293
|
// Some events emit line numbers that are 1 indexed, but the UI layer expects
|
|
251
294
|
// numbers to be 0 indexed. So here, if the event matches a known 1-indexed
|
|
252
295
|
// number event, we subtract one from the line and column numbers.
|
|
@@ -271,6 +314,30 @@ export function getZeroIndexedLineAndColumnNumbersForEvent(event) {
|
|
|
271
314
|
}
|
|
272
315
|
}
|
|
273
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Different trace events contain stack traces with line/column numbers
|
|
319
|
+
* that are 1 or 0 indexed.
|
|
320
|
+
* This function knows which events return 1 indexed numbers and normalizes
|
|
321
|
+
* them. The UI expects 0 indexed line numbers, so that is what we return.
|
|
322
|
+
*/
|
|
323
|
+
export function getZeroIndexedStackTraceForEvent(event) {
|
|
324
|
+
const stack = stackTraceForEvent(event);
|
|
325
|
+
if (!stack) {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
return stack.map(callFrame => {
|
|
329
|
+
const normalizedCallFrame = { ...callFrame };
|
|
330
|
+
switch (event.name) {
|
|
331
|
+
case "ScheduleStyleRecalculation" /* Types.TraceEvents.KnownEventName.ScheduleStyleRecalculation */:
|
|
332
|
+
case "InvalidateLayout" /* Types.TraceEvents.KnownEventName.InvalidateLayout */:
|
|
333
|
+
case "UpdateLayoutTree" /* Types.TraceEvents.KnownEventName.UpdateLayoutTree */: {
|
|
334
|
+
normalizedCallFrame.lineNumber = callFrame.lineNumber && callFrame.lineNumber - 1;
|
|
335
|
+
normalizedCallFrame.columnNumber = callFrame.columnNumber && callFrame.columnNumber - 1;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return normalizedCallFrame;
|
|
339
|
+
});
|
|
340
|
+
}
|
|
274
341
|
/**
|
|
275
342
|
* NOTE: you probably do not want this function! (Which is why it is not exported).
|
|
276
343
|
*
|
|
@@ -278,7 +345,7 @@ export function getZeroIndexedLineAndColumnNumbersForEvent(event) {
|
|
|
278
345
|
* indexed. This function does NOT normalize them, but
|
|
279
346
|
* `getZeroIndexedLineAndColumnNumbersForEvent` does. It is best to use that!
|
|
280
347
|
*
|
|
281
|
-
* @see {@link
|
|
348
|
+
* @see {@link getZeroIndexedLineAndColumnForEvent}
|
|
282
349
|
**/
|
|
283
350
|
function getRawLineAndColumnNumbersForEvent(event) {
|
|
284
351
|
if (!event.args?.data) {
|
|
@@ -317,7 +384,14 @@ export function frameIDForEvent(event) {
|
|
|
317
384
|
return null;
|
|
318
385
|
}
|
|
319
386
|
const DevToolsTimelineEventCategory = 'disabled-by-default-devtools.timeline';
|
|
320
|
-
function isTopLevelEvent(event) {
|
|
387
|
+
export function isTopLevelEvent(event) {
|
|
388
|
+
if (event.name === 'JSRoot' && event.cat === 'toplevel') {
|
|
389
|
+
// This is used in TimelineJSProfile to insert a fake event prior to the
|
|
390
|
+
// CPU Profile in order to ensure the trace isn't truncated. So if we see
|
|
391
|
+
// this, we want to treat it as a top level event.
|
|
392
|
+
// TODO(crbug.com/341234884): do we need this?
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
321
395
|
return event.cat.includes(DevToolsTimelineEventCategory) && event.name === "RunTask" /* Types.TraceEvents.KnownEventName.RunTask */;
|
|
322
396
|
}
|
|
323
397
|
function topLevelEventIndexEndingAfter(events, time) {
|
|
@@ -342,4 +416,96 @@ export function findUpdateLayoutTreeEvents(events, startTime, endTime) {
|
|
|
342
416
|
}
|
|
343
417
|
return foundEvents;
|
|
344
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Iterates events in a tree hierarchically, from top to bottom,
|
|
421
|
+
* calling back on every event's start and end in the order
|
|
422
|
+
* dictated by the corresponding timestamp.
|
|
423
|
+
*
|
|
424
|
+
* Events are assumed to be in ascendent order by timestamp.
|
|
425
|
+
*
|
|
426
|
+
* Events with 0 duration are treated as instant events. These do not have a
|
|
427
|
+
* begin and end, but will be passed to the config.onInstantEvent callback as
|
|
428
|
+
* they are discovered. Do not provide this callback if you are not interested
|
|
429
|
+
* in them.
|
|
430
|
+
*
|
|
431
|
+
* For example, given this tree, the following callbacks
|
|
432
|
+
* are expected to be made in the following order
|
|
433
|
+
* |---------------A---------------|
|
|
434
|
+
* |------B------||-------D------|
|
|
435
|
+
* |---C---|
|
|
436
|
+
*
|
|
437
|
+
* 1. Start A
|
|
438
|
+
* 3. Start B
|
|
439
|
+
* 4. Start C
|
|
440
|
+
* 5. End C
|
|
441
|
+
* 6. End B
|
|
442
|
+
* 7. Start D
|
|
443
|
+
* 8. End D
|
|
444
|
+
* 9. End A
|
|
445
|
+
*
|
|
446
|
+
* By default, async events are skipped. This behaviour can be
|
|
447
|
+
* overriden making use of the config.ignoreAsyncEvents parameter.
|
|
448
|
+
*/
|
|
449
|
+
export function forEachEvent(events, config) {
|
|
450
|
+
const globalStartTime = config.startTime || Types.Timing.MicroSeconds(0);
|
|
451
|
+
const globalEndTime = config.endTime || Types.Timing.MicroSeconds(Infinity);
|
|
452
|
+
const ignoreAsyncEvents = config.ignoreAsyncEvents === false ? false : true;
|
|
453
|
+
const stack = [];
|
|
454
|
+
const startEventIndex = topLevelEventIndexEndingAfter(events, globalStartTime);
|
|
455
|
+
for (let i = startEventIndex; i < events.length; i++) {
|
|
456
|
+
const currentEvent = events[i];
|
|
457
|
+
const currentEventTimings = eventTimingsMicroSeconds(currentEvent);
|
|
458
|
+
if (currentEventTimings.endTime < globalStartTime) {
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
if (currentEventTimings.startTime > globalEndTime) {
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
const isIgnoredAsyncEvent = ignoreAsyncEvents && Types.TraceEvents.isAsyncPhase(currentEvent.ph);
|
|
465
|
+
if (isIgnoredAsyncEvent || Types.TraceEvents.isFlowPhase(currentEvent.ph)) {
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
// If we have now reached an event that is after a bunch of events, we need
|
|
469
|
+
// to call the onEndEvent callback for those events before moving on.
|
|
470
|
+
let lastEventOnStack = stack.at(-1);
|
|
471
|
+
let lastEventEndTime = lastEventOnStack ? eventTimingsMicroSeconds(lastEventOnStack).endTime : null;
|
|
472
|
+
while (lastEventOnStack && lastEventEndTime && lastEventEndTime <= currentEventTimings.startTime) {
|
|
473
|
+
stack.pop();
|
|
474
|
+
config.onEndEvent(lastEventOnStack);
|
|
475
|
+
lastEventOnStack = stack.at(-1);
|
|
476
|
+
lastEventEndTime = lastEventOnStack ? eventTimingsMicroSeconds(lastEventOnStack).endTime : null;
|
|
477
|
+
}
|
|
478
|
+
// Now we have dealt with all events prior to this one, see if we need to care about this one.
|
|
479
|
+
if (config.eventFilter && !config.eventFilter(currentEvent)) {
|
|
480
|
+
// The user has chosen to filter this event out, so continue on and do nothing
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
if (currentEventTimings.duration) {
|
|
484
|
+
config.onStartEvent(currentEvent);
|
|
485
|
+
stack.push(currentEvent);
|
|
486
|
+
}
|
|
487
|
+
else if (config.onInstantEvent) {
|
|
488
|
+
// An event with 0 duration is an instant event.
|
|
489
|
+
config.onInstantEvent(currentEvent);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
// Now we have finished looping over all events; any events remaining on the
|
|
493
|
+
// stack need to have their onEndEvent called.
|
|
494
|
+
while (stack.length) {
|
|
495
|
+
const last = stack.pop();
|
|
496
|
+
if (last) {
|
|
497
|
+
config.onEndEvent(last);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
// Parsed categories are cached to prevent calling cat.split()
|
|
502
|
+
// multiple times on the same categories string.
|
|
503
|
+
const parsedCategories = new Map();
|
|
504
|
+
export function eventHasCategory(event, category) {
|
|
505
|
+
let parsedCategoriesForEvent = parsedCategories.get(event.cat);
|
|
506
|
+
if (!parsedCategoriesForEvent) {
|
|
507
|
+
parsedCategoriesForEvent = new Set(event.cat.split(',') || []);
|
|
508
|
+
}
|
|
509
|
+
return parsedCategoriesForEvent.has(category);
|
|
510
|
+
}
|
|
345
511
|
//# sourceMappingURL=Trace.js.map
|