• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2023 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 Path, DataPath, Metric
17from python.generators.diff_tests.testing import Csv, Json, TextProto
18from python.generators.diff_tests.testing import DiffTestBlueprint
19from python.generators.diff_tests.testing import TestSuite
20
21
22class LinuxStdlib(TestSuite):
23
24  def test_linux_cpu_idle_stats(self):
25      return DiffTestBlueprint(
26          trace=TextProto(r"""
27          packet {
28            ftrace_events {
29              cpu: 0
30              event: {
31                timestamp: 200000000000
32                pid: 2
33                cpu_frequency: {
34                  state : 1704000
35                  cpu_id: 0
36                }
37              }
38              event: {
39                timestamp: 200000000000
40                pid: 2
41                cpu_idle: {
42                  state: 4294967295
43                  cpu_id: 0
44                }
45              }
46              event {
47                timestamp: 200001000000
48                pid: 2
49                cpu_idle: {
50                  state : 1
51                  cpu_id: 0
52                }
53              }
54              event: {
55                timestamp: 200002000000
56                pid  : 2
57                cpu_idle: {
58                  state : 4294967295
59                  cpu_id: 0
60                }
61              }
62              event {
63                timestamp: 200003000000
64                pid: 2
65                cpu_idle: {
66                  state : 1
67                  cpu_id: 0
68                }
69              }
70              event: {
71                timestamp: 200004000000
72                pid: 2
73                cpu_idle: {
74                  state : 4294967295
75                  cpu_id: 0
76                }
77              }
78              event: {
79                timestamp: 200005000000
80                pid: 2
81                cpu_frequency: {
82                  state: 300000
83                  cpu_id: 0
84                }
85              }
86            }
87            trusted_uid: 9999
88            trusted_packet_sequence_id: 2
89          }
90         """),
91         query="""
92         INCLUDE PERFETTO MODULE linux.cpu_idle;
93         SELECT * FROM linux_cpu_idle_stats;
94         """,
95         out=Csv("""
96         "cpu","state","count","dur","avg_dur","idle_percent"
97         0,2,2,2000000,1000000,50.000013
98         """))
99
100