• 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 { XpowerComponentTopStruct } from '../../component/trace/sheet/xpower/TabPaneXpowerComponentTop';
17import { query } from '../SqlLite';
18export const queryXpowerMeasureData = (traceId?: string): Promise<
19  Array<{
20    filter_id: number;
21  }>
22> =>
23  query(
24    'queryXpowerMeasureData',
25    `
26    select
27        name
28    from
29        measure_filter mf
30    where
31        mf.type = 'xpower_filter'
32;
33`, {}, { traceId: traceId }
34  );
35
36export const queryXpowerData = (traceId?: string): Promise<
37  Array<{
38    name: string;
39    num: number;
40    maxValue: number;
41    minValue: number;
42  }>
43> =>
44  query(
45    'queryXpowerData',
46    `
47      select
48        name,
49        COUNT(*) num,
50                max(value) maxValue,
51                min(value) minValue
52      from
53        measure_filter mf
54      left join
55        xpower_measure xm
56      on
57        mf.id = xm.filter_id
58      where
59        mf.type = 'xpower_filter'
60      group by name
61;
62`, {}, { traceId: traceId }
63  );
64
65export const queryTraceConfig = (traceId?: string): Promise<
66  Array<{
67    traceSource: string;
68    key: string;
69    value: string;
70  }>
71> =>
72  query(
73    'queryTraceConfig',
74    `
75    select
76      trace_source as traceSource,
77      key,
78      value
79    from
80      trace_config;
81;
82`, {}, { traceId: traceId }
83  );
84
85export const queryXpowerComponentTop = (leftNS: number, rightNS: number, dur: number, traceId?: string): Promise<
86  Array<XpowerComponentTopStruct>
87> =>
88  query(
89    'queryXpowerComponentTop',
90    `
91    select
92        (start_time - tr.start_ts) as startNS,
93        component_type_id as componentTypeId,
94        appname as appName,
95        background_duration as backgroundDuration,
96        background_energy as backgroundEnergy,
97        foreground_duration as foregroundDuration,
98        foreground_energy as foregroundEnergy,
99        screen_off_duration as screenOffDuration,
100        screen_off_energy as screenOffEnergy,
101        screen_on_duration as screenOnDuration,
102        screen_on_energy as screenOnEnergy,
103        camera_id as cameraId,
104        uid as uId,
105        load,
106        app_usage_duration as appUsageDuration,
107        app_usage_energy as appUsageEnergy
108    from
109      xpower_component_top,
110      trace_range as tr
111    where
112      $leftNS <= startNS + ${dur} and $rightNS >= startNS
113    `, { $leftNS: leftNS, $rightNS: rightNS, traceId: traceId }
114);
115
116export const queryFreq = (traceId?: string): Promise<Array<{ frequency: number }>> =>
117  query(
118    'queryTraceConfig',
119    `
120  select
121    frequency
122  from
123    xpower_app_detail_gpu
124  order by
125    frequency
126`,
127    {},
128    { traceId: traceId }
129  );