Skip to content

Commit c1bcae9

Browse files
pkozlowski-opensourcekirjs
authored andcommitted
feat(core): expose performance data in Chrome DevTools (angular#60789)
This commit exposes the enableProfiling() function which enables performance data visualisation directly in the Chrome DevTools performance panel. PR Close angular#60789
1 parent 333d4e3 commit c1bcae9

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

goldens/public-api/core/global_utils.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export function applyChanges(component: {}): void;
1010
// @public
1111
export type DirectiveDebugMetadata = AngularDirectiveDebugMetadata | AcxDirectiveDebugMetadata | AngularComponentDebugMetadata | AcxComponentDebugMetadata | WizComponentDebugMetadata;
1212

13+
// @public
14+
export function enableProfiling(): () => void;
15+
1316
// @public
1417
export function getComponent<T>(element: Element): T | null;
1518

packages/core/src/render3/debug/chrome_dev_tools_performance.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {InjectionToken} from '../../di';
1010
import {isTypeProvider} from '../../di/provider_collection';
1111
import {assertDefined, assertEqual} from '../../util/assert';
12+
import {performanceMarkFeature} from '../../util/performance';
1213
import {setProfiler} from '../profiler';
1314
import {Profiler, ProfilerEvent} from '../profiler_types';
1415
import {stringifyForError} from '../util/stringify_utils';
@@ -224,7 +225,19 @@ function getProviderTokenMeasureName<T>(token: any) {
224225
}
225226
}
226227

228+
/**
229+
* Start listening to the Angular's internal performance-related events and route those to the Chrome DevTools performance panel.
230+
* This enables Angular-specific data visualization when recording a performance profile directly in the Chrome DevTools.
231+
*
232+
* @returns a function that can be invoked to stop sending profiling data.
233+
*/
227234
export function enableProfiling() {
228-
setInjectorProfiler(chromeDevToolsInjectorProfiler);
229-
setProfiler(devToolsProfiler);
235+
performanceMarkFeature('Chrome DevTools profiling');
236+
const removeInjectorProfiler = setInjectorProfiler(chromeDevToolsInjectorProfiler);
237+
const removeProfiler = setProfiler(devToolsProfiler);
238+
239+
return () => {
240+
removeInjectorProfiler();
241+
removeProfiler();
242+
};
230243
}

packages/core/src/render3/global_utils_api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
export {applyChanges} from './util/change_detection_utils';
19+
export {enableProfiling} from './debug/chrome_dev_tools_performance';
1920
export {
2021
DirectiveDebugMetadata,
2122
getComponent,

packages/core/src/render3/util/global_utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import {
3333
} from './injector_discovery_utils';
3434
import {getSignalGraph} from './signal_debug';
3535

36+
import {enableProfiling} from '../debug/chrome_dev_tools_performance';
37+
3638
/**
3739
* This file introduces series of globally accessible debug tools
3840
* to allow for the Angular debugging story to function.
@@ -82,6 +84,8 @@ const globalUtilsFunctions = {
8284
'getDirectives': getDirectives,
8385
'applyChanges': applyChanges,
8486
'isSignal': isSignal,
87+
88+
'enableProfiling': enableProfiling,
8589
};
8690
type CoreGlobalUtilsFunctions = keyof typeof globalUtilsFunctions;
8791
type ExternalGlobalUtilsFunctions = keyof NgGlobalPublishUtils;

0 commit comments

Comments
 (0)