Skip to content

Commit

Permalink
Merge "[ui] Port android logs track to plugin tracks" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegolton authored and Gerrit Code Review committed Sep 25, 2023
2 parents 090480e + 48cd3b5 commit 1bb37ed
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ui/src/controller/track_decider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
UtidToTrackSortKey,
} from '../common/state';
import {ACTUAL_FRAMES_SLICE_TRACK_KIND} from '../tracks/actual_frames';
import {ANDROID_LOGS_TRACK_KIND} from '../tracks/android_log';
import {ASYNC_SLICE_TRACK_KIND} from '../tracks/async_slices';
import {
ENABLE_SCROLL_JANK_PLUGIN_V2,
Expand Down Expand Up @@ -883,11 +882,12 @@ class TrackDecider {
if (count > 0) {
this.tracksToAdd.push({
engineId: this.engineId,
kind: ANDROID_LOGS_TRACK_KIND,
kind: PLUGIN_TRACK_KIND,
name: 'Android logs',
trackSortKey: PrimaryTrackSortKey.ORDINARY_TRACK,
trackGroup: SCROLLING_TRACK_GROUP,
config: {},
uri: 'perfetto.AndroidLog',
});
}
}
Expand Down
5 changes: 5 additions & 0 deletions ui/src/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ export interface TrackContext {
trackInstanceId: string;
}

export interface TrackContext {
// A unique ID for the instance of this track.
trackInstanceId: string;
}

// TODO(stevegolton): Rename `Track` to `BaseTrack` (or similar) and rename this
// interface to `Track`.
export interface TrackLike {
Expand Down
50 changes: 35 additions & 15 deletions ui/src/tracks/android_log/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@

import {duration, Time, time} from '../../base/time';
import {LONG, NUM} from '../../common/query_result';
import {LIMIT, TrackData} from '../../common/track_data';
import {
TrackController,
} from '../../controller/track_controller';
TrackAdapter,
TrackControllerAdapter,
TrackWithControllerAdapter,
} from '../../common/track_adapter';
import {LIMIT, TrackData} from '../../common/track_data';
import {checkerboardExcept} from '../../frontend/checkerboard';
import {globals} from '../../frontend/globals';
import {NewTrackArgs, Track} from '../../frontend/track';
import {Plugin, PluginContext, PluginInfo} from '../../public';

export const ANDROID_LOGS_TRACK_KIND = 'AndroidLogTrack';
import {NewTrackArgs} from '../../frontend/track';
import {
Plugin,
PluginContext,
PluginInfo,
TracePluginContext,
} from '../../public';

export interface Data extends TrackData {
// Total number of log events within [start, end], before any quantization.
Expand Down Expand Up @@ -56,9 +61,7 @@ const MARGIN_TOP = 2;
const RECT_HEIGHT = 35;
const EVT_PX = 2; // Width of an event tick in pixels.

class AndroidLogTrackController extends TrackController<Config, Data> {
static readonly kind = ANDROID_LOGS_TRACK_KIND;

class AndroidLogTrackController extends TrackControllerAdapter<Config, Data> {
async onBoundsChange(start: time, end: time, resolution: duration):
Promise<Data> {
const queryRes = await this.query(`
Expand Down Expand Up @@ -93,8 +96,7 @@ class AndroidLogTrackController extends TrackController<Config, Data> {
}
}

class AndroidLogTrack extends Track<Config, Data> {
static readonly kind = ANDROID_LOGS_TRACK_KIND;
class AndroidLogTrack extends TrackAdapter<Config, Data> {
static create(args: NewTrackArgs): AndroidLogTrack {
return new AndroidLogTrack(args);
}
Expand Down Expand Up @@ -143,9 +145,27 @@ class AndroidLogTrack extends Track<Config, Data> {
}

class AndroidLog implements Plugin {
onActivate(ctx: PluginContext): void {
ctx.registerTrack(AndroidLogTrack);
ctx.registerTrackController(AndroidLogTrackController);
onActivate(_ctx: PluginContext): void {}

async onTraceLoad(ctx: TracePluginContext): Promise<void> {
const result =
await ctx.engine.query(`select count(1) as cnt from android_logs`);
const count = result.firstRow({cnt: NUM}).cnt;
if (count > 0) {
ctx.addTrack({
uri: 'perfetto.AndroidLog',
displayName: 'Android logs',
tags: {type: 'counter'},
trackFactory: ({trackInstanceId}) => {
return new TrackWithControllerAdapter<Config, Data>(
ctx.engine,
trackInstanceId,
{},
AndroidLogTrack,
AndroidLogTrackController);
},
});
}
}
}

Expand Down

0 comments on commit 1bb37ed

Please sign in to comment.