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