8000 feat(core): expose performance data in Chrome DevTools by pkozlowski-opensource · Pull Request #60789 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

feat(core): expose performance data in Chrome DevTools #60789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(core): expose performance data in Chrome DevTools
This commit exposes the enableProfiling() function which enables
performance data visualisation directly in the Chrome DevTools
performance panel.
  • Loading branch information
pkozlowski-opensource committed Apr 14, 2025
commit aef67c0d4caae83186823d88d25ca9b21656f72a
3 changes: 3 additions & 0 deletions goldens/public-api/core/global_utils.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export function applyChanges(component: {}): void;
// @public
export type DirectiveDebugMetadata = AngularDirectiveDebugMetadata | AcxDirectiveDebugMetadata | AngularComponentDebugMetadata | AcxComponentDebugMetadata | WizComponentDebugMetadata;

// @public
export function enableProfiling(): () => void;

// @public
export function getComponent<T>(element: Element): T | null;

Expand Down
17 changes: 15 additions & 2 deletions packages/core/src/render3/debug/chrome_dev_tools_performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {InjectionToken} from '../../di';
import {isTypeProvider} from '../../di/provider_collection';
import {assertDefined, assertEqual} from '../../util/assert';
import {performanceMarkFeature} from '../../util/performance';
import {setProfiler} from '../profiler';
import {Profiler, ProfilerEvent} from '../profiler_types';
import {stringifyForError} from '../util/stringify_utils';
Expand Down Expand Up @@ -224,7 +225,19 @@ function getProviderTokenMeasureName<T>(token: any) {
}
}

/**
* Start listening to the Angular's internal performance-related events and route those to the Chrome DevTools performance panel.
* This enables Angular-specific data visualization when recording a performance profile directly in the Chrome DevTools.
*
* @returns a function that can be invoked to stop sending profiling data.
*/
export function enableProfiling() {
setInjectorProfiler(chromeDevToolsInjectorProfiler);
setProfiler(devToolsProfiler);
performanceMarkFeature('Chrome DevTools profiling');
const removeInjectorProfiler = setInjectorProfiler(chromeDevToolsInjectorProfiler);
const removeProfiler = setProfiler(devToolsProfiler);

return () => {
removeInjectorProfiler();
removeProfiler();
};
}
1 change: 1 addition & 0 deletions packages/core/src/render3/global_utils_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

export {applyChanges} from './util/change_detection_utils';
export {enableProfiling} from './debug/chrome_dev_tools_performance';
export {
DirectiveDebugMetadata,
getComponent,
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/render3/util/global_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
} from './injector_discovery_utils';
import {getSignalGraph} from './signal_debug';

import {enableProfiling} from '../debug/chrome_dev_tools_performance';

/**
* This file introduces series of globally accessible debug tools
* to allow for the Angular debugging story to function.
Expand Down Expand Up @@ -82,6 +84,8 @@ const globalUtilsFunctions = {
'getDirectives': getDirectives,
'applyChanges': applyChanges,
'isSignal': isSignal,

'enableProfiling': enableProfiling,
};
type CoreGlobalUtilsFunctions = keyof typeof globalUtilsFunctions;
type ExternalGlobalUtilsFunctions = keyof NgGlobalPublishUtils;
Expand Down
0