1/* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {Analytics} from 'logging/analytics'; 18import {Traces} from 'trace/traces'; 19import {TRACE_INFO} from 'trace/trace_info'; 20import {TraceProcessorFactory} from 'trace_processor/trace_processor_factory'; 21import {SearchViewFactoryProtoLog} from './search_view_factory_protolog'; 22import {SearchViewFactorySf} from './search_view_factory_sf'; 23import {SearchViewFactoryTransactions} from './search_view_factory_transactions'; 24import {SearchViewFactoryTransitions} from './search_view_factory_transitions'; 25import {SearchViewFactoryVc} from './search_view_factory_vc'; 26 27export class TraceSearchInitializer { 28 static readonly FACTORIES = [ 29 SearchViewFactorySf, 30 SearchViewFactoryTransactions, 31 SearchViewFactoryTransitions, 32 SearchViewFactoryVc, 33 SearchViewFactoryProtoLog, 34 ]; 35 36 static async createSearchViews(traces: Traces): Promise<string[]> { 37 const traceProcessor = await TraceProcessorFactory.getSingleInstance(); 38 39 const searchViews: string[] = []; 40 for (const FactoryType of TraceSearchInitializer.FACTORIES) { 41 const factory = new FactoryType(traceProcessor); 42 if (traces.getTrace(factory.traceType)?.isPerfetto()) { 43 const lastQueryStartTime = Date.now(); 44 const views = await factory.createSearchViews(); 45 const executionTimeMs = Date.now() - lastQueryStartTime; 46 Analytics.TraceSearch.logInitializationTime( 47 TRACE_INFO[factory.traceType].name, 48 executionTimeMs, 49 ); 50 searchViews.push(...views); 51 } 52 } 53 return searchViews; 54 } 55} 56 57export interface SearchView { 58 name: string; 59 dataType: string; 60 columns: Array<{name: string; desc: string}>; 61 examples: Array<{query: string; desc: string}>; 62} 63 64export const SEARCH_VIEWS = TraceSearchInitializer.FACTORIES.flatMap( 65 (factory) => factory.getPossibleSearchViews(), 66); 67