Skip to content

Commit

Permalink
Remove most of the logic in selection resolver
Browse files Browse the repository at this point in the history
Also remove some layering violations which got in the way here.

Change-Id: Ieeac9cbd2cbf2336e47d13e25ecf168fd2b1f2b2
  • Loading branch information
Alexander Timin committed Sep 11, 2024
1 parent 76c9a33 commit 10bba8d
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 627 deletions.
66 changes: 0 additions & 66 deletions ui/src/common/thread_state.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {exists} from '../../base/utils';
import {ColumnDef, ThreadStateExtra} from '../../common/aggregation_data';
import {Sorting} from '../../common/state';
import {Area} from '../../public/selection';
import {translateState} from '../../common/thread_state';
import {THREAD_STATE_TRACK_KIND} from '../../public/track_kinds';
import {globals} from '../../frontend/globals';
import {Engine} from '../../trace_processor/engine';
import {NUM, NUM_NULL, STR_NULL} from '../../trace_processor/query_result';
import {AggregationController} from './aggregation_controller';
import {translateState} from '../../trace_processor/sql_utils/thread_state';

export class ThreadAggregationController extends AggregationController {
private utids?: number[];
Expand Down
18 changes: 0 additions & 18 deletions ui/src/core/selection_arg_types.ts

This file was deleted.

72 changes: 20 additions & 52 deletions ui/src/core/selection_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ const INCOMPLETE_SLICE_DURATION = 30_000n;
// requires querying the SQL engine, which is an async operation.
export class SelectionManagerImpl implements SelectionManager {
private _selection: Selection = {kind: 'empty'};
private _selectedSlice?: SelectedSliceDetails;
private _selectedThreadState?: SelectedThreadStateDetails;
private _selectedDetails?: LegacySelectionDetails;
private _selectionResolver?: SelectionResolver;
private _pendingScrollId?: number;
// Incremented every time _selection changes.
Expand All @@ -68,10 +67,7 @@ export class SelectionManagerImpl implements SelectionManager {
},
) {
if (_deps !== undefined) {
this._selectionResolver = new SelectionResolver(
_deps.engine,
_deps.trackManager,
);
this._selectionResolver = new SelectionResolver(_deps.engine);
_deps.noteManager.onNoteDeleted = (noteId) => {
if (this.selection.kind === 'note' && this.selection.id === noteId) {
this.clear();
Expand Down Expand Up @@ -301,6 +297,10 @@ export class SelectionManagerImpl implements SelectionManager {
return toLegacySelection(this._selection);
}

get legacySelectionDetails(): LegacySelectionDetails | undefined {
return this._selectedDetails;
}

private setSelection(selection: Selection, opts?: SelectionOpts) {
if (this._deps === undefined) return;
this._selection = selection;
Expand All @@ -321,8 +321,7 @@ export class SelectionManagerImpl implements SelectionManager {
// the selection.
const clearOnTimeout = setTimeout(() => {
if (this._selectionGeneration !== generation) return;
this._selectedSlice = undefined;
this._selectedThreadState = undefined;
this._selectedDetails = undefined;
raf.scheduleFullRedraw();
}, 50);

Expand All @@ -335,18 +334,13 @@ export class SelectionManagerImpl implements SelectionManager {
await this._selectionResolver?.resolveSelection(legacySel);
raf.scheduleFullRedraw();
clearTimeout(clearOnTimeout);
this._selectedSlice = undefined;
this._selectedThreadState = undefined;
this._selectedDetails = undefined;
if (details == undefined) return;
if (this._selectionGeneration !== generation) return;
if (legacySel.kind === 'THREAD_STATE') {
this._selectedThreadState = details;
} else {
this._selectedSlice = details;
if (exists(details.id) && details.id === this._pendingScrollId) {
this._pendingScrollId = undefined;
this.scrollToCurrentSelection();
}
this._selectedDetails = details;
if (exists(legacySel.id) && legacySel.id === this._pendingScrollId) {
this._pendingScrollId = undefined;
this.scrollToCurrentSelection();
}
});
}
Expand Down Expand Up @@ -403,10 +397,12 @@ export class SelectionManagerImpl implements SelectionManager {
return undefined;
}

if (legacySel.kind === 'SCHED_SLICE' || legacySel.kind === 'SLICE') {
return findTimeRangeOfSlice(this.selectedSlice ?? {});
} else if (legacySel.kind === 'THREAD_STATE') {
return findTimeRangeOfSlice(this._selectedThreadState ?? {});
if (
legacySel.kind === 'SCHED_SLICE' ||
legacySel.kind === 'SLICE' ||
legacySel.kind === 'THREAD_STATE'
) {
return findTimeRangeOfSlice(this._selectedDetails ?? {});
} else if (legacySel.kind === 'LOG') {
// TODO(hjd): Make focus selection work for logs.
} else if (legacySel.kind === 'GENERIC_SLICE') {
Expand All @@ -418,10 +414,6 @@ export class SelectionManagerImpl implements SelectionManager {

return undefined;
}

get selectedSlice(): Optional<SelectedSliceDetails> {
return this._selectedSlice;
}
}

function toLegacySelection(selection: Selection): LegacySelection | null {
Expand Down Expand Up @@ -464,34 +456,10 @@ function findTimeRangeOfSlice(slice: {ts?: time; dur?: duration}): TimeSpan {
}
}

export interface SelectedSliceDetails {
export interface LegacySelectionDetails {
ts?: time;
absTime?: string;
dur?: duration;
threadTs?: time;
threadDur?: duration;
priority?: number;
endState?: string | null;
cpu?: number;
id?: number;
threadStateId?: number;
utid?: number;
// Additional information for sched selection, used to draw the wakeup arrow.
wakeupTs?: time;
wakerUtid?: number;
wakerCpu?: number;
category?: string;
name?: string;
tid?: number;
threadName?: string;
pid?: number;
processName?: string;
uid?: number;
packageName?: string;
versionCode?: number;
description?: Map<string, string>;
}

export interface SelectedThreadStateDetails {
ts?: time;
dur?: duration;
}
Loading

0 comments on commit 10bba8d

Please sign in to comment.