From b3ec084257db72534c5c999a1ae655cfeecd6e0a Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Tue, 31 Dec 2024 16:15:36 +0100 Subject: [PATCH 1/2] Use push instead of concat. This saves one level of indentation and feels more straightforward to me these days. --- src/profile-logic/process-profile.js | 80 ++++++++++++++-------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/src/profile-logic/process-profile.js b/src/profile-logic/process-profile.js index eb457b20a5..077b5b864f 100644 --- a/src/profile-logic/process-profile.js +++ b/src/profile-logic/process-profile.js @@ -1532,7 +1532,7 @@ export function processGeckoProfile(geckoProfile: GeckoProfile): Profile { // exception. upgradeGeckoProfileToCurrentVersion(geckoProfile); - let threads = []; + const threads = []; const extensions: ExtensionTable = geckoProfile.meta.extensions ? _toStructOfArrays(geckoProfile.meta.extensions) @@ -1553,51 +1553,49 @@ export function processGeckoProfile(geckoProfile: GeckoProfile): Profile { for (const subprocessProfile of geckoProfile.processes) { const adjustTimestampsBy = subprocessProfile.meta.startTime - geckoProfile.meta.startTime; - threads = threads.concat( - subprocessProfile.threads.map((thread) => { - const newThread: Thread = _processThread( - thread, - subprocessProfile, - extensions, - globalDataCollector + for (const thread of subprocessProfile.threads) { + const newThread: Thread = _processThread( + thread, + subprocessProfile, + extensions, + globalDataCollector + ); + newThread.samples = adjustTableTimestamps( + newThread.samples, + adjustTimestampsBy + ); + newThread.markers = adjustMarkerTimestamps( + newThread.markers, + adjustTimestampsBy + ); + if (newThread.jsTracer) { + newThread.jsTracer = _adjustJsTracerTimestamps( + newThread.jsTracer, + adjustTimestampsBy ); - newThread.samples = adjustTableTimestamps( - newThread.samples, + } + if (newThread.jsAllocations) { + newThread.jsAllocations = adjustTableTimestamps( + newThread.jsAllocations, adjustTimestampsBy ); - newThread.markers = adjustMarkerTimestamps( - newThread.markers, + } + if (newThread.nativeAllocations) { + newThread.nativeAllocations = adjustTableTimestamps( + newThread.nativeAllocations, adjustTimestampsBy ); - if (newThread.jsTracer) { - newThread.jsTracer = _adjustJsTracerTimestamps( - newThread.jsTracer, - adjustTimestampsBy - ); - } - if (newThread.jsAllocations) { - newThread.jsAllocations = adjustTableTimestamps( - newThread.jsAllocations, - adjustTimestampsBy - ); - } - if (newThread.nativeAllocations) { - newThread.nativeAllocations = adjustTableTimestamps( - newThread.nativeAllocations, - adjustTimestampsBy - ); - } - newThread.processStartupTime += adjustTimestampsBy; - if (newThread.processShutdownTime !== null) { - newThread.processShutdownTime += adjustTimestampsBy; - } - newThread.registerTime += adjustTimestampsBy; - if (newThread.unregisterTime !== null) { - newThread.unregisterTime += adjustTimestampsBy; - } - return newThread; - }) - ); + } + newThread.processStartupTime += adjustTimestampsBy; + if (newThread.processShutdownTime !== null) { + newThread.processShutdownTime += adjustTimestampsBy; + } + newThread.registerTime += adjustTimestampsBy; + if (newThread.unregisterTime !== null) { + newThread.unregisterTime += adjustTimestampsBy; + } + threads.push(newThread); + } counters.push( ..._processCounters(subprocessProfile, threads, adjustTimestampsBy) From 2ba48d9de3704527c4f417fb40655b4078fbdd33 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Tue, 31 Dec 2024 16:47:01 +0100 Subject: [PATCH 2/2] Factor out the definition of the ProcessType type. --- src/types/profile.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/types/profile.js b/src/types/profile.js index 99bb0dba7f..03bfe096ab 100644 --- a/src/types/profile.js +++ b/src/types/profile.js @@ -617,26 +617,28 @@ export type ProfilerOverhead = {| mainThreadIndex: ThreadIndex, |}; +// This list of process types is defined here: +// https://searchfox.org/mozilla-central/rev/819cd31a93fd50b7167979607371878c4d6f18e8/xpcom/build/nsXULAppAPI.h#383 +export type ProcessType = + | 'default' + | 'plugin' + | 'tab' + | 'ipdlunittest' + | 'geckomediaplugin' + | 'gpu' + | 'pdfium' + | 'vr' + // Unknown process type: + // https://searchfox.org/mozilla-central/rev/819cd31a93fd50b7167979607371878c4d6f18e8/toolkit/xre/nsEmbedFunctions.cpp#232 + | 'invalid' + | string; + /** * Gecko has one or more processes. There can be multiple threads per processes. Each * thread has a unique set of tables for its data. */ export type Thread = {| - // This list of process types is defined here: - // https://searchfox.org/mozilla-central/rev/819cd31a93fd50b7167979607371878c4d6f18e8/xpcom/build/nsXULAppAPI.h#383 - processType: - | 'default' - | 'plugin' - | 'tab' - | 'ipdlunittest' - | 'geckomediaplugin' - | 'gpu' - | 'pdfium' - | 'vr' - // Unknown process type: - // https://searchfox.org/mozilla-central/rev/819cd31a93fd50b7167979607371878c4d6f18e8/toolkit/xre/nsEmbedFunctions.cpp#232 - | 'invalid' - | string, + processType: ProcessType, processStartupTime: Milliseconds, processShutdownTime: Milliseconds | null, registerTime: Milliseconds,