• 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 {queryCpuData, queryCpuMax} from "../../database/SqlLite.js";
18import {info} from "../../../log/Log.js";
19import {CpuStruct} from "../../bean/CpuStruct.js";
20import {TraceRow} from "../trace/base/TraceRow.js";
21import {procedurePool} from "../../database/Procedure.js";
22
23export class SpCpuChart {
24    private trace: SpSystemTrace;
25    constructor(trace: SpSystemTrace) {
26        this.trace = trace;
27    }
28
29    async init() {
30        let CpuStartTime = new Date().getTime();
31        let array = await queryCpuMax();
32        info("Cpu trace row data size is: ", array.length)
33        if (array && array.length > 0 && array[0]) {
34            let cpuMax = array[0].cpu
35            CpuStruct.cpuCount = cpuMax + 1;
36            for (let i1 = 0; i1 < CpuStruct.cpuCount; i1++) {
37                const cpuId = i1;
38                let traceRow = new TraceRow<CpuStruct>();
39                traceRow.rowId = `${cpuId}`
40                traceRow.rowType = TraceRow.ROW_TYPE_CPU
41                traceRow.rowParentId = ''
42                traceRow.style.height = '40px'
43                traceRow.name = `Cpu ${cpuId}`
44                traceRow.favoriteChangeHandler = this.trace.favoriteChangeHandler;
45                traceRow.selectChangeHandler = this.trace.selectChangeHandler;
46                traceRow.supplier = () => queryCpuData(cpuId, TraceRow.range?.startNS || 0, TraceRow.range?.endNS || 0)
47                traceRow.onThreadHandler = ((useCache: boolean, buf: ArrayBuffer | undefined | null) => {
48                    procedurePool.submitWithName(`cpu${cpuId % procedurePool.cpusLen.length}`, `cpu-data-${cpuId}`, {
49                        list: traceRow.must ? traceRow.dataList : undefined,
50                        offscreen: !traceRow.isTransferCanvas ? traceRow.offscreen[0] : undefined,//是否离屏
51                        dpr: traceRow.dpr,//屏幕dpr值
52                        xs: TraceRow.range?.xs,//线条坐标信息
53                        isHover: traceRow.isHover,
54                        flagMoveInfo: this.trace.hoverFlag,
55                        flagSelectedInfo: this.trace.selectFlag,
56                        hoverX: traceRow.hoverX,
57                        hoverY: traceRow.hoverY,
58                        canvasWidth: traceRow.canvasWidth,
59                        canvasHeight: traceRow.canvasHeight,
60                        hoverCpuStruct: CpuStruct.hoverCpuStruct,
61                        selectCpuStruct: CpuStruct.selectCpuStruct,
62                        wakeupBean: CpuStruct.wakeupBean,
63                        isRangeSelect: traceRow.rangeSelect,
64                        rangeSelectObject: TraceRow.rangeSelectObject,
65                        useCache: useCache,
66                        lineColor: traceRow.getLineColor(),
67                        startNS: TraceRow.range?.startNS || 0,
68                        endNS: TraceRow.range?.endNS || 0,
69                        totalNS: TraceRow.range?.totalNS || 0,
70                        slicesTime: TraceRow.range?.slicesTime,
71                        range: TraceRow.range,
72                        frame: traceRow.frame
73                    }, traceRow.getTransferArray(), (res: any, hover: any) => {
74                        traceRow.must = false;
75                        if (traceRow.isHover) {
76                            CpuStruct.hoverCpuStruct = hover;
77                            if (TraceRow.range) TraceRow.range.refresh = false;
78                            this.trace.visibleRows.filter(it => it.rowType === TraceRow.ROW_TYPE_CPU && it.name !== traceRow.name).forEach(it => it.draw(true));
79                        }
80                    })
81                    traceRow.isTransferCanvas = true;
82                })
83                this.trace.rowsEL?.appendChild(traceRow);
84
85            }
86        }
87        let CpuDurTime = new Date().getTime() - CpuStartTime;
88        info('The time to load the Cpu data is: ', CpuDurTime)
89    }
90
91    initProcessThreadStateData = async (progress: Function) => {
92        let time = new Date().getTime();
93        SpSystemTrace.SPT_DATA = [];
94        progress("StateProcessThread", 93);
95        procedurePool.submitWithName("logic1","spt-init",{},undefined,(res:any)=>{
96            SpSystemTrace.SPT_DATA = Array.from(res);
97        })
98        let durTime = new Date().getTime() - time;
99        info('The time to load the first ProcessThreadState data is: ', durTime)
100    }
101}