• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2025 Huawei Device Co., Ltd.
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 */
15
16export interface PerfProbe {
17    /**
18     * The name of the probe.
19     */
20    readonly name: string;
21    /**
22     * Whether this is a dummy probe which does not measure (a noop).
23     *
24     * @see MainPerfProbe.getProbe
25     */
26    readonly dummy: boolean;
27    /**
28     * Exists the probe.
29     *
30     * @param log log the gathered statistics.
31     * @see MainPerfProbe.enterProbe
32     */
33    exit(log: boolean | undefined): void;
34    /**
35     * Cancels measuring the probe and its children probes.
36     */
37    cancel(): void;
38    /**
39     * User-defined data associated with the probe.
40     */
41    userData: string | undefined;
42    /**
43     * Whether the probe was canceled.
44     */
45    readonly canceled: boolean;
46}
47/**
48 * The main (root) {@link PerfProbe}.
49 *
50 * This probe is used to enter the main activity.
51 *
52 * Calling {@link PerfProbe.cancel} removes the main probe and disposes all its resources.
53 *
54 * Calling {@link PerfProbe.exit} exits the main probe, cancels it and when the log option is provided
55 * logs the gathered statistics.
56 *
57 * @see enterMainPerfProbe
58 * @see getMainPerfProbe
59 */
60export interface MainPerfProbe extends PerfProbe {
61    /**
62     * Enters a child probe referenced by the {@link name} and measures it.
63     * If the probe does not exist, returns a dummy instance.
64     *
65     * If the probe already performs a recursive call is counted.
66     *
67     * @see PerfProbe.exit
68     * @see exitProbe
69     */
70    enterProbe(name: string): PerfProbe;
71    /**
72     * Exits a child probe referenced by the {@link name}.
73     * If the probe does not exist, returns a dummy instance.
74     *
75     * This is an equivalent of calling {@link getProbe} and then {@link PerfProbe.exit}.
76     */
77    exitProbe(name: string): PerfProbe;
78    /**
79     * Returns the child probe referenced by the {@link name} if it exists,
80     * otherwise a dummy instance.
81     *
82     * @see PerfProbe.dummy
83     */
84    getProbe(name: string): PerfProbe;
85    /**
86     * Performs the {@link func} of a child probe referenced by the {@link name} and measures it.
87     *
88     * This is an equivalent of calling {@link enterProbe} and then {@link exitProbe}.
89     *
90     * If the probe already performs a recursive call is counted.
91     */
92    performProbe<T>(name: string, func: () => T): T;
93    /**
94     * Returns true if the probe referenced by the {@link name} has been performed
95     * (entered and exited all the recursive calls).
96     */
97    probePerformed(name: string): boolean;
98}
99/**
100 * Creates a {@link MainPerfProbe} instance with the {@link name} and enters its main probe.
101 *
102 * If a {@link MainPerfProbe} with this {@link name} already exists then it is canceled and the new one is created.
103 *
104 * Exit it with {@link MainPerfProbe.exit}.
105 */
106export declare function enterMainPerfProbe(name: string): MainPerfProbe;
107/**
108 * Returns {@link MainPerfProbe} instance with the {@link name} if it exists,
109 * otherwise a dummy instance.
110 *
111 * @see MainPerfProbe.dummy
112 */
113export declare function getMainPerfProbe(name: string): MainPerfProbe;
114//# sourceMappingURL=PerfProbe.d.ts.map