• 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 */
15import {query} from "../SqlLite";
16import {ClockStruct} from "../ui-worker/ProcedureWorkerClock";
17
18export const queryClockData = (): Promise<
19  Array<{
20    name: string;
21    num: number;
22    srcname: string;
23  }>
24> =>
25  query(
26    'queryClockData',
27    `
28    select name || ' Frequency' name, COUNT(*) num, name srcname
29from (select id, name
30      from clock_event_filter
31      where type = 'clock_set_rate')
32group by name
33union
34select name || ' State' name, COUNT(*) num, name srcname
35from (select id, name
36      from clock_event_filter
37      where type != 'clock_set_rate')
38group by name;
39`
40  );
41
42export const queryClockFrequency = (clockName: string): Promise<Array<ClockStruct>> =>
43  query(
44    'queryClockFrequency',
45    `with freq as (  select measure.filter_id, measure.ts, measure.type, measure.value from clock_event_filter
46left join measure
47where clock_event_filter.name = $clockName and clock_event_filter.type = 'clock_set_rate' and clock_event_filter.id = measure.filter_id
48order by measure.ts)
49select freq.filter_id as filterId,freq.ts - r.start_ts as startNS,freq.type,freq.value from freq,trace_range r order by startNS`,
50    { $clockName: clockName }
51  );
52
53export const queryClockState = (clockName: string): Promise<Array<ClockStruct>> =>
54  query(
55    'queryClockState',
56    `with state as (
57select filter_id, ts, endts, endts-ts as dur, type, value from
58(select measure.filter_id, measure.ts, lead(ts, 1, null) over( order by measure.ts) endts, measure.type, measure.value from clock_event_filter,trace_range
59left join measure
60where clock_event_filter.name = $clockName and clock_event_filter.type != 'clock_set_rate' and clock_event_filter.id = measure.filter_id
61order by measure.ts))
62select s.filter_id as filterId,s.ts-r.start_ts as startNS,s.type,s.value,s.dur from state s,trace_range r`,
63    { $clockName: clockName }
64  );
65export const queryBootTime = (): Promise<Array<any>> =>
66  query(
67    'queryBootTime',
68    `select CS.ts -TR.start_ts as ts ,clock_name from clock_snapshot as CS ,trace_range as TR
69      where clock_name = 'boottime'`,
70    {}
71  );
72export const queryScreenState = (): Promise<Array<ClockStruct>> =>
73  query(
74    'queryScreenState',
75    `select m.type, m.ts-r.start_ts as startNS, value, filter_id  as filterId from measure m,trace_range r where filter_id in (select id from process_measure_filter where name = 'ScreenState')  order by startNS;
76`
77  );
78export const queryRealTime = (): Promise<
79  Array<{
80    ts: number;
81  }>
82> => query('queryRealTime', `select CS.ts as ts from clock_snapshot as CS where clock_name = 'realtime';`);
83