• 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 {SpHiPerf} from "./SpHiPerf.js";
18import {SpCpuChart} from "./SpCpuChart.js";
19import {SpFreqChart} from "./SpFreqChart.js";
20import {SpFpsChart} from "./SpFpsChart.js";
21import {
22    getCpuUtilizationRate, queryDataDICT,
23    queryTotalTime
24} from "../../database/SqlLite.js";
25import {info} from "../../../log/Log.js";
26import {SpNativeMemoryChart} from "./SpNativeMemoryChart.js";
27import {SpAbilityMonitorChart} from "./SpAbilityMonitorChart.js";
28import {SpProcessChart} from "./SpProcessChart.js";
29import {perfDataQuery} from "./PerfDataQuery.js";
30import {SpVirtualMemChart} from "./SpVirtualMemChart.js";
31import {SpFileSystemChart} from "./SpFileSystemChart.js";
32import {procedurePool} from "../../database/Procedure.js";
33import {SpSdkChart} from "./SpSdkChart.js";
34import {SpHiSysEventChart} from "./SpHiSysEventChart.js";
35import {SmpsChart} from "./SmpsChart.js";
36
37export class SpChartManager {
38    private trace: SpSystemTrace;
39    public perf: SpHiPerf;
40    private cpu: SpCpuChart;
41    private freq: SpFreqChart;
42    private virtualMemChart:SpVirtualMemChart;
43    private fps: SpFpsChart
44    private nativeMemory: SpNativeMemoryChart;
45    private abilityMonitor: SpAbilityMonitorChart;
46    private process: SpProcessChart;
47    private fileSystem: SpFileSystemChart;
48    private sdkChart: SpSdkChart;
49    private hiSyseventChart: SpHiSysEventChart;
50    private smpsChart:SmpsChart;
51
52    constructor(trace: SpSystemTrace) {
53        this.trace = trace;
54        this.perf = new SpHiPerf(trace);
55        this.fileSystem = new SpFileSystemChart(trace);
56        this.cpu = new SpCpuChart(trace);
57        this.freq = new SpFreqChart(trace);
58        this.virtualMemChart = new SpVirtualMemChart(trace);
59        this.fps = new SpFpsChart(trace);
60        this.nativeMemory = new SpNativeMemoryChart(trace);
61        this.abilityMonitor = new SpAbilityMonitorChart(trace);
62        this.process = new SpProcessChart(trace);
63        this.sdkChart = new SpSdkChart(trace);
64        this.hiSyseventChart = new SpHiSysEventChart(trace);
65        this.smpsChart = new SmpsChart(trace);
66    }
67
68    async init(progress:Function){
69        progress("load data dict", 50);
70        SpSystemTrace.DATA_DICT.clear();
71        let dict = await queryDataDICT();
72        dict.map((d) => SpSystemTrace.DATA_DICT.set(d['id'], d['data']));
73        progress("time range", 65);
74        await this.initTotalTime();
75        info("timerShaftEL Data initialized")
76        progress("cpu", 70);
77        await this.cpu.init();
78        info("cpu Data initialized")
79        progress("process", 73);
80        await this.cpu.initProcessThreadStateData(progress);
81        info("ProcessThreadState Data initialized")
82        progress("cpu rate", 75);
83        await this.initCpuRate();
84        info("Cpu Rate Data initialized")
85        progress("cpu freq", 80);
86        await this.freq.init();
87        info("Cpu Freq Data initialized")
88        await this.virtualMemChart.init();
89        progress("fps", 85);
90        await this.fps.init();
91        info("FPS Data initialized")
92        progress("native memory", 86);
93        await this.nativeMemory.initNativeMemory()
94        progress("native memory", 87);
95        await this.nativeMemory.initChart();
96        info("Native Memory Data initialized")
97        progress("ability monitor", 88);
98        await this.abilityMonitor.init();
99        progress("hiSysevent", 88.2);
100        await this.hiSyseventChart.init();
101        info("Perf Files Data initialized")
102        progress("vm tracker", 88.4);
103        await this.smpsChart.init();
104        progress("sdk", 88.6);
105        await this.sdkChart.init();
106        progress("perf", 88.8);
107        await this.perf!.init();
108        progress("file system", 89);
109        await this.fileSystem!.init();
110        info("Ability Monitor Data initialized")
111        await perfDataQuery.initPerfCache()
112        info("HiPerf Data initialized")
113        progress("process", 90);
114        await this.process.initAsyncFuncData()
115        await this.process.init();
116        info("Process Data initialized")
117        progress("display", 95);
118    }
119
120    initTotalTime = async () => {
121        let res = await queryTotalTime();
122        if (this.trace.timerShaftEL) {
123            this.trace.timerShaftEL.totalNS = res[0].total;
124            (window as any).recordStartNS = res[0].recordStartNS;
125            (window as any).recordEndNS = res[0].recordEndNS;
126            this.trace.timerShaftEL.loadComplete = true;
127        }
128    }
129
130    initCpuRate = async () => {
131        let rates = await getCpuUtilizationRate(0, this.trace.timerShaftEL?.totalNS || 0);
132        if (this.trace.timerShaftEL) this.trace.timerShaftEL.cpuUsage = rates;
133        info("Cpu UtilizationRate data size is: ", rates.length)
134    }
135
136}