• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 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 at
7--
8--     https://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
16INCLUDE PERFETTO MODULE prelude.after_eof.casts;
17
18-- Counters are values put into tracks during parsing of the trace.
19CREATE PERFETTO VIEW counter (
20  -- Unique id of a counter value
21  id ID,
22  -- Time of fetching the counter value.
23  ts TIMESTAMP,
24  -- Track this counter value belongs to.
25  track_id JOINID(track.id),
26  -- Value.
27  value DOUBLE,
28  -- Additional information about the counter value.
29  arg_set_id ARGSETID
30) AS
31SELECT
32  id,
33  ts,
34  track_id,
35  value,
36  arg_set_id
37FROM __intrinsic_counter;
38
39-- Contains slices from userspace which explains what threads were doing
40-- during the trace.
41CREATE PERFETTO VIEW slice (
42  -- The id of the slice.
43  id ID,
44  -- The timestamp at the start of the slice in nanoseconds. The actual value
45  -- depends on the `primary_trace_clock` selected in TraceConfig. This is often
46  -- the value of a monotonic counter since device boot so is only meaningful in
47  -- the context of a trace.
48  ts TIMESTAMP,
49  -- The duration of the slice in nanoseconds.
50  dur DURATION,
51  -- The id of the track this slice is located on.
52  track_id JOINID(track.id),
53  -- The "category" of the slice. If this slice originated with track_event,
54  -- this column contains the category emitted.
55  -- Otherwise, it is likely to be null (with limited exceptions).
56  category STRING,
57  -- The name of the slice. The name describes what was happening during the
58  -- slice.
59  name STRING,
60  -- The depth of the slice in the current stack of slices.
61  depth LONG,
62  -- A unique identifier obtained from the names of all slices in this stack.
63  -- This is rarely useful and kept around only for legacy reasons.
64  stack_id LONG,
65  -- The stack_id for the parent of this slice. Rarely useful.
66  parent_stack_id LONG,
67  -- The id of the parent (i.e. immediate ancestor) slice for this slice.
68  parent_id JOINID(slice.id),
69  -- The id of the argument set associated with this slice.
70  arg_set_id ARGSETID,
71  -- The thread timestamp at the start of the slice. This column will only be
72  -- populated if thread timestamp collection is enabled with track_event.
73  thread_ts TIMESTAMP,
74  -- The thread time used by this slice. This column will only be populated if
75  -- thread timestamp collection is enabled with track_event.
76  thread_dur DURATION,
77  -- The value of the CPU instruction counter at the start of the slice. This
78  -- column will only be populated if thread instruction collection is enabled
79  -- with track_event.
80  thread_instruction_count LONG,
81  -- The change in value of the CPU instruction counter between the start and
82  -- end of the slice. This column will only be populated if thread instruction
83  -- collection is enabled with track_event.
84  thread_instruction_delta LONG,
85  -- Alias of `category`.
86  cat STRING,
87  -- Alias of `id`.
88  slice_id JOINID(slice.id)
89) AS
90SELECT
91  *,
92  category AS cat,
93  id AS slice_id
94FROM __intrinsic_slice;
95
96-- Contains instant events from userspace which indicates what happened at a
97-- single moment in time.
98CREATE PERFETTO VIEW instant (
99  -- The timestamp of the instant.
100  ts TIMESTAMP,
101  -- The id of the track this instant is located on.
102  track_id JOINID(track.id),
103  -- The name of the instant. The name describes what happened during the
104  -- instant.
105  name STRING,
106  -- The id of the argument set associated with this instant.
107  arg_set_id ARGSETID
108) AS
109SELECT
110  ts,
111  track_id,
112  name,
113  arg_set_id
114FROM slice
115WHERE
116  dur = 0;
117
118-- Alternative alias of table `slice`.
119CREATE PERFETTO VIEW slices (
120  -- Alias of `slice.id`.
121  id JOINID(slice.id),
122  -- Alias of `slice.ts`.
123  ts TIMESTAMP,
124  -- Alias of `slice.dur`.
125  dur DURATION,
126  -- Alias of `slice.track_id`.
127  track_id JOINID(track.id),
128  -- Alias of `slice.category`.
129  category STRING,
130  -- Alias of `slice.name`.
131  name STRING,
132  -- Alias of `slice.depth`.
133  depth LONG,
134  -- Alias of `slice.stack_id`.
135  stack_id LONG,
136  -- Alias of `slice.parent_stack_id`.
137  parent_stack_id LONG,
138  -- Alias of `slice.parent_id`.
139  parent_id JOINID(slice.id),
140  -- Alias of `slice.arg_set_id`.
141  arg_set_id ARGSETID,
142  -- Alias of `slice.thread_ts`.
143  thread_ts TIMESTAMP,
144  -- Alias of `slice.thread_dur`.
145  thread_dur DURATION,
146  -- Alias of `slice.thread_instruction_count`.
147  thread_instruction_count LONG,
148  -- Alias of `slice.thread_instruction_delta`.
149  thread_instruction_delta LONG,
150  -- Alias of `slice.cat`.
151  cat STRING,
152  -- Alias of `slice.slice_id`.
153  slice_id JOINID(slice.id)
154) AS
155SELECT
156  *
157FROM slice;
158
159-- Contains information of threads seen during the trace.
160CREATE PERFETTO VIEW thread (
161  -- The id of the thread. Prefer using `utid` instead.
162  id ID,
163  -- Unique thread id. This is != the OS tid. This is a monotonic number
164  -- associated to each thread. The OS thread id (tid) cannot be used as primary
165  -- key because tids and pids are recycled by most kernels.
166  utid ID,
167  -- The OS id for this thread. Note: this is *not* unique over the lifetime of
168  -- the trace so cannot be used as a primary key. Use |utid| instead.
169  tid LONG,
170  -- The name of the thread. Can be populated from many sources (e.g. ftrace,
171  -- /proc scraping, track event etc).
172  name STRING,
173  -- The start timestamp of this thread (if known). Is null in most cases unless
174  -- a thread creation event is enabled (e.g. task_newtask ftrace event on
175  -- Linux/Android).
176  start_ts TIMESTAMP,
177  -- The end timestamp of this thread (if known). Is null in most cases unless
178  -- a thread destruction event is enabled (e.g. sched_process_free ftrace event
179  -- on Linux/Android).
180  end_ts TIMESTAMP,
181  -- The process hosting this thread.
182  upid JOINID(process.id),
183  -- Boolean indicating if this thread is the main thread in the process.
184  is_main_thread BOOL,
185  -- Boolean indicating if this thread is a kernel idle thread.
186  is_idle BOOL,
187  -- Machine identifier, non-null for threads on a remote machine.
188  machine_id LONG
189) AS
190SELECT
191  id AS utid,
192  *
193FROM __intrinsic_thread;
194
195-- Contains information of processes seen during the trace.
196CREATE PERFETTO VIEW process (
197  -- The id of the process. Prefer using `upid` instead.
198  id ID,
199  -- Unique process id. This is != the OS pid. This is a monotonic number
200  -- associated to each process. The OS process id (pid) cannot be used as
201  -- primary key because tids and pids are recycled by most kernels.
202  upid JOINID(process.id),
203  -- The OS id for this process. Note: this is *not* unique over the lifetime of
204  -- the trace so cannot be used as a primary key. Use |upid| instead.
205  pid LONG,
206  -- The name of the process. Can be populated from many sources (e.g. ftrace,
207  -- /proc scraping, track event etc).
208  name STRING,
209  -- The start timestamp of this process (if known). Is null in most cases
210  -- unless a process creation event is enabled (e.g. task_newtask ftrace event
211  -- on Linux/Android).
212  start_ts TIMESTAMP,
213  -- The end timestamp of this process (if known). Is null in most cases unless
214  -- a process destruction event is enabled (e.g. sched_process_free ftrace
215  -- event on Linux/Android).
216  end_ts TIMESTAMP,
217  -- The upid of the process which caused this process to be spawned.
218  parent_upid JOINID(process.id),
219  -- The Unix user id of the process.
220  uid LONG,
221  -- Android appid of this process.
222  android_appid LONG,
223  -- Android user id of this process.
224  android_user_id LONG,
225  -- /proc/cmdline for this process.
226  cmdline STRING,
227  -- Extra args for this process.
228  arg_set_id ARGSETID,
229  -- Machine identifier, non-null for processes on a remote machine.
230  machine_id LONG
231) AS
232SELECT
233  id AS upid,
234  *
235FROM __intrinsic_process;
236
237-- Arbitrary key-value pairs which allow adding metadata to other, strongly
238-- typed tables.
239-- Note: for a given row, only one of |int_value|, |string_value|, |real_value|
240-- will be non-null.
241CREATE PERFETTO VIEW args (
242  -- The id of the arg.
243  id ID,
244  -- The id for a single set of arguments.
245  arg_set_id ARGSETID,
246  -- The "flat key" of the arg: this is the key without any array indexes.
247  flat_key STRING,
248  -- The key for the arg.
249  key STRING,
250  -- The integer value of the arg.
251  int_value LONG,
252  -- The string value of the arg.
253  string_value STRING,
254  -- The double value of the arg.
255  real_value DOUBLE,
256  -- The type of the value of the arg. Will be one of 'int', 'uint', 'string',
257  -- 'real', 'pointer', 'bool' or 'json'.
258  value_type STRING,
259  -- The human-readable formatted value of the arg.
260  display_value STRING
261) AS
262SELECT
263  *,
264  -- This should be kept in sync with GlobalArgsTracker::AddArgSet.
265  CASE value_type
266    WHEN 'int'
267    THEN cast_string!(int_value)
268    WHEN 'uint'
269    THEN cast_string!(int_value)
270    WHEN 'string'
271    THEN string_value
272    WHEN 'real'
273    THEN cast_string!(real_value)
274    WHEN 'pointer'
275    THEN printf('0x%x', int_value)
276    WHEN 'bool'
277    THEN (
278      CASE WHEN int_value != 0 THEN 'true' ELSE 'false' END
279    )
280    WHEN 'json'
281    THEN string_value
282    ELSE NULL
283  END AS display_value
284FROM __intrinsic_args;
285
286-- Contains the Linux perf sessions in the trace.
287CREATE PERFETTO VIEW perf_session (
288  -- The id of the perf session. Prefer using `perf_session_id` instead.
289  id LONG,
290  -- The id of the perf session.
291  perf_session_id LONG,
292  -- Command line used to collect the data.
293  cmdline STRING
294) AS
295SELECT
296  *,
297  id AS perf_session_id
298FROM __intrinsic_perf_session;
299
300-- Log entries from Android logcat.
301--
302-- NOTE: this table is not sorted by timestamp.
303CREATE PERFETTO VIEW android_logs (
304  -- Which row in the table the log corresponds to.
305  id ID,
306  -- Timestamp of log entry.
307  ts TIMESTAMP,
308  -- Thread writing the log entry.
309  utid JOINID(thread.id),
310  -- Priority of the log. 3=DEBUG, 4=INFO, 5=WARN, 6=ERROR.
311  prio LONG,
312  -- Tag of the log entry.
313  tag STRING,
314  -- Content of the log entry
315  msg STRING
316) AS
317SELECT
318  id,
319  ts,
320  utid,
321  prio,
322  tag,
323  msg
324FROM __intrinsic_android_logs;
325