• 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
16-- Returns the provided nanosecond duration, which is the default
17-- representation of time durations in trace processor. Provided for
18-- consistency with other functions.
19CREATE PERFETTO FUNCTION time_from_ns(
20    -- Time duration in nanoseconds.
21    nanos LONG
22)
23-- Time duration in nanoseconds.
24RETURNS TIMESTAMP AS
25SELECT
26  $nanos;
27
28-- Converts a duration in microseconds to nanoseconds, which is the default
29-- representation of time durations in trace processor.
30CREATE PERFETTO FUNCTION time_from_us(
31    -- Time duration in microseconds.
32    micros LONG
33)
34-- Time duration in nanoseconds.
35RETURNS LONG AS
36SELECT
37  $micros * 1000;
38
39-- Converts a duration in millseconds to nanoseconds, which is the default
40-- representation of time durations in trace processor.
41CREATE PERFETTO FUNCTION time_from_ms(
42    -- Time duration in milliseconds.
43    millis LONG
44)
45-- Time duration in nanoseconds.
46RETURNS TIMESTAMP AS
47SELECT
48  $millis * 1000 * 1000;
49
50-- Converts a duration in seconds to nanoseconds, which is the default
51-- representation of time durations in trace processor.
52CREATE PERFETTO FUNCTION time_from_s(
53    -- Time duration in seconds.
54    seconds LONG
55)
56-- Time duration in nanoseconds.
57RETURNS TIMESTAMP AS
58SELECT
59  $seconds * 1000 * 1000 * 1000;
60
61-- Converts a duration in minutes to nanoseconds, which is the default
62-- representation of time durations in trace processor.
63CREATE PERFETTO FUNCTION time_from_min(
64    -- Time duration in minutes.
65    minutes LONG
66)
67-- Time duration in nanoseconds.
68RETURNS TIMESTAMP AS
69SELECT
70  $minutes * 60 * 1000 * 1000 * 1000;
71
72-- Converts a duration in hours to nanoseconds, which is the default
73-- representation of time durations in trace processor.
74CREATE PERFETTO FUNCTION time_from_hours(
75    -- Time duration in hours.
76    hours LONG
77)
78-- Time duration in nanoseconds.
79RETURNS TIMESTAMP AS
80SELECT
81  $hours * 60 * 60 * 1000 * 1000 * 1000;
82
83-- Converts a duration in days to nanoseconds, which is the default
84-- representation of time durations in trace processor.
85CREATE PERFETTO FUNCTION time_from_days(
86    -- Time duration in days.
87    days LONG
88)
89-- Time duration in nanoseconds.
90RETURNS LONG AS
91SELECT
92  $days * 24 * 60 * 60 * 1000 * 1000 * 1000;
93
94-- Returns the provided nanosecond duration, which is the default
95-- representation of time durations in trace processor. Provided for
96-- consistency with other functions.
97CREATE PERFETTO FUNCTION time_to_ns(
98    -- Time duration in nanoseconds.
99    nanos TIMESTAMP
100)
101-- Time duration in nanoseconds.
102RETURNS LONG AS
103SELECT
104  $nanos;
105
106-- Converts a duration in nanoseconds to microseconds. Nanoseconds is the default
107-- representation of time durations in trace processor.
108CREATE PERFETTO FUNCTION time_to_us(
109    -- Time duration in nanoseconds.
110    nanos TIMESTAMP
111)
112-- Time duration in microseconds.
113RETURNS LONG AS
114SELECT
115  $nanos / 1000;
116
117-- Converts a duration in nanoseconds to millseconds. Nanoseconds is the default
118-- representation of time durations in trace processor.
119CREATE PERFETTO FUNCTION time_to_ms(
120    -- Time duration in nanoseconds.
121    nanos TIMESTAMP
122)
123-- Time duration in milliseconds.
124RETURNS LONG AS
125SELECT
126  $nanos / (
127    1000 * 1000
128  );
129
130-- Converts a duration in nanoseconds to seconds. Nanoseconds is the default
131-- representation of time durations in trace processor.
132CREATE PERFETTO FUNCTION time_to_s(
133    -- Time duration in nanoseconds.
134    nanos TIMESTAMP
135)
136-- Time duration in seconds.
137RETURNS LONG AS
138SELECT
139  $nanos / (
140    1000 * 1000 * 1000
141  );
142
143-- Converts a duration in nanoseconds to minutes. Nanoseconds is the default
144-- representation of time durations in trace processor.
145CREATE PERFETTO FUNCTION time_to_min(
146    -- Time duration in nanoseconds.
147    nanos TIMESTAMP
148)
149-- Time duration in minutes.
150RETURNS LONG AS
151SELECT
152  $nanos / (
153    60 * 1000 * 1000 * 1000
154  );
155
156-- Converts a duration in nanoseconds to hours. Nanoseconds is the default
157-- representation of time durations in trace processor.
158CREATE PERFETTO FUNCTION time_to_hours(
159    -- Time duration in nanoseconds.
160    nanos TIMESTAMP
161)
162-- Time duration in hours.
163RETURNS LONG AS
164SELECT
165  $nanos / (
166    60 * 60 * 1000 * 1000 * 1000
167  );
168
169-- Converts a duration in nanoseconds to days. Nanoseconds is the default
170-- representation of time durations in trace processor.
171CREATE PERFETTO FUNCTION time_to_days(
172    -- Time duration in nanoseconds.
173    nanos TIMESTAMP
174)
175-- Time duration in days.
176RETURNS LONG AS
177SELECT
178  $nanos / (
179    24 * 60 * 60 * 1000 * 1000 * 1000
180  );
181