1/* 2 * Copyright (C) 2025 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 {TraceProcessorConfig} from './engine'; 19import {QueryResult} from './query_result'; 20import {WasmEngineProxy} from './wasm_engine_proxy'; 21 22export class TraceProcessor { 23 private wasmEngine: WasmEngineProxy; 24 25 constructor(engineId: string, enginePort: MessagePort) { 26 this.wasmEngine = new WasmEngineProxy(engineId, enginePort); 27 } 28 29 async query(sqlQuery: string): Promise<QueryResult> { 30 const startTimeMs = Date.now(); 31 const result = await this.wasmEngine.query(sqlQuery); 32 Analytics.TraceProcessor.logQueryExecutionTime( 33 Date.now() - startTimeMs, 34 false 35 ); 36 return result; 37 } 38 39 async queryAllRows(sqlQuery: string): Promise<QueryResult> { 40 const startTimeMs = Date.now(); 41 const result = await this.wasmEngine.query(sqlQuery).waitAllRows(); 42 Analytics.TraceProcessor.logQueryExecutionTime( 43 Date.now() - startTimeMs, 44 true 45 ); 46 return result; 47 } 48 49 async resetTraceProcessor(config: TraceProcessorConfig) { 50 await this.wasmEngine.resetTraceProcessor(config); 51 } 52 53 async parse(data: Uint8Array) { 54 await this.wasmEngine.parse(data); 55 } 56 57 async notifyEof() { 58 await this.wasmEngine.notifyEof(); 59 } 60} 61