• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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        SpRecordTrace.isSnapShotCapture = false;
31        let traceRow = await this.initData(traceId);
32        if (parentRow) {
33            parentRow.addChildTraceRow(traceRow);
34        } else {
35            this.trace.rowsEL?.appendChild(traceRow);
36        }
37    }
38
39    async initData(traceId?: string): Promise<TraceRow<SnapShotStruct>> {
40        let snapShotTraceRow: TraceRow<SnapShotStruct> = TraceRow.skeleton<SnapShotStruct>(traceId);
41        snapShotTraceRow.rowId = 'snapShot';
42        snapShotTraceRow.index = 0;
43        snapShotTraceRow.rowType = TraceRow.ROW_TYPE_SNAPSHOT;
44        snapShotTraceRow.rowParentId = '';
45        snapShotTraceRow.style.height = '150px';
46        snapShotTraceRow.name = 'snapShot';
47        snapShotTraceRow.favoriteChangeHandler = this.trace.favoriteChangeHandler;
48        snapShotTraceRow.selectChangeHandler = this.trace.selectChangeHandler;
49        snapShotTraceRow.supplierFrame = async (): Promise<SnapShotStruct[]> => {
50            const baseDuration = SpRecordTrace.snapShotDuration * 1000000;
51            const baseStartTime = 0;
52            const imageList = SpRecordTrace.snapShotList as string[];
53            interface CachedImageInfo {
54                img: string;
55                startTime: number;
56                dur: number;
57            }
58            const cachedImages: CachedImageInfo[] = imageList.map((img, index) => {
59                const startTime = baseStartTime + index * baseDuration;
60                return {
61                    img: img,
62                    startTime: startTime,
63                    dur: baseDuration
64                };
65            });
66            return cachedImages as unknown as SnapShotStruct[];
67        };
68        snapShotTraceRow.onThreadHandler = rowThreadHandler<SnapShotRender>('snap-shot', 'snapShotContext', {
69            type: 'snapShots',
70            translateY: snapShotTraceRow.translateY,
71        }, snapShotTraceRow, this.trace);
72        return snapShotTraceRow;
73    }
74}