• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2023 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {TPTime} from '../common/time';
16
17import {globals} from './globals';
18
19// Type-safe aliases for various flavours of ints Trace Processor exposes
20// (e.g. timestamp or ids into a given SQL table) and functions to work with
21// them.
22//
23// These rely on TypeScript's type branding: extending a number with additional
24// compile-time-only type information, which prevents "implicit" conversions
25// between different ids.
26
27// Timestamp (in nanoseconds) in the same time domain as Trace Processor is
28// exposing.
29export type TPTimestamp = TPTime&{
30  __type: 'TPTimestamp'
31}
32
33export function asTPTimestamp(v: bigint): TPTimestamp;
34export function asTPTimestamp(v?: bigint): TPTimestamp|undefined;
35export function asTPTimestamp(v?: bigint): TPTimestamp|undefined {
36  return v as (TPTimestamp | undefined);
37}
38
39// TODO: unify this with common/time.ts.
40export function toTraceTime(ts: TPTimestamp): TPTime {
41  return ts - globals.state.traceTime.start;
42}
43
44// Unique id for a process, id into |process| table.
45export type Upid = number&{
46  __type: 'Upid'
47}
48
49export function asUpid(v: number): Upid;
50export function asUpid(v?: number): Upid|undefined;
51export function asUpid(v?: number): Upid|undefined {
52  return v as (Upid | undefined);
53}
54
55// Unique id for a thread, id into |thread| table.
56export type Utid = number&{
57  __type: 'Utid'
58}
59
60export function asUtid(v: number): Utid;
61export function asUtid(v?: number): Utid|undefined;
62export function asUtid(v?: number): Utid|undefined {
63  return v as (Utid | undefined);
64}
65
66// Id into |sched| SQL table.
67export type SchedSqlId = number&{
68  __type: 'SchedSqlId'
69}
70
71// Id into |thread_state| SQL table.
72export type ThreadStateSqlId = number&{
73  __type: 'ThreadStateSqlId'
74}
75