• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2024 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License a
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from python.generators.diff_tests.testing import Csv, TextProto
17from python.generators.diff_tests.testing import DiffTestBlueprint
18from python.generators.diff_tests.testing import TestSuite
19
20class ParsingSysStats(TestSuite):
21
22  def test_cpuidle_stats(self):
23    return DiffTestBlueprint(
24        trace=TextProto(r"""
25        packet {
26          sys_stats {
27            cpuidle_state {
28              cpu_id: 0
29              cpuidle_state_entry {
30                state: "C8"
31                duration_us: 486626084
32              }
33            }
34          }
35          timestamp: 71625871363623
36          trusted_packet_sequence_id: 2
37        }
38        packet {
39          sys_stats {
40            cpuidle_state {
41              cpu_id: 0
42              cpuidle_state_entry {
43                state: "C8"
44                duration_us: 486636254
45              }
46            }
47          }
48          timestamp: 71626000387166
49          trusted_packet_sequence_id: 2
50        }
51        """),
52        query="""
53        SELECT
54          ts,
55          EXTRACT_ARG(t.dimension_arg_set_id, 'state') as state,
56          value,
57          EXTRACT_ARG(t.dimension_arg_set_id, 'cpu') as cpu
58        FROM counter c
59        JOIN track t on c.track_id = t.id
60        ORDER BY ts;
61        """,
62        out=Csv("""
63        "ts","state","value","cpu"
64        71625871363623,"C8",486626084.000000,0
65        71626000387166,"C8",486636254.000000,0
66        """))
67
68  def test_thermal_zones(self):
69    return DiffTestBlueprint(
70        trace=TextProto(r"""
71        packet {
72          sys_stats {
73            thermal_zone {
74              name: "thermal_zone0"
75              temp: 29
76              type: "x86_pkg_temp"
77            }
78          }
79          timestamp: 71625871363623
80          trusted_packet_sequence_id: 2
81        }
82        packet {
83          sys_stats {
84            thermal_zone {
85              name: "thermal_zone0"
86              temp: 31
87              type: "x86_pkg_temp"
88            }
89          }
90          timestamp: 71626000387166
91          trusted_packet_sequence_id: 2
92        }
93        """),
94        query="""
95        SELECT c.ts,
96               t.name,
97               c.value
98        FROM counter_track t
99        JOIN counter c ON t.id = c.track_id
100        """,
101        out=Csv("""
102        "ts","name","value"
103        71625871363623,"x86_pkg_temp",29.000000
104        71626000387166,"x86_pkg_temp",31.000000
105        """))
106
107  def test_gpufreq(self):
108    return DiffTestBlueprint(
109        trace=TextProto(r"""
110    packet {
111      sys_stats {
112        gpufreq_mhz: 300
113      }
114      timestamp: 115835063108
115      trusted_packet_sequence_id: 2
116    }
117    packet {
118      sys_stats {
119        gpufreq_mhz: 350
120      }
121      timestamp: 115900182490
122      trusted_packet_sequence_id: 2
123    }
124    """),
125        query="""
126    SELECT c.ts,
127            t.name,
128            c.value
129    FROM counter_track t
130    JOIN counter c ON t.id = c.track_id
131    """,
132        out=Csv("""
133    "ts","name","value"
134    115835063108,"gpufreq",300.000000
135    115900182490,"gpufreq",350.000000
136    """))
137