1414
1515import { OmniboxMode } from '../../core/omnibox_manager' ;
1616import { Trace } from '../../public/trace' ;
17- import { PromptOption } from '../../public/omnibox' ;
1817import { PerfettoPlugin , PluginDescriptor } from '../../public/plugin' ;
1918import { AppImpl } from '../../core/app_impl' ;
2019import { getTimeSpanOfSelectionOrVisibleWindow } from '../../public/utils' ;
20+ import { exists } from '../../base/utils' ;
21+ import { TrackNode } from '../../public/workspace' ;
2122
2223class TrackUtilsPlugin implements PerfettoPlugin {
2324 async onTraceLoad ( ctx : Trace ) : Promise < void > {
@@ -37,13 +38,22 @@ class TrackUtilsPlugin implements PerfettoPlugin {
3738
3839 ctx . commands . registerCommand ( {
3940 // Selects & reveals the first track on the timeline with a given URI.
40- id : 'perfetto.FindTrack ' ,
41- name : 'Find track by URI ' ,
41+ id : 'perfetto.FindTrackByName ' ,
42+ name : 'Find track by name ' ,
4243 callback : async ( ) => {
43- const tracks = ctx . tracks . getAllTracks ( ) ;
44- const options = tracks . map ( ( { uri} ) : PromptOption => {
45- return { key : uri , displayName : uri } ;
46- } ) ;
44+ const tracks = ctx . workspace . flatTracks ;
45+ const options = tracks
46+ . map ( ( node ) => ( exists ( node . uri ) ? { uri : node . uri , node} : undefined ) )
47+ . filter ( ( pair ) => pair !== undefined )
48+ . map ( ( { uri, node} ) => {
49+ let parent = node . parent ;
50+ let fullPath = [ node . title ] ;
51+ while ( parent && parent instanceof TrackNode ) {
52+ fullPath = [ parent . title , ...fullPath ] ;
53+ parent = parent . parent ;
54+ }
55+ return { key : uri , displayName : fullPath . join ( ' \u2023 ' ) } ;
56+ } ) ;
4757
4858 // Sort tracks in a natural sort order
4959 const collator = new Intl . Collator ( 'en' , {
@@ -59,12 +69,38 @@ class TrackUtilsPlugin implements PerfettoPlugin {
5969 sortedOptions ,
6070 ) ;
6171 if ( selectedUri === undefined ) return ; // Prompt cancelled.
62- ctx . scrollTo ( { track : { uri : selectedUri , expandGroup : true } } ) ;
63- ctx . selection . selectArea ( {
64- start : ctx . traceInfo . start ,
65- end : ctx . traceInfo . end ,
66- trackUris : [ selectedUri ] ,
72+ ctx . selection . selectTrack ( selectedUri , { scrollToSelection : true } ) ;
73+ } ,
74+ } ) ;
75+
76+ ctx . commands . registerCommand ( {
77+ // Selects & reveals the first track on the timeline with a given URI.
78+ id : 'perfetto.FindTrackByUri' ,
79+ name : 'Find track by URI' ,
80+ callback : async ( ) => {
81+ const tracks = ctx . workspace . flatTracks ;
82+ const options = tracks
83+ . map ( ( track ) => track . uri )
84+ . filter ( ( uri ) => uri !== undefined )
85+ . map ( ( uri ) => {
86+ return { key : uri , displayName : uri } ;
87+ } ) ;
88+
89+ // Sort tracks in a natural sort order
90+ const collator = new Intl . Collator ( 'en' , {
91+ numeric : true ,
92+ sensitivity : 'base' ,
93+ } ) ;
94+ const sortedOptions = options . sort ( ( a , b ) => {
95+ return collator . compare ( a . displayName , b . displayName ) ;
6796 } ) ;
97+
98+ const selectedUri = await ctx . omnibox . prompt (
99+ 'Choose a track...' ,
100+ sortedOptions ,
101+ ) ;
102+ if ( selectedUri === undefined ) return ; // Prompt cancelled.
103+ ctx . selection . selectTrack ( selectedUri , { scrollToSelection : true } ) ;
68104 } ,
69105 } ) ;
70106 }
0 commit comments