From 4043fab1dcf679b7d2613ccace0282eb3a7ad076 Mon Sep 17 00:00:00 2001 From: Lalit Maganti Date: Mon, 4 Nov 2024 16:45:30 +0000 Subject: [PATCH] ui: move TraceSource back into core There's no need for it to be exposed to plugins, exposing it also requires exposing StateSerializationSchema which is just confusing. Change-Id: Ib36b6cec0220c56fcd0a510ad2113f3ff20e5e32 --- ui/src/common/state.ts | 2 +- ui/src/core/app_impl.ts | 4 ++-- ui/src/core/cache_manager.ts | 2 +- ui/src/core/fake_trace_impl.ts | 4 ++-- ui/src/core/load_trace.ts | 8 ++++---- ui/src/core/state_serialization.ts | 2 +- .../state_serialization_schema.ts | 0 ui/src/core/trace_impl.ts | 10 +++++----- ui/src/core/trace_info_impl.ts | 20 +++++++++++++++++++ ui/src/{public => core}/trace_source.ts | 0 ui/src/frontend/permalink.ts | 2 +- ui/src/frontend/post_message_handler.ts | 2 +- ui/src/frontend/sidebar.ts | 7 ++++--- ui/src/frontend/trace_share_utils.ts | 5 +++-- ui/src/public/trace_info.ts | 3 --- 15 files changed, 45 insertions(+), 26 deletions(-) rename ui/src/{public => core}/state_serialization_schema.ts (100%) create mode 100644 ui/src/core/trace_info_impl.ts rename ui/src/{public => core}/trace_source.ts (100%) diff --git a/ui/src/common/state.ts b/ui/src/common/state.ts index 4d45311d76..39f9c5b15e 100644 --- a/ui/src/common/state.ts +++ b/ui/src/common/state.ts @@ -13,7 +13,7 @@ // limitations under the License. import {RecordConfig} from '../controller/record_config_types'; -import {TraceSource} from '../public/trace_source'; +import {TraceSource} from '../core/trace_source'; /** * A plain js object, holding objects of type |Class| keyed by string id. diff --git a/ui/src/core/app_impl.ts b/ui/src/core/app_impl.ts index 097211a8fc..0779457a2d 100644 --- a/ui/src/core/app_impl.ts +++ b/ui/src/core/app_impl.ts @@ -23,8 +23,8 @@ import {PluginManagerImpl} from './plugin_manager'; import {NewEngineMode} from '../trace_processor/engine'; import {RouteArgs} from '../public/route_schema'; import {SqlPackage} from '../public/extra_sql_packages'; -import {SerializedAppState} from '../public/state_serialization_schema'; -import {PostedTrace, TraceSource} from '../public/trace_source'; +import {SerializedAppState} from './state_serialization_schema'; +import {PostedTrace, TraceSource} from './trace_source'; import {loadTrace} from './load_trace'; import {CORE_PLUGIN_ID} from './plugin_manager'; import {Router} from './router'; diff --git a/ui/src/core/cache_manager.ts b/ui/src/core/cache_manager.ts index 78c75670b4..7dd9cd0f0f 100644 --- a/ui/src/core/cache_manager.ts +++ b/ui/src/core/cache_manager.ts @@ -18,7 +18,7 @@ * containing it is discarded by Chrome (e.g. because the tab was not used for * a long time) or when the user accidentally hits reload. */ -import {TraceArrayBufferSource, TraceSource} from '../public/trace_source'; +import {TraceArrayBufferSource, TraceSource} from './trace_source'; const TRACE_CACHE_NAME = 'cached_traces'; const TRACE_CACHE_SIZE = 10; diff --git a/ui/src/core/fake_trace_impl.ts b/ui/src/core/fake_trace_impl.ts index bb8084483e..6b3f7634d4 100644 --- a/ui/src/core/fake_trace_impl.ts +++ b/ui/src/core/fake_trace_impl.ts @@ -14,10 +14,10 @@ import {getServingRoot} from '../base/http_utils'; import {Time} from '../base/time'; -import {TraceInfo} from '../public/trace_info'; import {EngineBase} from '../trace_processor/engine'; import {AppImpl} from './app_impl'; import {TraceImpl} from './trace_impl'; +import {TraceInfoImpl} from './trace_info_impl'; export interface FakeTraceImplArgs { // If true suppresses exceptions when trying to issue a query. This is to @@ -48,7 +48,7 @@ export function createFakeTraceImpl(args: FakeTraceImplArgs = {}) { if (!AppImpl.initialized) { initializeAppImplForTesting(); } - const fakeTraceInfo: TraceInfo = { + const fakeTraceInfo: TraceInfoImpl = { source: {type: 'URL', url: ''}, traceTitle: '', traceUrl: '', diff --git a/ui/src/core/load_trace.ts b/ui/src/core/load_trace.ts index 1423365318..3776f95730 100644 --- a/ui/src/core/load_trace.ts +++ b/ui/src/core/load_trace.ts @@ -40,13 +40,13 @@ import { deserializeAppStatePhase1, deserializeAppStatePhase2, } from './state_serialization'; -import {TraceInfo} from '../public/trace_info'; import {AppImpl} from './app_impl'; import {raf} from './raf_scheduler'; import {TraceImpl} from './trace_impl'; -import {SerializedAppState} from '../public/state_serialization_schema'; -import {TraceSource} from '../public/trace_source'; +import {SerializedAppState} from './state_serialization_schema'; +import {TraceSource} from './trace_source'; import {Router} from '../core/router'; +import {TraceInfoImpl} from './trace_info_impl'; const ENABLE_CHROME_RELIABLE_RANGE_ZOOM_FLAG = featureFlags.register({ id: 'enableChromeReliableRangeZoom', @@ -354,7 +354,7 @@ async function computeVisibleTime( async function getTraceInfo( engine: Engine, traceSource: TraceSource, -): Promise { +): Promise { const traceTime = await getTraceTimeBounds(engine); // Find the first REALTIME or REALTIME_COARSE clock snapshot. diff --git a/ui/src/core/state_serialization.ts b/ui/src/core/state_serialization.ts index 38b8727637..bafc74f859 100644 --- a/ui/src/core/state_serialization.ts +++ b/ui/src/core/state_serialization.ts @@ -19,7 +19,7 @@ import { SerializedPluginState, SerializedSelection, SerializedAppState, -} from '../public/state_serialization_schema'; +} from './state_serialization_schema'; import {TimeSpan} from '../base/time'; import {TraceImpl} from './trace_impl'; diff --git a/ui/src/public/state_serialization_schema.ts b/ui/src/core/state_serialization_schema.ts similarity index 100% rename from ui/src/public/state_serialization_schema.ts rename to ui/src/core/state_serialization_schema.ts diff --git a/ui/src/core/trace_impl.ts b/ui/src/core/trace_impl.ts index 8944fe08ec..591664f770 100644 --- a/ui/src/core/trace_impl.ts +++ b/ui/src/core/trace_impl.ts @@ -19,7 +19,6 @@ import {TimelineImpl} from './timeline'; import {Command} from '../public/command'; import {EventListeners, Trace} from '../public/trace'; import {ScrollToArgs, setScrollToFunction} from '../public/scroll_helper'; -import {TraceInfo} from '../public/trace_info'; import {TrackDescriptor} from '../public/track'; import {EngineBase, EngineProxy} from '../trace_processor/engine'; import {CommandManagerImpl} from './command_manager'; @@ -44,6 +43,7 @@ import {CORE_PLUGIN_ID} from './plugin_manager'; import {Analytics} from '../public/analytics'; import {getOrCreate} from '../base/utils'; import {fetchWithProgress} from '../base/http_utils'; +import {TraceInfoImpl} from './trace_info_impl'; /** * Handles the per-trace state of the UI @@ -61,7 +61,7 @@ class TraceContext implements Disposable { readonly selectionMgr: SelectionManagerImpl; readonly tabMgr = new TabManagerImpl(); readonly timeline: TimelineImpl; - readonly traceInfo: TraceInfo; + readonly traceInfo: TraceInfoImpl; readonly trackMgr = new TrackManagerImpl(); readonly workspaceMgr = new WorkspaceManagerImpl(); readonly noteMgr = new NoteManagerImpl(); @@ -77,7 +77,7 @@ class TraceContext implements Disposable { // what TraceProcessor reports on the stats table at import time. readonly loadingErrors: string[] = []; - constructor(gctx: AppContext, engine: EngineBase, traceInfo: TraceInfo) { + constructor(gctx: AppContext, engine: EngineBase, traceInfo: TraceInfoImpl) { this.appCtx = gctx; this.engine = engine; this.trash.use(engine); @@ -179,7 +179,7 @@ export class TraceImpl implements Trace { static createInstanceForCore( appImpl: AppImpl, engine: EngineBase, - traceInfo: TraceInfo, + traceInfo: TraceInfoImpl, ): TraceImpl { const traceCtx = new TraceContext( appImpl.__appCtxForTraceImplCtor, @@ -321,7 +321,7 @@ export class TraceImpl implements Trace { return this.traceCtx.selectionMgr; } - get traceInfo(): TraceInfo { + get traceInfo(): TraceInfoImpl { return this.traceCtx.traceInfo; } diff --git a/ui/src/core/trace_info_impl.ts b/ui/src/core/trace_info_impl.ts new file mode 100644 index 0000000000..1584143daa --- /dev/null +++ b/ui/src/core/trace_info_impl.ts @@ -0,0 +1,20 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import {TraceSource} from '../core/trace_source'; +import {TraceInfo} from '../public/trace_info'; + +export interface TraceInfoImpl extends TraceInfo { + readonly source: TraceSource; +} diff --git a/ui/src/public/trace_source.ts b/ui/src/core/trace_source.ts similarity index 100% rename from ui/src/public/trace_source.ts rename to ui/src/core/trace_source.ts diff --git a/ui/src/frontend/permalink.ts b/ui/src/frontend/permalink.ts index 9dda6845d7..75c7f0b81a 100644 --- a/ui/src/frontend/permalink.ts +++ b/ui/src/frontend/permalink.ts @@ -30,7 +30,7 @@ import {globals} from './globals'; import { SERIALIZED_STATE_VERSION, SerializedAppState, -} from '../public/state_serialization_schema'; +} from '../core/state_serialization_schema'; import {z} from 'zod'; import {showModal} from '../widgets/modal'; import {AppImpl} from '../core/app_impl'; diff --git a/ui/src/frontend/post_message_handler.ts b/ui/src/frontend/post_message_handler.ts index 1a381c8132..60c97c5c7d 100644 --- a/ui/src/frontend/post_message_handler.ts +++ b/ui/src/frontend/post_message_handler.ts @@ -14,7 +14,7 @@ import m from 'mithril'; import {Time} from '../base/time'; -import {PostedTrace} from '../public/trace_source'; +import {PostedTrace} from '../core/trace_source'; import {showModal} from '../widgets/modal'; import {initCssConstants} from './css_constants'; import {toggleHelp} from './help_modal'; diff --git a/ui/src/frontend/sidebar.ts b/ui/src/frontend/sidebar.ts index 319d59a5e3..55608cf8ea 100644 --- a/ui/src/frontend/sidebar.ts +++ b/ui/src/frontend/sidebar.ts @@ -41,6 +41,7 @@ import {SidebarMenuItem} from '../public/sidebar'; import {AppImpl} from '../core/app_impl'; import {Trace} from '../public/trace'; import {removeFalsyValues} from '../base/array_utils'; +import {TraceImpl} from '../core/trace_impl'; const GITILES_URL = 'https://android.googlesource.com/platform/external/perfetto'; @@ -96,7 +97,7 @@ const EXPLORE_PAGE_IN_NAV_FLAG = featureFlags.register({ }); export interface OptionalTraceAttrs { - trace?: Trace; + trace?: TraceImpl; } function shouldShowHiringBanner(): boolean { @@ -147,7 +148,7 @@ function insertSidebarMenuitems( }); } -function getSections(app: AppImpl, trace: Trace | undefined): Section[] { +function getSections(app: AppImpl, trace: TraceImpl | undefined): Section[] { const downloadDisabled = trace?.traceInfo.downloadable ? undefined : 'Cannot download external trace'; @@ -315,7 +316,7 @@ async function convertTraceToJson(trace: Trace): Promise { await convertTraceToJsonAndDownload(file); } -function downloadTrace(trace: Trace) { +function downloadTrace(trace: TraceImpl) { if (!trace.traceInfo.downloadable) return; AppImpl.instance.analytics.logEvent('Trace Actions', 'Download trace'); diff --git a/ui/src/frontend/trace_share_utils.ts b/ui/src/frontend/trace_share_utils.ts index c1033c6d95..418fe51ca2 100644 --- a/ui/src/frontend/trace_share_utils.ts +++ b/ui/src/frontend/trace_share_utils.ts @@ -13,19 +13,20 @@ // limitations under the License. import m from 'mithril'; -import {TraceUrlSource} from '../public/trace_source'; +import {TraceUrlSource} from '../core/trace_source'; import {createPermalink} from './permalink'; import {showModal} from '../widgets/modal'; import {onClickCopy} from './clipboard'; import {globals} from './globals'; import {AppImpl} from '../core/app_impl'; import {Trace} from '../public/trace'; +import {TraceImpl} from '../core/trace_impl'; export function isShareable(trace: Trace) { return globals.isInternalUser && trace.traceInfo.downloadable; } -export async function shareTrace(trace: Trace) { +export async function shareTrace(trace: TraceImpl) { const traceSource = trace.traceInfo.source; const traceUrl = (traceSource as TraceUrlSource).url ?? ''; diff --git a/ui/src/public/trace_info.ts b/ui/src/public/trace_info.ts index 6ac99c5ddc..71d977bd76 100644 --- a/ui/src/public/trace_info.ts +++ b/ui/src/public/trace_info.ts @@ -13,11 +13,8 @@ // limitations under the License. import {time} from '../base/time'; -import {TraceSource} from './trace_source'; export interface TraceInfo { - readonly source: TraceSource; - readonly traceTitle: string; // File name and size of the current trace. readonly traceUrl: string; // URL of the Trace.