Skip to content

Commit

Permalink
Merge "[ui] Rename various things." into main
Browse files Browse the repository at this point in the history
  • Loading branch information
chromy authored and Gerrit Code Review committed Oct 9, 2023
2 parents 5eafba6 + 211d6a3 commit 1204dd5
Show file tree
Hide file tree
Showing 42 changed files with 228 additions and 232 deletions.
4 changes: 2 additions & 2 deletions ui/src/common/basic_async_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {globals} from '../frontend/globals';
import {PxSpan, TimeScale} from '../frontend/time_scale';
import {SliceRect} from '../frontend/track';
import {TrackButtonAttrs} from '../frontend/track_panel';
import {TrackLike} from '../public';
import {Track} from '../public';

import {TrackData} from './track_data';

Expand All @@ -40,7 +40,7 @@ export {
// This provides the logic to perform data reloads at appropriate times as the
// window is panned and zoomed about.
// The extending class need only define renderCanvas() and onBoundsChange().
export abstract class BasicAsyncTrack<Data> implements TrackLike {
export abstract class BasicAsyncTrack<Data> implements Track {
private requestingData = false;
private queuedRequest = false;
private currentState?: TrackData;
Expand Down
60 changes: 29 additions & 31 deletions ui/src/common/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import {
Plugin,
PluginClass,
PluginContext,
PluginInfo,
PluginTrackInfo,
PluginContextTrace,
PluginDescriptor,
StatefulPlugin,
Store,
TracePluginContext,
Track,
TrackContext,
TrackInfo,
TrackLike,
TrackDescriptor,
TrackInstanceDescriptor,
Viewer,
} from '../public';

Expand Down Expand Up @@ -73,13 +73,13 @@ export class PluginContextImpl implements PluginContext, Disposable {
});
}

registerTrackController(track: TrackControllerFactory): void {
LEGACY_registerTrackController(track: TrackControllerFactory): void {
if (!this.alive) return;
const unregister = trackControllerRegistry.register(track);
this.trash.add(unregister);
}

registerTrack(track: TrackCreator): void {
LEGACY_registerTrack(track: TrackCreator): void {
if (!this.alive) return;
const unregister = trackRegistry.register(track);
this.trash.add(unregister);
Expand All @@ -95,30 +95,30 @@ export class PluginContextImpl implements PluginContext, Disposable {
// related resources, such as the engine and the store.
// The TracePluginContext exists for the whole duration a plugin is active AND a
// trace is loaded.
class TracePluginContextImpl<T> implements TracePluginContext<T>, Disposable {
class TracePluginContextImpl<T> implements PluginContextTrace<T>, Disposable {
private trash = new Trash();
private alive = true;

constructor(
private ctx: PluginContext, readonly store: Store<T>,
readonly engine: EngineProxy,
readonly trackRegistry: Map<string, PluginTrackInfo>,
private suggestedTracks: Set<TrackInfo>,
readonly trackRegistry: Map<string, TrackDescriptor>,
private suggestedTracks: Set<TrackInstanceDescriptor>,
private commandRegistry: Map<string, Command>) {
this.trash.add(engine);
this.trash.add(store);
}

registerTrackController(track: TrackControllerFactory): void {
LEGACY_registerTrackController(track: TrackControllerFactory): void {
// Silently ignore if context is dead.
if (!this.alive) return;
this.ctx.registerTrackController(track);
this.ctx.LEGACY_registerTrackController(track);
}

registerTrack(track: TrackCreator): void {
LEGACY_registerTrack(track: TrackCreator): void {
// Silently ignore if context is dead.
if (!this.alive) return;
this.ctx.registerTrack(track);
this.ctx.LEGACY_registerTrack(track);
}

addCommand(cmd: Command): void {
Expand All @@ -143,7 +143,7 @@ class TracePluginContextImpl<T> implements TracePluginContext<T>, Disposable {
// Register a new track in this context.
// All tracks registered through this method are removed when this context is
// destroyed, i.e. when the trace is unloaded.
addTrack(trackDetails: PluginTrackInfo): void {
addTrack(trackDetails: TrackDescriptor): void {
// Silently ignore if context is dead.
if (!this.alive) return;
const {uri} = trackDetails;
Expand All @@ -156,7 +156,7 @@ class TracePluginContextImpl<T> implements TracePluginContext<T>, Disposable {
// This is a direct replacement for findPotentialTracks().
// Note: This interface is likely to be deprecated soon, but is required while
// both plugin and original type tracks coexist.
suggestTrack(trackInfo: TrackInfo): void {
suggestTrack(trackInfo: TrackInstanceDescriptor): void {
this.suggestedTracks.add(trackInfo);
this.trash.addCallback(() => this.suggestedTracks.delete(trackInfo));
}
Expand All @@ -168,7 +168,7 @@ class TracePluginContextImpl<T> implements TracePluginContext<T>, Disposable {
}

// 'Static' registry of all known plugins.
export class PluginRegistry extends Registry<PluginInfo<unknown>> {
export class PluginRegistry extends Registry<PluginDescriptor<unknown>> {
constructor() {
super((info) => info.pluginId);
}
Expand All @@ -184,19 +184,17 @@ function isPluginClass<T>(v: unknown): v is PluginClass<T> {
return typeof v === 'function' && !!(v.prototype.onActivate);
}

function makePlugin<T>(info: PluginInfo<T>): Plugin<T> {
const {plugin: pluginFactory} = info;
function makePlugin<T>(info: PluginDescriptor<T>): Plugin<T> {
const {plugin} = info;

if (typeof pluginFactory === 'function') {
if (isPluginClass(pluginFactory)) {
const PluginClass = pluginFactory;
if (typeof plugin === 'function') {
if (isPluginClass(plugin)) {
const PluginClass = plugin;
return new PluginClass();
} else {
return pluginFactory();
return plugin();
}
} else {
// pluginFactory is the plugin!
const plugin = pluginFactory;
return plugin;
}
}
Expand All @@ -205,9 +203,9 @@ export class PluginManager {
private registry: PluginRegistry;
private plugins: Map<string, PluginDetails<unknown>>;
private engine?: Engine;
readonly trackRegistry = new Map<string, PluginTrackInfo>();
readonly trackRegistry = new Map<string, TrackDescriptor>();
readonly commandRegistry = new Map<string, Command>();
readonly suggestedTracks = new Set<TrackInfo>();
readonly suggestedTracks = new Set<TrackInstanceDescriptor>();

constructor(registry: PluginRegistry) {
this.registry = registry;
Expand Down Expand Up @@ -265,7 +263,7 @@ export class PluginManager {
return this.plugins.get(pluginId);
}

findPotentialTracks(): TrackInfo[] {
findPotentialTracks(): TrackInstanceDescriptor[] {
return Array.from(this.suggestedTracks);
}

Expand Down Expand Up @@ -300,15 +298,15 @@ export class PluginManager {

// Look up track into for a given track's URI.
// Returns |undefined| if no track can be found.
resolveTrackInfo(uri: string): PluginTrackInfo|undefined {
resolveTrackInfo(uri: string): TrackDescriptor|undefined {
return this.trackRegistry.get(uri);
}

// Create a new plugin track object from its URI.
// Returns undefined if no such track is registered.
createTrack(uri: string, trackCtx: TrackContext): TrackLike|undefined {
createTrack(uri: string, trackCtx: TrackContext): Track|undefined {
const trackInfo = pluginManager.trackRegistry.get(uri);
return trackInfo && trackInfo.trackFactory(trackCtx);
return trackInfo && trackInfo.track(trackCtx);
}

private doPluginTraceLoad<T>(
Expand Down
4 changes: 2 additions & 2 deletions ui/src/frontend/base_slice_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {Slice} from './slice';
import {DEFAULT_SLICE_LAYOUT, SliceLayout} from './slice_layout';
import {constraintsToQuerySuffix} from './sql_utils';
import {PxSpan, TimeScale} from './time_scale';
import {NewTrackArgs, SliceRect, Track} from './track';
import {NewTrackArgs, SliceRect, TrackBase} from './track';
import {BUCKETS_PER_PIXEL, CacheKey, TrackCache} from './track_cache';

// The common class that underpins all tracks drawing slices.
Expand Down Expand Up @@ -179,7 +179,7 @@ export interface BaseSliceTrackTypes {

export abstract class BaseSliceTrack<T extends BaseSliceTrackTypes =
BaseSliceTrackTypes> extends
Track<T['config']> {
TrackBase<T['config']> {
protected sliceLayout: SliceLayout = {...DEFAULT_SLICE_LAYOUT};

// This is the over-skirted cached bounds:
Expand Down
8 changes: 4 additions & 4 deletions ui/src/frontend/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {duration, Span, time} from '../base/time';
import {EngineProxy} from '../common/engine';
import {TrackState} from '../common/state';
import {TrackData} from '../common/track_data';
import {TrackLike} from '../public';
import {Track} from '../public';

import {checkerboard} from './checkerboard';
import {globals} from './globals';
Expand All @@ -42,7 +42,7 @@ export interface TrackCreator {

// We need the |create| method because the stored value in the registry can be
// an abstract class, and we cannot call 'new' on an abstract class.
create(args: NewTrackArgs): Track;
create(args: NewTrackArgs): TrackBase;
}

export interface SliceRect {
Expand All @@ -54,8 +54,8 @@ export interface SliceRect {
}

// The abstract class that needs to be implemented by all tracks.
export abstract class Track<Config = {}, Data extends TrackData = TrackData>
implements TrackLike {
export abstract class TrackBase<Config = {}, Data extends TrackData = TrackData>
implements Track {
// The UI-generated track ID (not to be confused with the SQL track.id).
protected readonly trackId: string;
protected readonly engine: EngineProxy;
Expand Down
7 changes: 3 additions & 4 deletions ui/src/frontend/track_group_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
TrackGroupState,
TrackState,
} from '../common/state';
import {Migrate, TrackContext, TrackLike} from '../public';
import {Migrate, Track, TrackContext} from '../public';

import {globals} from './globals';
import {drawGridLines} from './gridline_helper';
Expand All @@ -45,7 +45,7 @@ export class TrackGroupPanel extends Panel<Attrs> {
private readonly trackGroupId: string;
private shellWidth = 0;
private backgroundColor = '#ffffff'; // Updated from CSS later.
private summaryTrack?: TrackLike;
private summaryTrack?: Track;

constructor({attrs}: m.CVnode<Attrs>) {
super();
Expand Down Expand Up @@ -305,8 +305,7 @@ function StripPathFromExecutable(path: string) {
return path.split('/').slice(-1)[0];
}

function loadTrack(trackState: TrackState, trackId: string): TrackLike|
undefined {
function loadTrack(trackState: TrackState, trackId: string): Track|undefined {
const engine = globals.engines.get(trackState.engineId);
if (engine === undefined) {
return undefined;
Expand Down
13 changes: 6 additions & 7 deletions ui/src/frontend/track_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {pluginManager} from '../common/plugins';
import {RegistryError} from '../common/registry';
import {TrackState} from '../common/state';
import {raf} from '../core/raf_scheduler';
import {Migrate, TrackContext, TrackLike} from '../public';
import {Migrate, Track, TrackContext} from '../public';

import {SELECTION_FILL_COLOR, TRACK_SHELL_WIDTH} from './css_constants';
import {globals} from './globals';
Expand Down Expand Up @@ -101,7 +101,7 @@ export function renderChips({uri, config}: TrackState) {
}

interface TrackShellAttrs {
track: TrackLike;
track: Track;
trackState: TrackState;
}

Expand Down Expand Up @@ -233,7 +233,7 @@ class TrackShell implements m.ClassComponent<TrackShellAttrs> {
}

export interface TrackContentAttrs {
track: TrackLike;
track: Track;
}
export class TrackContent implements m.ClassComponent<TrackContentAttrs> {
private mouseDownX?: number;
Expand Down Expand Up @@ -292,7 +292,7 @@ export class TrackContent implements m.ClassComponent<TrackContentAttrs> {

interface TrackComponentAttrs {
trackState: TrackState;
track: TrackLike;
track: Track;
}
class TrackComponent implements m.ClassComponent<TrackComponentAttrs> {
view({attrs}: m.CVnode<TrackComponentAttrs>) {
Expand Down Expand Up @@ -356,7 +356,7 @@ export class TrackPanel extends Panel<TrackPanelAttrs> {
// TODO(hjd): It would be nicer if these could not be undefined here.
// We should implement a NullTrack which can be used if the trackState
// has disappeared.
private track: TrackLike|undefined;
private track: Track|undefined;
private trackState: TrackState|undefined;

private tryLoadTrack(vnode: m.CVnode<TrackPanelAttrs>) {
Expand Down Expand Up @@ -520,8 +520,7 @@ export class TrackPanel extends Panel<TrackPanelAttrs> {
}
}

function loadTrack(trackState: TrackState, trackId: string): TrackLike|
undefined {
function loadTrack(trackState: TrackState, trackId: string): Track|undefined {
const engine = globals.engines.get(trackState.engineId);
if (engine === undefined) {
return undefined;
Expand Down
18 changes: 9 additions & 9 deletions ui/src/plugins/com.example.Skeleton/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
MetricVisualisation,
Plugin,
PluginContext,
PluginInfo,
TracePluginContext,
TrackInfo,
PluginContextTrace,
PluginDescriptor,
TrackInstanceDescriptor,
} from '../../public';

interface State {
Expand All @@ -35,29 +35,29 @@ class Skeleton implements Plugin<State> {
return {foo: 'bar'};
}

async onTraceLoad(_: TracePluginContext<State>): Promise<void> {
async onTraceLoad(_: PluginContextTrace<State>): Promise<void> {
//
}

async onTraceUnload(_: TracePluginContext<State>): Promise<void> {
async onTraceUnload(_: PluginContextTrace<State>): Promise<void> {
//
}

onDeactivate(_: PluginContext): void {
//
}

async findPotentialTracks(_: TracePluginContext<State>):
Promise<TrackInfo[]> {
async findPotentialTracks(_: PluginContextTrace<State>):
Promise<TrackInstanceDescriptor[]> {
return [];
}

metricVisualisations(_: TracePluginContext<State>): MetricVisualisation[] {
metricVisualisations(_: PluginContextTrace<State>): MetricVisualisation[] {
return [];
}
}

export const plugin: PluginInfo<State> = {
export const plugin: PluginDescriptor<State> = {
// SKELETON: Update pluginId to match the directory of the plugin.
pluginId: 'com.example.Skeleton',
plugin: Skeleton,
Expand Down
4 changes: 2 additions & 2 deletions ui/src/plugins/dev.perfetto.AndroidBinderViz/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
MetricVisualisation,
Plugin,
PluginContext,
PluginInfo,
PluginDescriptor,
} from '../../public';

const SPEC = `
Expand Down Expand Up @@ -50,7 +50,7 @@ class AndroidBinderVizPlugin implements Plugin {
}
}

export const plugin: PluginInfo = {
export const plugin: PluginDescriptor = {
pluginId: 'dev.perfetto.AndroidBinderVizPlugin',
plugin: AndroidBinderVizPlugin,
};
4 changes: 2 additions & 2 deletions ui/src/plugins/dev.perfetto.AndroidCujs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import {
Plugin,
PluginContext,
PluginInfo,
PluginDescriptor,
} from '../../public';

class AndroidCujs implements Plugin {
Expand Down Expand Up @@ -130,7 +130,7 @@ class AndroidCujs implements Plugin {
}
}

export const plugin: PluginInfo = {
export const plugin: PluginDescriptor = {
pluginId: 'dev.perfetto.AndroidCujs',
plugin: AndroidCujs,
};
Loading

0 comments on commit 1204dd5

Please sign in to comment.