1/* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { SpSystemTrace } from '../SpSystemTrace'; 17import { TraceRow } from '../trace/base/TraceRow'; 18import { BaseStruct } from '../../bean/BaseStruct'; 19import { SnapShotRender, SnapShotStruct } from '../../database/ui-worker/ProcedureWorkerSnaps'; 20import { rowThreadHandler } from './SpChartManager'; 21import { SpRecordTrace } from '../SpRecordTrace'; 22 23export class SpSnapShotChart { 24 private readonly trace: SpSystemTrace; 25 constructor(trace: SpSystemTrace) { 26 this.trace = trace; 27 } 28 29 async init(parentRow?: TraceRow<BaseStruct>, traceId?: string): Promise<void> { 30 let traceRow = await this.initData(traceId); 31 if (parentRow) { 32 parentRow.addChildTraceRow(traceRow); 33 } else { 34 this.trace.rowsEL?.appendChild(traceRow); 35 } 36 } 37 38 async initData(traceId?: string): Promise<TraceRow<SnapShotStruct>> { 39 let snapShotTraceRow: TraceRow<SnapShotStruct> = TraceRow.skeleton<SnapShotStruct>(traceId); 40 snapShotTraceRow.rowId = 'snapShot'; 41 snapShotTraceRow.index = 0; 42 snapShotTraceRow.rowType = TraceRow.ROW_TYPE_SNAPSHOT; 43 snapShotTraceRow.rowParentId = ''; 44 snapShotTraceRow.style.height = '150px'; 45 snapShotTraceRow.name = 'snapShot'; 46 snapShotTraceRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 47 snapShotTraceRow.selectChangeHandler = this.trace.selectChangeHandler; 48 snapShotTraceRow.supplierFrame = async (): Promise<SnapShotStruct[]> => { 49 const baseDuration = SpRecordTrace.snapShotDuration * 1000000; 50 const baseStartTime = 0; 51 const imageList = SpRecordTrace.snapShotList as string[]; 52 interface CachedImageInfo { 53 img: string; 54 startTime: number; 55 dur: number; 56 } 57 const cachedImages: CachedImageInfo[] = imageList.map((img, index) => { 58 const startTime = baseStartTime + index * baseDuration; 59 return { 60 img: img, 61 startTime: startTime, 62 dur: baseDuration 63 }; 64 }); 65 return cachedImages as unknown as SnapShotStruct[]; 66 }; 67 snapShotTraceRow.onThreadHandler = rowThreadHandler<SnapShotRender>('snap-shot', 'snapShotContext', { 68 type: 'snapShots', 69 translateY: snapShotTraceRow.translateY, 70 }, snapShotTraceRow, this.trace); 71 return snapShotTraceRow; 72 } 73}