Skip to content

Commit

Permalink
ui: move TraceSource back into core
Browse files Browse the repository at this point in the history
There's no need for it to be exposed to plugins, exposing it also
requires exposing StateSerializationSchema which is just confusing.

Change-Id: Ib36b6cec0220c56fcd0a510ad2113f3ff20e5e32
  • Loading branch information
LalitMaganti committed Nov 4, 2024
1 parent 18a81e9 commit 4043fab
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 26 deletions.
2 changes: 1 addition & 1 deletion ui/src/common/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions ui/src/core/app_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion ui/src/core/cache_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ui/src/core/fake_trace_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: '',
Expand Down
8 changes: 4 additions & 4 deletions ui/src/core/load_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -354,7 +354,7 @@ async function computeVisibleTime(
async function getTraceInfo(
engine: Engine,
traceSource: TraceSource,
): Promise<TraceInfo> {
): Promise<TraceInfoImpl> {
const traceTime = await getTraceTimeBounds(engine);

// Find the first REALTIME or REALTIME_COARSE clock snapshot.
Expand Down
2 changes: 1 addition & 1 deletion ui/src/core/state_serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions ui/src/core/trace_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -321,7 +321,7 @@ export class TraceImpl implements Trace {
return this.traceCtx.selectionMgr;
}

get traceInfo(): TraceInfo {
get traceInfo(): TraceInfoImpl {
return this.traceCtx.traceInfo;
}

Expand Down
20 changes: 20 additions & 0 deletions ui/src/core/trace_info_impl.ts
Original file line number Diff line number Diff line change
@@ -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;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion ui/src/frontend/permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion ui/src/frontend/post_message_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 4 additions & 3 deletions ui/src/frontend/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -96,7 +97,7 @@ const EXPLORE_PAGE_IN_NAV_FLAG = featureFlags.register({
});

export interface OptionalTraceAttrs {
trace?: Trace;
trace?: TraceImpl;
}

function shouldShowHiringBanner(): boolean {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -315,7 +316,7 @@ async function convertTraceToJson(trace: Trace): Promise<void> {
await convertTraceToJsonAndDownload(file);
}

function downloadTrace(trace: Trace) {
function downloadTrace(trace: TraceImpl) {
if (!trace.traceInfo.downloadable) return;
AppImpl.instance.analytics.logEvent('Trace Actions', 'Download trace');

Expand Down
5 changes: 3 additions & 2 deletions ui/src/frontend/trace_share_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '';

Expand Down
3 changes: 0 additions & 3 deletions ui/src/public/trace_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 4043fab

Please sign in to comment.