1 | /**
|
2 | * Contains contains utility methods for profiling.
|
3 | * All methods in this module are experimental and may be changed in a non-major version.
|
4 | */
|
5 |
|
6 | interface TimerInfo {
|
7 | totalTime: number;
|
8 | count: number;
|
9 | }
|
10 |
|
11 | /**
|
12 | * Profiling mode to use.
|
13 | * - `counters` Accumulates method call counts and times until dumpProfiles is called and then prints aggregated statistic in the console. This is the default.
|
14 | * - `timeline` Outputs method names along start/end timestamps in the console on the go.
|
15 | * - `lifecycle` Outputs basic non-verbose times for startup, navigation, etc.
|
16 | */
|
17 | type InstrumentationMode = 'counters' | 'timeline' | 'lifecycle';
|
18 |
|
19 | /**
|
20 | * Logging levels in order of verbosity.
|
21 | */
|
22 | export enum Level {
|
23 | none,
|
24 | lifecycle,
|
25 | timeline,
|
26 | }
|
27 |
|
28 | /**
|
29 | * Get the current logging level.
|
30 | */
|
31 | export function level(): Level;
|
32 |
|
33 | /**
|
34 | * Enables profiling.
|
35 | *
|
36 | * Upon loading of the module it will cache the package.json of the app and check if there is a "profiling" key set,
|
37 | * its value can be one of the options available for InstrumentationMode, and if set,
|
38 | * enable() will be called in pre app start with the value in the package.json.
|
39 | *
|
40 | * An example for an `app/package.json` enabling the manual instrumentation profiling is:
|
41 | * ```
|
42 | * {
|
43 | * "main": "main.js",
|
44 | * "profiling": "timeline"
|
45 | * }
|
46 | * ```
|
47 | *
|
48 | * @param type Profiling mode to use.
|
49 | * - "counters" - Accumulates method call counts and times until dumpProfiles is called and then prints aggregated statistic in the console. This is the default.
|
50 | * - "timeline" - Outputs method names along start/end timestamps in the console on the go.
|
51 | * - "lifecycle" - Outputs basic non-verbose times for startup, navigation, etc.
|
52 | */
|
53 | export declare function enable(type?: InstrumentationMode): void;
|
54 |
|
55 | /**
|
56 | * Disables profiling.
|
57 | */
|
58 | export declare function disable(): void;
|
59 |
|
60 | /**
|
61 | * Gets accurate system timestamp in ms.
|
62 | */
|
63 | export declare function time(): number;
|
64 |
|
65 | /**
|
66 | * Starts a timer with a specific name.
|
67 | * Works only if profiling is enabled.
|
68 | * @param name Name of the timer.
|
69 | */
|
70 | export declare function start(name: string): void;
|
71 |
|
72 | /**
|
73 | * Pauses a timer with a specific name. This will increase call count and accumulate time.
|
74 | * Works only if profiling is enabled.
|
75 | * @param name Name of the timer.
|
76 | * @returns TimerInfo for the paused timer.
|
77 | */
|
78 | export declare function stop(name: string): TimerInfo;
|
79 |
|
80 | /**
|
81 | * Read a timer info.
|
82 | * @param name The name of the timer to obtain information about.
|
83 | */
|
84 | export function timer(name: string): TimerInfo;
|
85 |
|
86 | /**
|
87 | * Returns true if a timer is currently running.
|
88 | * @param name Name of the timer.
|
89 | * @returns true is the timer is currently running.
|
90 | */
|
91 | export declare function isRunning(name: string): boolean;
|
92 |
|
93 | /**
|
94 | * Method decorator factory. It will intercept the method call and start and pause a timer before and after the method call.
|
95 | * Works only if profiling is enabled.
|
96 | * @param name Name of the timer which will be used for method calls. If not provided - the name of the method will be used.
|
97 | */
|
98 | export declare function profile(name?: string): MethodDecorator;
|
99 |
|
100 | /**
|
101 | * Function factory. It will intercept the function call and start and pause a timer before and after the function call. Works only if profiling is enabled.
|
102 | * Works only if profiling is enabled.
|
103 | * @param fn The function to wrap. Uses the function name to track the times.
|
104 | */
|
105 | export declare function profile<F extends Function>(fn: F): F;
|
106 |
|
107 | /**
|
108 | * Function factory. It will intercept the function call and start and pause a timer before and after the function call. Works only if profiling is enabled.
|
109 | * @param name The name used to track calls and times.
|
110 | * @param fn The function to wrap.
|
111 | */
|
112 | export declare function profile<F extends Function>(name: string, fn: F): F;
|
113 |
|
114 | /**
|
115 | * Method decorator. It will intercept the method calls and start and pause a timer before and after the method call. Works only if profiling is enabled.
|
116 | */
|
117 | export declare function profile<T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;
|
118 | export function profile(): any;
|
119 |
|
120 | /**
|
121 | * Prints the timer for all methods instrumented with profile decorator.
|
122 | */
|
123 | export declare function dumpProfiles(): void;
|
124 |
|
125 | /**
|
126 | * Resets the timers for all methods instrumented with profile decorator.
|
127 | */
|
128 | export function resetProfiles(): void;
|
129 |
|
130 | /**
|
131 | * Starts android cpu profiling.
|
132 | * @param name Name of the cpu profiling session.
|
133 | */
|
134 | export declare function startCPUProfile(name: string): void;
|
135 |
|
136 | /**
|
137 | * Stops android cpu profiling.
|
138 | * @param name Name of the cpu profiling session.
|
139 | */
|
140 | export declare function stopCPUProfile(name: string): void;
|
141 |
|
142 | /**
|
143 | * Gets the uptime of the current process in milliseconds.
|
144 | */
|
145 | export function uptime(): number;
|
146 |
|
147 | /**
|
148 | * Logs important messages. Contrary to console.log's behavior, the profiling log should output even for release builds.
|
149 | */
|
150 | export function log(message: string): void;
|
151 |
|
152 | /**
|
153 | * Manually output profiling messages. The `@profile` decorator is useful when measuring times that function calls take on the stack
|
154 | * but when measuring times between longer periods (startup times, times between the navigatingTo - navigatedTo events etc.)
|
155 | * you can call this method and provide manually the times to be logged.
|
156 | * @param message A string message
|
157 | * @param start The start time (see `time()`)
|
158 | * @param end The end time (see `time()`)
|
159 | */
|
160 | export function trace(message: string, start: number, end: number): void;
|