• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 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.js";
17import {getFps} from "../../database/SqlLite.js";
18import {TraceRow} from "../trace/base/TraceRow.js";
19import {FpsStruct} from "../../bean/FpsStruct.js";
20import {procedurePool} from "../../database/Procedure.js";
21import {CpuStruct} from "../../bean/CpuStruct.js";
22import {info} from "../../../log/Log.js";
23
24export class SpFpsChart {
25    private trace: SpSystemTrace;
26
27    constructor(trace: SpSystemTrace) {
28        this.trace = trace;
29    }
30
31    async init() {
32        let res = await getFps();
33        if (res.length == 0) {
34            return;
35        }
36        let startTime = new Date().getTime();
37        let fpsRow = new TraceRow<FpsStruct>({canvasNumber: 1, alpha: true, contextId: '2d', isOffScreen: true});
38        fpsRow.rowId = `fps`
39        fpsRow.rowType = TraceRow.ROW_TYPE_FPS
40        fpsRow.rowParentId = ''
41        FpsStruct.maxFps = 0
42        fpsRow.style.height = '40px'
43        fpsRow.name = "FPS"
44        fpsRow.supplier = () => new Promise<Array<any>>((resolve, reject) => resolve(res));
45        fpsRow.favoriteChangeHandler = this.trace.favoriteChangeHandler;
46        fpsRow.selectChangeHandler = this.trace.selectChangeHandler;
47        fpsRow.onThreadHandler = (useCache) => {
48            procedurePool.submitWithName(`process0`, `fps0`, {
49                list: fpsRow.must ? fpsRow.dataList : undefined,
50                offscreen: !fpsRow.isTransferCanvas ? fpsRow.offscreen[0] : undefined,
51                xs: TraceRow.range?.xs,
52                dpr: fpsRow.dpr,
53                isHover: fpsRow.isHover,
54                flagMoveInfo: this.trace.hoverFlag,
55                flagSelectedInfo: this.trace.selectFlag,
56                hoverX: fpsRow.hoverX,
57                hoverY: fpsRow.hoverY,
58                hoverFpsStruct: FpsStruct.hoverFpsStruct,
59                canvasWidth: fpsRow.canvasWidth,
60                canvasHeight: fpsRow.canvasHeight,
61                wakeupBean: CpuStruct.wakeupBean,
62                isRangeSelect: fpsRow.rangeSelect,
63                rangeSelectObject: TraceRow.rangeSelectObject,
64                useCache: useCache,
65                lineColor: fpsRow.getLineColor(),
66                startNS: TraceRow.range?.startNS || 0,
67                endNS: TraceRow.range?.endNS || 0,
68                totalNS: TraceRow.range?.totalNS || 0,
69                slicesTime: TraceRow.range?.slicesTime,
70                range: TraceRow.range,
71                frame: fpsRow.frame
72            }, !fpsRow.isTransferCanvas ? fpsRow.offscreen[0] : undefined, (res: any, hover: any) => {
73                fpsRow.must = false;
74                if (fpsRow.args.isOffScreen == true) {
75                    if (fpsRow.isHover) {
76                        FpsStruct.hoverFpsStruct = hover;
77                        this.trace.visibleRows.filter(it => it.rowType === TraceRow.ROW_TYPE_FPS && it.name !== fpsRow.name).forEach(it => it.draw(true));
78                    }
79                    return;
80                }
81            });
82            fpsRow.isTransferCanvas = true;
83        }
84        this.trace.rowsEL?.appendChild(fpsRow)
85        let durTime = new Date().getTime() - startTime;
86        info('The time to load the FPS data is: ', durTime)
87    }
88}