UNPKG

2.05 kBTypeScriptView Raw
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10type EventName = string | (() => string);
11type EventArgs = {[key: string]: string} | void | null;
12
13/**
14 * Indicates if the application is currently being traced.
15 *
16 * Calling methods on this module when the application isn't being traced is
17 * cheap, but this method can be used to avoid computing expensive values for
18 * those functions.
19 *
20 * @example
21 * if (Systrace.isEnabled()) {
22 * const expensiveArgs = computeExpensiveArgs();
23 * Systrace.beginEvent('myEvent', expensiveArgs);
24 * }
25 */
26export function isEnabled(): boolean;
27
28/**
29 * @deprecated This function is now a no-op but it's left for backwards
30 * compatibility. `isEnabled` will now synchronously check if we're actively
31 * profiling or not. This is necessary because we don't have callbacks to know
32 * when profiling has started/stopped on Android APIs.
33 */
34export function setEnabled(_doEnable: boolean): void;
35
36/**
37 * Marks the start of a synchronous event that should end in the same stack
38 * frame. The end of this event should be marked using the `endEvent` function.
39 */
40export function beginEvent(eventName: EventName, args?: EventArgs): void;
41
42/**
43 * Marks the end of a synchronous event started in the same stack frame.
44 */
45export function endEvent(args?: EventArgs): void;
46
47/**
48 * Marks the start of a potentially asynchronous event. The end of this event
49 * should be marked calling the `endAsyncEvent` function with the cookie
50 * returned by this function.
51 */
52export function beginAsyncEvent(eventName: EventName, args?: EventArgs): number;
53
54/**
55 * Registers a new value for a counter event.
56 */
57export function endAsyncEvent(
58 eventName: EventName,
59 cookie: number,
60 args?: EventArgs,
61): void;
62
63/**
64 * counterEvent registers the value to the eventName on the systrace timeline
65 **/
66export function counterEvent(eventName: EventName, value: number): void;
67
\No newline at end of file