1/* 2 * Copyright (C) 2023 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 {assertDefined} from 'common/assert_utils'; 18import {AbsoluteFrameIndex} from 'trace/trace'; 19import {Traces} from 'trace/traces'; 20import {TraceType} from 'trace/trace_type'; 21import {TraceUtils} from './trace_utils'; 22 23export class TracesUtils { 24 static async extractEntries(traces: Traces): Promise<Map<TraceType, Array<{}>>> { 25 const entries = new Map<TraceType, Array<{}>>(); 26 27 const promises = traces.mapTrace(async (trace) => { 28 entries.set(trace.type, await TraceUtils.extractEntries(trace)); 29 }); 30 await Promise.all(promises); 31 32 return entries; 33 } 34 35 static async extractFrames( 36 traces: Traces 37 ): Promise<Map<AbsoluteFrameIndex, Map<TraceType, Array<{}>>>> { 38 const frames = new Map<AbsoluteFrameIndex, Map<TraceType, Array<{}>>>(); 39 40 const framePromises = traces.mapFrame(async (frame, index) => { 41 frames.set(index, new Map<TraceType, Array<{}>>()); 42 const tracePromises = frame.mapTrace(async (trace, type) => { 43 assertDefined(frames.get(index)).set(type, await TraceUtils.extractEntries(trace)); 44 }); 45 await Promise.all(tracePromises); 46 }); 47 await Promise.all(framePromises); 48 49 return frames; 50 } 51} 52