Skip to content

Commit

Permalink
Merge changes I353ea405,I29724762 into main
Browse files Browse the repository at this point in the history
* changes:
  ui: Remove LegacyDetailsPanel
  ui: Add selection resolver API
  • Loading branch information
stevegolton authored and Gerrit Code Review committed Sep 28, 2024
2 parents e6b7f34 + b9ff56b commit b0c45bb
Show file tree
Hide file tree
Showing 48 changed files with 382 additions and 290 deletions.
10 changes: 5 additions & 5 deletions ui/src/common/state_serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,19 @@ export function deserializeAppStatePhase2(appState: SerializedAppState): void {
const selMgr = globals.selectionManager;
switch (sel.kind) {
case 'TRACK_EVENT':
selMgr.setEvent(sel.trackKey, parseInt(sel.eventId));
selMgr.selectTrackEvent(sel.trackKey, parseInt(sel.eventId));
break;
case 'LEGACY_SCHED_SLICE':
selMgr.setLegacy({kind: 'SCHED_SLICE', id: sel.id});
selMgr.selectSqlEvent('sched_slice', sel.id);
break;
case 'LEGACY_SLICE':
selMgr.setLegacy({kind: 'SLICE', id: sel.id});
selMgr.selectSqlEvent('slice', sel.id);
break;
case 'LEGACY_THREAD_STATE':
selMgr.setLegacy({kind: 'THREAD_STATE', id: sel.id});
selMgr.selectSqlEvent('thread_slice', sel.id);
break;
case 'LEGACY_HEAP_PROFILE':
selMgr.setLegacy({
selMgr.selectLegacy({
kind: 'HEAP_PROFILE',
id: sel.id,
upid: sel.upid,
Expand Down
20 changes: 6 additions & 14 deletions ui/src/controller/trace_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class TraceController extends Controller<States> {
const upid = row.upid;
const leftTs = traceTime.start;
const rightTs = traceTime.end;
globals.selectionManager.setLegacy({
globals.selectionManager.selectLegacy({
kind: 'PERF_SAMPLES',
id: 0,
upid,
Expand Down Expand Up @@ -531,7 +531,7 @@ export class TraceController extends Controller<States> {
const row = profile.firstRow({ts: LONG, type: STR, upid: NUM});
const ts = Time.fromRaw(row.ts);
const upid = row.upid;
globals.selectionManager.setLegacy({
globals.selectionManager.selectLegacy({
kind: 'HEAP_PROFILE',
id: 0,
upid,
Expand Down Expand Up @@ -581,18 +581,10 @@ export class TraceController extends Controller<States> {
if (track === undefined) {
return;
}
globals.selectionManager.setLegacy(
{
kind: 'SLICE',
id: row.id,
trackUri: track.uri,
table: 'slice',
},
{
pendingScrollId: row.id,
switchToCurrentSelectionTab: false,
},
);
globals.selectionManager.selectSqlEvent('slice', row.id, {
pendingScrollId: row.id,
switchToCurrentSelectionTab: false,
});
}
}

Expand Down
11 changes: 0 additions & 11 deletions ui/src/core/app_trace_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {TimeSpan} from '../base/time';
import {TimelineImpl} from '../core/timeline';
import {App} from '../public/app';
import {Command} from '../public/command';
import {DetailsPanel, LegacyDetailsPanel} from '../public/details_panel';
import {Trace} from '../public/trace';
import {setScrollToFunction} from '../public/scroll_helper';
import {ScrollToArgs} from '../public/scroll_helper';
Expand Down Expand Up @@ -328,16 +327,6 @@ export class TraceImpl implements Trace {
return new TraceImpl(this.appImpl.forkForPlugin(pluginId), this.traceCtx);
}

registerDetailsPanel(
detailsPanel: DetailsPanel | LegacyDetailsPanel,
): Disposable {
if (detailsPanel.panelType === 'LegacyDetailsPanel') {
return this.traceCtx.tabMgr.registerLegacyDetailsPanel(detailsPanel);
} else {
return this.traceCtx.tabMgr.registerDetailsPanel(detailsPanel);
}
}

mountStore<T>(migrate: Migrate<T>): Store<T> {
return this.traceCtx.pluginSerializableState.createSubStore(
[this.pluginId],
Expand Down
115 changes: 70 additions & 45 deletions ui/src/core/selection_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SelectionOpts,
SelectionManager,
AreaSelectionAggregator,
SqlSelectionResolver,
} from '../public/selection';
import {duration, Time, time, TimeSpan} from '../base/time';
import {
Expand Down Expand Up @@ -57,6 +58,7 @@ export class SelectionManagerImpl implements SelectionManager {
// Incremented every time _selection changes.
private _selectionGeneration = 0;
private _limiter = new AsyncLimiter();
private readonly selectionResolvers = new Array<SqlSelectionResolver>();

constructor(
engine: Engine,
Expand All @@ -79,29 +81,38 @@ export class SelectionManagerImpl implements SelectionManager {
this.setSelection({kind: 'empty'});
}

setEvent(trackUri: string, eventId: number) {
this.setSelection({
kind: 'single',
trackUri,
eventId,
});
selectTrackEvent(trackUri: string, eventId: number, opts?: SelectionOpts) {
this.setSelection(
{
kind: 'single',
trackUri,
eventId,
},
opts,
);
}

setNote(args: {id: string}) {
this.setSelection({
kind: 'note',
id: args.id,
});
selectNote(args: {id: string}, opts?: SelectionOpts) {
this.setSelection(
{
kind: 'note',
id: args.id,
},
opts,
);
}

setArea(args: Area): void {
selectArea(args: Area, opts?: SelectionOpts): void {
const {start, end} = args;
assertTrue(start <= end);
this.setSelection({
kind: 'area',
tracks: [],
...args,
});
this.setSelection(
{
kind: 'area',
tracks: [],
...args,
},
opts,
);
}

toggleTrackAreaSelection(trackUri: string) {
Expand Down Expand Up @@ -150,7 +161,7 @@ export class SelectionManagerImpl implements SelectionManager {

// There is no matching addLegacy as we did not support multi-single
// selection with the legacy selection system.
setLegacy(legacySelection: LegacySelection, opts?: SelectionOpts): void {
selectLegacy(legacySelection: LegacySelection, opts?: SelectionOpts): void {
this.setSelection(
{
kind: 'legacy',
Expand All @@ -160,7 +171,7 @@ export class SelectionManagerImpl implements SelectionManager {
);
}

setGenericSlice(args: {
selectGenericSlice(args: {
id: number;
sqlTableName: string;
start: time;
Expand Down Expand Up @@ -204,6 +215,35 @@ export class SelectionManagerImpl implements SelectionManager {
return this._selectedDetails;
}

registerSqlSelectionResolver(resolver: SqlSelectionResolver): void {
this.selectionResolvers.push(resolver);
}

async resolveSqlEvent(
sqlTableName: string,
id: number,
): Promise<Selection | undefined> {
const matchingResolvers = this.selectionResolvers.filter(
(r) => r.sqlTableName === sqlTableName,
);

for (const resolver of matchingResolvers) {
const result = await resolver.callback(id, sqlTableName);
if (result) {
// If we have multiple resolvers for the same table, just return the first one.
return result;
}
}

return undefined;
}

selectSqlEvent(sqlTableName: string, id: number, opts?: SelectionOpts): void {
this.resolveSqlEvent(sqlTableName, id).then((selection) => {
selection && this.setSelection(selection, opts);
});
}

private setSelection(selection: Selection, opts?: SelectionOpts) {
if (selection.kind === 'area') {
// In the case of area selection, the caller provides a list of trackUris.
Expand Down Expand Up @@ -278,21 +318,14 @@ export class SelectionManagerImpl implements SelectionManager {
});
break;
case 'cpu':
this.setLegacy(
{
kind: 'SCHED_SLICE',
id: eventId,
trackUri,
},
{
clearSearch: false,
pendingScrollId: eventId,
switchToCurrentSelectionTab: true,
},
);
this.selectSqlEvent('sched_slice', eventId, {
clearSearch: false,
pendingScrollId: eventId,
switchToCurrentSelectionTab: true,
});
break;
case 'log':
this.setLegacy(
this.selectLegacy(
{
kind: 'LOG',
id: eventId,
Expand All @@ -307,19 +340,11 @@ export class SelectionManagerImpl implements SelectionManager {
case 'slice':
// Search results only include slices from the slice table for now.
// When we include annotations we need to pass the correct table.
this.setLegacy(
{
kind: 'SLICE',
id: eventId,
trackUri,
table: 'slice',
},
{
clearSearch: false,
pendingScrollId: eventId,
switchToCurrentSelectionTab: true,
},
);
this.selectSqlEvent('slice', eventId, {
clearSearch: false,
pendingScrollId: eventId,
switchToCurrentSelectionTab: true,
});
break;
default:
assertUnreachable(source);
Expand Down
14 changes: 1 addition & 13 deletions ui/src/core/tab_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {DetailsPanel, LegacyDetailsPanel} from '../public/details_panel';
import {DetailsPanel} from '../public/details_panel';
import {TabDescriptor, TabManager} from '../public/tab';
import {raf} from './raf_scheduler';

Expand All @@ -28,7 +28,6 @@ export interface ResolvedTab {
export class TabManagerImpl implements TabManager, Disposable {
private _registry = new Map<string, TabDescriptor>();
private _defaultTabs = new Set<string>();
private _legacyDetailsPanelRegistry = new Set<LegacyDetailsPanel>();
private _detailsPanelRegistry = new Set<DetailsPanel>();
private _instantiatedTabs = new Map<string, TabDescriptor>();
private _openTabs: string[] = []; // URIs of the tabs open.
Expand Down Expand Up @@ -56,13 +55,6 @@ export class TabManagerImpl implements TabManager, Disposable {
};
}

registerLegacyDetailsPanel(section: LegacyDetailsPanel): Disposable {
this._legacyDetailsPanelRegistry.add(section);
return {
[Symbol.dispose]: () => this._legacyDetailsPanelRegistry.delete(section),
};
}

registerDetailsPanel(section: DetailsPanel): Disposable {
this._detailsPanelRegistry.add(section);
return {
Expand Down Expand Up @@ -146,10 +138,6 @@ export class TabManagerImpl implements TabManager, Disposable {
return Array.from(this._defaultTabs);
}

get legacyDetailsPanels(): LegacyDetailsPanel[] {
return Array.from(this._legacyDetailsPanelRegistry);
}

get detailsPanels(): DetailsPanel[] {
return Array.from(this._detailsPanelRegistry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class CriticalUserInteractionTrack extends CustomSqlTableSliceTrack {

onSliceClick(args: OnSliceClickArgs<CriticalUserInteractionSlice>) {
const detailsPanelConfig = this.getDetailsPanel(args);
this.trace.selection.setGenericSlice({
this.trace.selection.selectGenericSlice({
id: args.slice.scopedId,
sqlTableName: this.tableName,
start: args.slice.ts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CriticalUserInteractionPlugin implements PerfettoPlugin {
}),
});

ctx.registerDetailsPanel(
ctx.tabs.registerDetailsPanel(
new BottomTabToSCSAdapter({
tabFactory: (selection) => {
if (
Expand All @@ -69,7 +69,7 @@ class CriticalUserInteractionPlugin implements PerfettoPlugin {
}),
);

ctx.registerDetailsPanel(
ctx.tabs.registerDetailsPanel(
new BottomTabToSCSAdapter({
tabFactory: (selection) => {
if (
Expand All @@ -88,7 +88,7 @@ class CriticalUserInteractionPlugin implements PerfettoPlugin {
}),
);

ctx.registerDetailsPanel(
ctx.tabs.registerDetailsPanel(
new BottomTabToSCSAdapter({
tabFactory: (selection) => {
if (
Expand Down
6 changes: 3 additions & 3 deletions ui/src/core_plugins/chrome_scroll_jank/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ChromeScrollJankPlugin implements PerfettoPlugin {
const track = new TrackNode({uri, title});
group.addChildInOrder(track);

ctx.registerDetailsPanel(
ctx.tabs.registerDetailsPanel(
new BottomTabToSCSAdapter({
tabFactory: (selection) => {
if (
Expand Down Expand Up @@ -298,7 +298,7 @@ class ChromeScrollJankPlugin implements PerfettoPlugin {
const track = new TrackNode({uri, title});
group.addChildInOrder(track);

ctx.registerDetailsPanel(
ctx.tabs.registerDetailsPanel(
new BottomTabToSCSAdapter({
tabFactory: (selection) => {
if (
Expand Down Expand Up @@ -345,7 +345,7 @@ class ChromeScrollJankPlugin implements PerfettoPlugin {
const track = new TrackNode({uri, title});
group.addChildInOrder(track);

ctx.registerDetailsPanel(
ctx.tabs.registerDetailsPanel(
new BottomTabToSCSAdapter({
tabFactory: (selection) => {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export function getCauseLink(
viewPercentage: 0.3,
},
});
trace.selection.setArea({
trace.selection.selectArea({
start: ts,
end: Time.fromRaw(ts + dur),
trackUris,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class ScrollJankSliceRef
}

const trackUri = track.key;
globals.selectionManager.setGenericSlice({
globals.selectionManager.selectGenericSlice({
id: vnode.attrs.id,
sqlTableName: track.sqlTableName,
start: vnode.attrs.ts,
Expand Down
Loading

0 comments on commit b0c45bb

Please sign in to comment.