refactor(devtools): improve profiler ux

- Add info tooltips that describe the visualizations and other
parts of the UI
- Improve the frame selector by adding axes labels and a
horizontal line for frames exceeding 60 fps
- Use a precise frame rate calculations instead of approximations
- Introduce improvements to the details panel
- Improve the bar chart visualization
- And more
This commit is contained in:
Georgi Serev
2026-08-11 10:00:02 -07:00
committed by GitHub
parent 8925a4ee49
commit 66c5ea7544
38 changed files with 628 additions and 328 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
"dependencies": {
"d3": "^7.0.0",
"dagre-d3-es": "^7.0.14",
"ngx-flamegraph": "0.1.1",
"ngx-flamegraph": "0.2.0",
"todomvc-app-css": "^2.3.0",
"todomvc-common": "^1.0.5",
"webtreemap": "^2.0.1"
@@ -10,7 +10,6 @@ sass_binary(
ng_project(
name = "recording-timeline",
srcs = [
"filter.ts",
"recording-timeline.component.ts",
],
angular_assets = [
@@ -23,8 +22,9 @@ ng_project(
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/frame-selector",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/record-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/recording-timeline-controls",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/recording-timeline-controls:filter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/recording-visualizer",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/shared:estimate-frame-rate",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/shared:calculate-frame-rate",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/shared:visualization-mode",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/visualizer-controls",
"//devtools/projects/ng-devtools/src/lib/shared/angie",
@@ -25,7 +25,7 @@ ng_project(
"//:node_modules/@angular/core",
"//:node_modules/@angular/material",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/record-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/shared:estimate-frame-rate",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/shared:calculate-frame-rate",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/tab-update",
"//devtools/projects/ng-devtools/src/lib/shared/button",
"//devtools/projects/protocol",
@@ -1,46 +1,69 @@
<p class="selected-frame">{{ selectionLabel() }} / {{ frameCount() }}</p>
<button
ng-button
btnType="icon"
(click)="move(-1)"
[disabled]="disablePreviousFrameButton()"
class="nav-btn"
matTooltip="Select previous frame"
aria-label="Select previous frame"
>
<mat-icon>chevron_left</mat-icon>
</button>
<cdk-virtual-scroll-viewport
#barContainer
orientation="horizontal"
[itemSize]="itemWidth"
class="bar-container"
(mouseleave)="stopDragScrolling()"
(mousedown)="startDragScroll($event)"
(mouseup)="stopDragScrolling()"
(mousemove)="dragScroll($event)"
[class.drag-scrolling]="dragScrolling()"
>
<div
*cdkVirtualFor="let d of graphData(); let i = index; trackBy: trackByIndex"
[ngStyle]="d.style"
class="frame-bar"
[class.selected]="selectedFrameIndexes().has(i)"
(click)="handleFrameSelection(i, $event)"
[matTooltip]="'Time spent: ' + (d.frame.duration | number) + 'ms\nSource: ' + d.frame.source"
[matTooltipShowDelay]="375"
matTooltipClass="multiline-tooltip"
></div>
</cdk-virtual-scroll-viewport>
<div class="frame-container">
<p class="x-axis-label">Change detection cycles</p>
<p class="y-axis-label">Time (ms)</p>
<p class="selected-frame">{{ selectionLabel() }} / {{ frameCount() }}</p>
<cdk-virtual-scroll-viewport
#barContainer
orientation="horizontal"
[itemSize]="itemWidth"
class="bar-container"
(mouseleave)="stopDragScrolling()"
(mousedown)="startDragScroll($event)"
(mouseup)="stopDragScrolling()"
(mousemove)="dragScroll($event)"
[class.drag-scrolling]="dragScrolling()"
>
<div
*cdkVirtualFor="let d of graphData(); let i = index; trackBy: trackByIndex"
[ngStyle]="d.style"
class="frame-bar"
[class.selected]="selectedFrameIndexes().has(i)"
(click)="handleFrameSelection(i, $event)"
[matTooltip]="d.tooltip"
[matTooltipShowDelay]="375"
matTooltipClass="multiline-tooltip"
></div>
</cdk-virtual-scroll-viewport>
@let sixtyFpsLineHeightPerc = this.sixtyFpsLineHeightPerc();
@if (sixtyFpsLineHeightPerc !== null) {
<div
class="sixty-fps-line"
[style.height.%]="sixtyFpsLineHeightPerc"
[class.text-below-line]="sixtyFpsLineHeightPerc > 90"
></div>
}
</div>
<button
ng-button
btnType="icon"
(click)="move(1)"
[disabled]="disableNextFrameButton()"
class="nav-btn"
matTooltip="Select next frame"
aria-label="Select next frame"
>
<mat-icon>chevron_right</mat-icon>
</button>
<mat-icon
class="frame-range-info"
matTooltip="You can select a range of frames by holding Shift"
aria-label="You can select a range of frames by holding Shift"
>
info
</mat-icon>
@@ -1,5 +1,7 @@
@use '../../../../../styles/typography';
$sel-bar-outline-width: 2px;
:host {
position: relative;
height: var(--max-bar-height);
@@ -11,72 +13,154 @@
align-items: flex-end;
justify-content: center;
align-items: center;
padding: 0.5rem;
padding: 0.75rem 0.5rem 1.75rem 0.5rem;
gap: 0.375rem;
.selected-frame {
@extend %body-01;
position: absolute;
top: 0.5rem;
right: 2rem;
margin: 0;
padding: 0.1rem 0.375rem;
text-align: center;
background: var(--dynamic-transparent-01);
backdrop-filter: blur(10px);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
border-radius: 0.75rem;
pointer-events: none;
z-index: 1;
}
.bar-container {
align-items: baseline;
overflow-x: auto;
.frame-container {
position: relative;
width: 100%;
height: 100%;
flex: 1;
cursor: pointer;
margin-left: 0.75rem;
&.drag-scrolling {
/* We use an animation for the cursor to avoid
applying the style when we perform a regular click. */
animation: grabbing-cursor 1 forwards;
animation-delay: 200ms;
.x-axis-label,
.y-axis-label {
position: absolute;
@extend %caption-text;
margin: 0;
color: var(--quaternary-contrast);
white-space: nowrap;
}
&::-webkit-scrollbar {
display: none;
.x-axis-label {
left: 0;
bottom: 0;
margin-bottom: -1.2rem;
}
::ng-deep .cdk-virtual-scroll-content-wrapper {
display: flex;
column-gap: 2.5px;
.y-axis-label {
transform: rotate(-90deg);
transform-origin: bottom left;
left: 0;
bottom: 0;
margin-left: -0.375rem;
}
.frame-bar {
position: relative;
.sixty-fps-line {
position: absolute;
bottom: 0;
left: 0;
right: 0;
box-sizing: border-box;
border-top: 1px dashed var(--dynamic-red-01);
color: var(--dynamic-red-01);
pointer-events: none;
&::before,
&::after {
position: absolute;
@extend %caption-text;
content: '16.6 ms = 60 fps';
top: 0;
padding: 0 0.75rem;
margin-top: -1.125rem;
white-space: nowrap;
}
&::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
z-index: -1;
left: 0;
}
&:hover::before {
background-color: var(--septenary-contrast);
&::after {
right: 0;
}
&.selected::before {
background-color: var(--dynamic-blue-01);
&.text-below-line {
&::before,
&::after {
margin-top: 0.125rem;
}
}
}
.selected-frame {
@extend %caption-text;
position: absolute;
color: var(--primary-contrast);
bottom: 0;
right: 0;
margin: 0 0 -1.2rem 0;
}
.bar-container {
align-items: baseline;
overflow-x: auto;
width: inherit;
height: inherit;
flex: 1;
padding: $sel-bar-outline-width;
cursor: pointer;
&.drag-scrolling {
/* We use an animation for the cursor to avoid
applying the style when we perform a regular click. */
animation: grabbing-cursor 1 forwards;
animation-delay: 200ms;
}
&::-webkit-scrollbar {
display: none;
}
::ng-deep .cdk-virtual-scroll-content-wrapper {
display: flex;
column-gap: 2.5px;
}
.frame-bar {
position: relative;
margin-top: $sel-bar-outline-width;
&:first-of-type {
margin-left: $sel-bar-outline-width;
}
&:last-of-type {
margin-right: $sel-bar-outline-width;
}
&::before {
content: '';
position: absolute;
top: -$sel-bar-outline-width;
left: -$sel-bar-outline-width;
right: -$sel-bar-outline-width;
bottom: -$sel-bar-outline-width;
z-index: -1;
}
&:hover::before {
background-color: var(--septenary-contrast);
}
&.selected::before {
background-color: var(--dynamic-blue-01);
}
}
}
}
.nav-btn {
margin-top: 1rem;
}
.frame-range-info {
position: absolute;
top: 0.75rem;
right: 0.75rem;
color: var(--tertiary-contrast);
width: 16px;
height: 16px;
font-size: 16px;
}
}
@@ -30,13 +30,13 @@ import {TabUpdate} from '../../../tab-update/index';
import {GraphNode} from '../record-formatter/record-formatter';
import {MatIcon} from '@angular/material/icon';
import {MatTooltip} from '@angular/material/tooltip';
import {DecimalPipe, NgStyle} from '@angular/common';
import {NgStyle} from '@angular/common';
import {ProfilerFrame} from '../../../../../../../protocol';
import {ButtonComponent} from '../../../../shared/button/button.component';
import {estimateFrameRate} from '../shared/estimate-frame-rate';
import {calculateFrameRate} from '../shared/calculate-frame-rate';
const ITEM_GAP = 2.5;
const ITEM_WIDTH = 18;
const ITEM_WIDTH = 14;
const MAX_HEIGHT = 100;
const DRAG_SCROLL_SPEED = 2;
@@ -70,7 +70,6 @@ function framesBoundSignal<T>(source: Signal<ProfilerFrame[]>, defaultValue: T)
CdkVirtualForOf,
NgStyle,
ButtonComponent,
DecimalPipe,
],
})
export class FrameSelectorComponent {
@@ -100,10 +99,10 @@ export class FrameSelectorComponent {
return `${this.startFrameIndex() + 1}`;
}
return this._smartJoinIndexLabels([...this.selectedFrameIndexes()]);
return this.smartJoinIndexLabels([...this.selectedFrameIndexes()]);
});
private _viewportScrollState = {scrollLeft: 0, xCoordinate: 0, isDragScrolling: false};
private viewportScrollState = {scrollLeft: 0, xCoordinate: 0, isDragScrolling: false};
readonly itemWidth = ITEM_WIDTH + ITEM_GAP;
@@ -119,6 +118,22 @@ export class FrameSelectorComponent {
this.frames().map((r) => this.getBarStyles(r, this.multiplicationFactor())),
);
/**
* Represents the position of the line that corresponds to 16.6 ms (60 fps) in the
* frame selector. It is available only if there is a bar/frame that exceeds that time.
*/
protected readonly sixtyFpsLineHeightPerc = computed(() => {
const max = Math.max(...this.graphData().map((n) => n.frame.duration));
if (max === -Infinity || max === 0) {
return null;
}
const frameRate = calculateFrameRate(max);
if (frameRate >= 60) {
return null;
}
return (1000 / 60 / max) * 100;
});
constructor() {
afterRenderEffect(() => {
// Listen for tab updates to reset the scroll position to the top
@@ -135,7 +150,7 @@ export class FrameSelectorComponent {
});
}
private _smartJoinIndexLabels(indexArray: number[]): string {
private smartJoinIndexLabels(indexArray: number[]): string {
const sortedIndexes = indexArray.sort((a, b) => a - b);
const groups: number[][] = [];
@@ -171,15 +186,15 @@ export class FrameSelectorComponent {
const newVal = this.startFrameIndex() + value;
this.selectedFrameIndexes.set(new Set([newVal]));
if (newVal > -1 && newVal < this.frameCount()) {
this._selectFrames({indexes: this.selectedFrameIndexes()});
this.emitSelectedFrames({indexes: this.selectedFrameIndexes()});
}
}
private _selectFrames({indexes}: {indexes: Set<number>}): void {
private emitSelectedFrames({indexes}: {indexes: Set<number>}): void {
const sortedIndexes = [...indexes].sort((a, b) => a - b);
this.startFrameIndex.set(sortedIndexes[0]);
this.endFrameIndex.set(sortedIndexes[sortedIndexes.length - 1]);
this._ensureVisible(this.startFrameIndex());
this.ensureVisible(this.startFrameIndex());
this.selectFrames.emit({indexes: sortedIndexes});
}
@@ -206,10 +221,10 @@ export class FrameSelectorComponent {
frames = new Set([idx]);
}
this.selectedFrameIndexes.set(new Set(frames));
this._selectFrames({indexes: this.selectedFrameIndexes()});
this.emitSelectedFrames({indexes: this.selectedFrameIndexes()});
}
private _ensureVisible(index: number): void {
private ensureVisible(index: number): void {
if (!this.viewport()) {
return;
}
@@ -228,12 +243,12 @@ export class FrameSelectorComponent {
stopDragScrolling(): void {
this.dragScrolling.set(false);
this._viewportScrollState.isDragScrolling = false;
this.viewportScrollState.isDragScrolling = false;
}
startDragScroll(event: MouseEvent): void {
this.dragScrolling.set(true);
this._viewportScrollState = {
this.viewportScrollState = {
xCoordinate: event.clientX,
scrollLeft: this.viewport().elementRef.nativeElement.scrollLeft,
isDragScrolling: true,
@@ -241,13 +256,13 @@ export class FrameSelectorComponent {
}
dragScroll(event: MouseEvent): void {
if (!this._viewportScrollState.isDragScrolling) {
if (!this.viewportScrollState.isDragScrolling) {
return;
}
const dx = event.clientX - this._viewportScrollState.xCoordinate;
const dx = event.clientX - this.viewportScrollState.xCoordinate;
this.viewport().elementRef.nativeElement.scrollLeft =
this._viewportScrollState.scrollLeft - dx * DRAG_SCROLL_SPEED;
this.viewportScrollState.scrollLeft - dx * DRAG_SCROLL_SPEED;
}
trackByIndex(index: number): number {
@@ -256,16 +271,23 @@ export class FrameSelectorComponent {
private getBarStyles(frame: ProfilerFrame, multiplicationFactor: number): GraphNode {
const height = frame.duration * multiplicationFactor;
const colorPercentage = Math.max(10, Math.round((height / MAX_HEIGHT) * 100));
const backgroundColor = this.getColorByFrameRate(estimateFrameRate(frame.duration));
const colorPercentage = Math.max(1, Math.round((height / MAX_HEIGHT) * 100));
const frameRate = calculateFrameRate(frame.duration);
const backgroundColor = this.getColorByFrameRate(frameRate);
const style = {
// We use a linear gradient to illustrate the height of
// the bar that corresponds to the duration of the frame.
'background-image': `-webkit-linear-gradient(bottom, ${backgroundColor} ${colorPercentage}%, transparent ${colorPercentage}%)`,
width: ITEM_WIDTH + 'px',
height: MAX_HEIGHT + 'px',
};
const toolTip = `${frame.source} TimeSpent: ${frame.duration.toFixed(3)}ms`;
return {style, toolTip, frame};
const tooltip =
`Time spent: ${frame.duration.toFixed(1)} ms` +
(frameRate < 60 ? `\nFrame rate: ${frameRate} fps` : '') +
(frame.source ? `\nSource: ${frame.source}` : '');
return {style, tooltip, frame};
}
private getColorByFrameRate(framerate: number): string {
@@ -274,7 +296,7 @@ export class FrameSelectorComponent {
} else if (60 > framerate && framerate >= 30) {
return 'var(--dynamic-yellow-01)';
} else if (30 > framerate && framerate >= 15) {
return 'var(--dynamic-red-02)';
return 'var(--dynamic-orange-01)';
}
return 'var(--dynamic-red-01)';
}
@@ -42,11 +42,13 @@ export class FlamegraphFormatter extends RecordFormatter<FlamegraphNode> {
},
};
const colors = createColors(theme);
if (showChangeDetection) {
result.color = theme === 'dark' ? CHANGE_DETECTION_COLOR_DARK : CHANGE_DETECTION_COLOR_LIGHT;
result.color = colors.cdColor;
}
this.addFrame(result.children, frame.directives, showChangeDetection, theme);
this.addFrame(result.children, frame.directives, showChangeDetection, colors);
return result;
}
@@ -54,15 +56,16 @@ export class FlamegraphFormatter extends RecordFormatter<FlamegraphNode> {
nodes: FlamegraphNode[],
elements: ElementProfile[],
showChangeDetection?: boolean,
theme?: ThemeUi,
colors?: Colors,
): number {
let timeSpent = 0;
elements.forEach((element) => {
for (const element of elements) {
// Possibly undefined because of
// the insertion on the backend.
if (!element) {
console.error('Unable to insert undefined element');
return;
continue;
}
const changeDetected = didRunChangeDetection(element);
const node: FlamegraphNode = {
@@ -73,15 +76,13 @@ export class FlamegraphFormatter extends RecordFormatter<FlamegraphNode> {
original: element,
changeDetected,
};
if (showChangeDetection) {
const CHANGE_DETECTION_COLOR =
theme === 'dark' ? CHANGE_DETECTION_COLOR_DARK : CHANGE_DETECTION_COLOR_LIGHT;
node.color = changeDetected ? CHANGE_DETECTION_COLOR : NO_CHANGE_DETECTION_COLOR;
if (showChangeDetection && colors) {
node.color = changeDetected ? colors.cdColor : colors.noCdColor;
}
timeSpent += this.addFrame(node.children, element.children, showChangeDetection, theme);
timeSpent += this.addFrame(node.children, element.children, showChangeDetection, colors);
timeSpent += node.value;
nodes.push(node);
});
}
return timeSpent;
}
}
@@ -90,7 +91,9 @@ export class FlamegraphFormatter extends RecordFormatter<FlamegraphNode> {
const CHANGE_DETECTION_COLOR_LIGHT = 'oklch(47.5% 0.26 295)';
const CHANGE_DETECTION_COLOR_DARK = 'oklch(76% 0.15 305)';
const NO_CHANGE_DETECTION_COLOR = 'transparent';
// Represent quaternary-contrast
const NO_CHANGE_DETECTION_COLOR_LIGHT = 'oklch(54.84% 0 0)';
const NO_CHANGE_DETECTION_COLOR_DARK = 'oklch(70.9% 0 0)';
const didRunChangeDetection = (profile: ElementProfile) => {
const components = profile.directives.filter((d) => d.isComponent);
@@ -99,3 +102,17 @@ const didRunChangeDetection = (profile: ElementProfile) => {
}
return components.some((c) => c.changeDetection !== undefined);
};
type Colors = {
cdColor: string;
noCdColor: string;
};
function createColors(theme?: ThemeUi): Colors {
const isDark = theme === 'dark';
return {
cdColor: isDark ? CHANGE_DETECTION_COLOR_DARK : CHANGE_DETECTION_COLOR_LIGHT,
noCdColor: isDark ? NO_CHANGE_DETECTION_COLOR_DARK : NO_CHANGE_DETECTION_COLOR_LIGHT,
};
}
@@ -19,7 +19,7 @@ export interface AppEntry<T> {
}
export interface GraphNode {
toolTip: string;
tooltip: string;
style: Record<string, unknown>;
frame: ProfilerFrame;
}
@@ -1,4 +1,4 @@
load("//devtools/tools:defaults.bzl", "ng_project", "sass_binary")
load("//devtools/tools:defaults.bzl", "ng_project", "sass_binary", "ts_project", "ts_test_library", "zoneless_web_test_suite")
package(default_visibility = ["//devtools:__subpackages__"])
@@ -17,7 +17,32 @@ ng_project(
":recording-timeline-controls_styles",
],
deps = [
":filter",
"//:node_modules/@angular/core",
"//:node_modules/@angular/material",
"//devtools/projects/ng-devtools/src/lib/shared/button",
],
)
ts_project(
name = "filter",
srcs = ["filter.ts"],
deps = [
"//devtools/projects/protocol",
],
)
ts_test_library(
name = "test_lib",
srcs = glob(["*.spec.ts"]),
deps = [
":filter",
],
)
zoneless_web_test_suite(
name = "test",
deps = [
":test_lib",
],
)
@@ -87,25 +87,17 @@ describe('filtering', () => {
const filter = createFilter('source:click');
expect(
filter({
frame: {
directives: [],
duration: 10,
source: 'click',
},
style: {},
toolTip: '',
directives: [],
duration: 10,
source: 'click',
}),
).toBeTrue();
expect(
filter({
frame: {
directives: [],
duration: 10,
source: 'mouseenter',
},
style: {},
toolTip: '',
directives: [],
duration: 10,
source: 'mouseenter',
}),
).toBeFalse();
});
@@ -114,49 +106,33 @@ describe('filtering', () => {
const filter1 = createFilter('duration:>10ms');
expect(
filter1({
frame: {
directives: [],
duration: 10,
source: 'click',
},
style: {},
toolTip: '',
directives: [],
duration: 10,
source: 'click',
}),
).toBeFalse();
expect(
filter1({
frame: {
directives: [],
duration: 15,
source: 'mouseenter',
},
style: {},
toolTip: '',
directives: [],
duration: 15,
source: 'mouseenter',
}),
).toBeTrue();
const filter2 = createFilter('duration:=10ms');
expect(
filter2({
frame: {
directives: [],
duration: 11,
source: 'mouseenter',
},
style: {},
toolTip: '',
directives: [],
duration: 11,
source: 'mouseenter',
}),
).toBeFalse();
expect(
filter2({
frame: {
directives: [],
duration: 10,
source: 'mouseenter',
},
style: {},
toolTip: '',
directives: [],
duration: 10,
source: 'mouseenter',
}),
).toBeTrue();
});
@@ -165,37 +141,25 @@ describe('filtering', () => {
const filter = createFilter('duration:>10ms source: click');
expect(
filter({
frame: {
directives: [],
duration: 10,
source: 'click',
},
style: {},
toolTip: '',
directives: [],
duration: 10,
source: 'click',
}),
).toBeFalse();
expect(
filter({
frame: {
directives: [],
duration: 15,
source: 'mouseenter',
},
style: {},
toolTip: '',
directives: [],
duration: 15,
source: 'mouseenter',
}),
).toBeFalse();
expect(
filter({
frame: {
directives: [],
duration: 15,
source: 'click',
},
style: {},
toolTip: '',
directives: [],
duration: 15,
source: 'click',
}),
).toBeTrue();
});
@@ -205,13 +169,9 @@ describe('filtering', () => {
expect(
filter({
frame: {
directives: [],
duration: 15,
source: 'click',
},
style: {},
toolTip: '',
directives: [],
duration: 15,
source: 'click',
}),
).toBeTrue();
});
@@ -221,13 +181,9 @@ describe('filtering', () => {
expect(
filter({
frame: {
directives: [],
duration: 15,
source: 'message',
},
style: {},
toolTip: '',
directives: [],
duration: 15,
source: 'message',
}),
).toBeFalse();
});
@@ -237,37 +193,25 @@ describe('filtering', () => {
expect(
filter({
frame: {
directives: [],
duration: 15,
source: 'click',
},
style: {},
toolTip: '',
directives: [],
duration: 15,
source: 'click',
}),
).toBeFalse();
expect(
filter({
frame: {
directives: [],
duration: 10,
source: 'message',
},
style: {},
toolTip: '',
directives: [],
duration: 10,
source: 'message',
}),
).toBeFalse();
expect(
filter({
frame: {
directives: [],
duration: 14,
source: 'click',
},
style: {},
toolTip: '',
directives: [],
duration: 14,
source: 'click',
}),
).toBeTrue();
});
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {ProfilerFrame} from '../../../../../../protocol';
import {ProfilerFrame} from '../../../../../../../protocol';
export type Filter = (nodes: ProfilerFrame) => boolean;
@@ -1,9 +1,25 @@
<input
class="ng-input size-mid filter-input"
(keyup)="filter.emit($any($event.target).value)"
(focus)="filterPlaceholder.set('duration: >30 source: click')"
(blur)="filterPlaceholder.set(FILTER_PLACEHOLDER)"
[placeholder]="filterPlaceholder()"
aria-label="Frames filter"
/>
<div class="filter-input-wrapper">
<div class="filter-input">
<input
#filter
class="ng-input size-mid filter-input"
(keyup)="onFilterInput($event.target.value)"
placeholder="Filter"
aria-label="Frames filter"
/>
@if (filter.value.length) {
<button ng-button btnType="icon" (click)="clearFilter()" title="Clear filter">
<mat-icon>close</mat-icon>
</button>
}
</div>
<mat-icon
class="info"
matTooltipClass="multiline-tooltip"
[matTooltip]="'Filter by duration (ms) and/or source.\nExample: duration: >5 source: setTimeout'"
aria-label="Filter by duration (ms) and/or source. Example: duration: >5 source: setTimeout"
>
info
</mat-icon>
</div>
<button ng-button size="mid" (click)="exportProfile.emit()">Save Profile</button>
@@ -4,7 +4,42 @@
padding: 0.5rem;
border-bottom: 1px solid var(--color-separator);
input {
width: 10rem;
.filter-input-wrapper {
display: flex;
align-items: center;
gap: 0.375rem;
.filter-input {
position: relative;
input {
width: 10rem;
padding-right: 1.625rem;
}
button {
position: absolute;
right: 0;
top: 4px;
margin-right: 0.5rem;
opacity: 0.5;
&:hover {
opacity: 0.8;
}
mat-icon {
width: 16px;
height: 16px;
font-size: 16px;
}
}
}
.info {
width: 18px;
height: 18px;
font-size: 18px;
}
}
}
@@ -6,20 +6,31 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, output, signal} from '@angular/core';
import {ButtonComponent} from '../../../../shared/button/button.component';
import {Component, ElementRef, output, viewChild} from '@angular/core';
import {MatIcon} from '@angular/material/icon';
import {MatTooltip} from '@angular/material/tooltip';
const FILTER_PLACEHOLDER = 'Filter';
import {ButtonComponent} from '../../../../shared/button/button.component';
import {createFilter, Filter} from './filter';
@Component({
selector: 'ng-recording-timeline-controls',
templateUrl: './recording-timeline-controls.component.html',
styleUrls: ['./recording-timeline-controls.component.scss'],
imports: [ButtonComponent],
imports: [ButtonComponent, MatIcon, MatTooltip],
})
export class RecordingTimelineControlsComponent {
protected readonly filterRef = viewChild<ElementRef>('filter');
protected readonly exportProfile = output<void>();
protected readonly filter = output<string>();
protected readonly filterPlaceholder = signal(FILTER_PLACEHOLDER);
protected readonly FILTER_PLACEHOLDER = FILTER_PLACEHOLDER;
protected readonly filter = output<Filter>();
onFilterInput(value: string) {
this.filter.emit(createFilter(value));
}
clearFilter() {
const filterInput = this.filterRef()?.nativeElement;
filterInput.value = '';
this.onFilterInput('');
}
}
@@ -23,7 +23,7 @@
} @else if (hasFrames() && frame) {
<ng-visualizer-controls
[record]="frame"
[estimatedFrameRate]="currentFrameRate()"
[frameRate]="currentFrameRate()"
[(visualizationMode)]="visualizationMode"
[(changeDetection)]="changeDetection"
/>
@@ -10,7 +10,7 @@ import {Component, computed, effect, input, linkedSignal, output, signal} from '
import {ProfilerFrame} from '../../../../../../protocol';
import {Observable} from 'rxjs';
import {createFilter, Filter, noopFilter} from './filter';
import {Filter, noopFilter} from './recording-timeline-controls/filter';
import {mergeFrames} from './record-formatter/frame-merger';
import {VisualizationMode} from './shared/visualization-mode';
@@ -18,7 +18,7 @@ import {RecordingVisualizerComponent} from './recording-visualizer/recording-vis
import {FrameSelectorComponent} from './frame-selector/frame-selector.component';
import {RecordingTimelineControlsComponent} from './recording-timeline-controls/recording-timeline-controls.component';
import {VisualizerControlsComponent} from './visualizer-controls/visualizer-controls.component';
import {estimateFrameRate} from './shared/estimate-frame-rate';
import {calculateFrameRate} from './shared/calculate-frame-rate';
import {AngieComponent} from '../../../shared/angie/angie.component';
@Component({
@@ -46,7 +46,7 @@ export class RecordingTimelineComponent {
return mergeFrames(indexes.map((index) => data[index]).filter(Boolean));
});
private readonly _filter = signal<Filter>(noopFilter);
private readonly filter = signal<Filter>(noopFilter);
protected readonly visualizing = signal(false);
// Ensure that `allFrames` is always cleaned if the stream changes.
@@ -58,11 +58,11 @@ export class RecordingTimelineComponent {
});
protected readonly frames = computed(() => {
const filter = this._filter();
const filter = this.filter();
return this.allFrames().filter((node) => filter(node));
});
readonly currentFrameRate = computed(() => estimateFrameRate(this.frame()?.duration ?? 0));
readonly currentFrameRate = computed(() => calculateFrameRate(this.frame()?.duration ?? 0));
readonly hasFrames = computed(() => this.allFrames().length > 0);
@@ -81,7 +81,7 @@ export class RecordingTimelineComponent {
});
}
setFilter(filter: string): void {
this._filter.set(createFilter(filter));
setFilter(filter: Filter): void {
this.filter.set(filter);
}
}
@@ -32,11 +32,13 @@ ng_project(
":recording-visualizer-types",
"//:node_modules/@angular/common",
"//:node_modules/@angular/core",
"//:node_modules/@angular/material",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/recording-visualizer/bargraph-visualizer",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/recording-visualizer/execution-details",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/recording-visualizer/flamegraph-visualizer",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/recording-visualizer/tree-map-visualizer",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/shared:visualization-mode",
"//devtools/projects/ng-devtools/src/lib/shared/button",
"//devtools/projects/ng-devtools/src/lib/shared/split",
"//devtools/projects/protocol",
],
@@ -17,7 +17,9 @@ ng_project(
":bar-chart_styles",
],
deps = [
"//:node_modules/@angular/common",
"//:node_modules/@angular/core",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/recording-timeline/record-formatter/bargraph-formatter",
"//devtools/projects/protocol",
],
)
@@ -3,10 +3,17 @@
<div
(click)="barClick.emit(data()[$index])"
class="bar"
[class.highlighted]="highlighted() === bar.original"
[style.width.%]="bar.width"
[style.animation-delay]="$index * 0.1 + 's'"
>
<span>{{ bar.text }}</span>
<span class="text">
<span class="label">{{ bar.label }}</span>
<span class="time pill">{{ bar.time | number: '1.0-1' }} ms</span>
<span class="count pill"
>{{ bar.count }} {{ bar.count !== 1 ? 'instances' : 'instance' }}</span
>
</span>
</div>
}
</div>
@@ -20,12 +20,13 @@
background-color 0.3s ease-out,
width 0.3s ease;
&.highlighted,
&:hover {
background-color: color-mix(in srgb, var(--dynamic-blue-02) 70%, var(--full-contrast) 30%);
opacity: 1;
}
span {
.text {
padding-inline: 0.5rem;
max-width: 100%;
display: inline-block;
@@ -34,6 +35,17 @@
overflow: hidden;
opacity: 1;
color: var(--septenary-contrast);
.label {
font-weight: 600;
}
.pill {
background-color: color-mix(in srgb, 80% var(--dynamic-blue-02), var(--full-contrast));
border-radius: 0.5rem;
margin-left: 0.375rem;
padding: 0 0.375rem;
}
}
}
}
@@ -7,25 +7,31 @@
*/
import {Component, computed, input, output} from '@angular/core';
import {DecimalPipe} from '@angular/common';
import {BargraphNode} from '../../../record-formatter/bargraph-formatter/bargraph-formatter';
import {ElementProfile} from '../../../../../../../../../protocol';
interface BarData {
label: string;
count: number;
width: number;
time: number;
text: string;
original: ElementProfile;
}
@Component({
selector: 'ng-bar-chart',
templateUrl: './bar-chart.component.html',
styleUrls: ['./bar-chart.component.scss'],
styleUrl: './bar-chart.component.scss',
imports: [DecimalPipe],
})
export class BarChartComponent {
readonly data = input<BargraphNode[]>([]);
/** The `ElementProfile` that corresponds to a bar graph node to highlight. */
readonly highlighted = input<ElementProfile | null>(null);
readonly internalData = computed(() => {
const nodes = this.data() ?? [];
const values: BarData[] = [];
@@ -34,9 +40,9 @@ export class BarChartComponent {
values.push({
label: node.label,
count: node.count ?? 1,
width: (node.value / max) * 100,
width: Math.max(1, (node.value / max) * 100),
time: node.value,
text: createBarText(node),
original: node.original,
});
}
return values;
@@ -44,9 +50,3 @@ export class BarChartComponent {
readonly barClick = output<BargraphNode>();
}
export function createBarText(bar: BargraphNode) {
return `${bar.label} | ${bar.value.toFixed(1)} ms | ${bar.count} ${
bar.count === 1 ? 'instance' : 'instances'
}`;
}
@@ -1 +1,5 @@
<ng-bar-chart (barClick)="selectNode($event)" [data]="profileRecords()" />
<ng-bar-chart
(barClick)="selectNode($event)"
[data]="profileRecords()"
[highlighted]="highlighted()"
/>
@@ -7,7 +7,7 @@
*/
import {Component, computed, input, output} from '@angular/core';
import {ProfilerFrame} from '../../../../../../../../protocol';
import {ElementProfile, ProfilerFrame} from '../../../../../../../../protocol';
import {BarGraphFormatter, BargraphNode} from '../../record-formatter/bargraph-formatter/index';
@@ -27,6 +27,9 @@ export class BargraphVisualizerComponent {
private readonly _formatter = new BarGraphFormatter();
frame = input.required<ProfilerFrame>();
/** The `ElementProfile` that corresponds to a bar graph node to highlight. */
highlighted = input<ElementProfile | null>(null);
profileRecords = computed(() => this._formatter.formatFrame(this.frame()));
formatEntryData(bargraphNode: BargraphNode): SelectedDirective[] {
@@ -1,4 +1,9 @@
:host {
display: block;
white-space: nowrap;
.ng-table td {
padding-top: 0.375rem;
padding-bottom: 0.375rem;
}
}
@@ -30,7 +30,7 @@ export class FlamegraphVisualizerComponent {
public themeService = inject(ThemeService);
readonly profilerBars = computed(() => {
return [
this._formatter.formatFrame(
this.formatter.formatFrame(
this.frame(),
this.changeDetection(),
this.themeService.currentTheme(),
@@ -39,19 +39,19 @@ export class FlamegraphVisualizerComponent {
});
view: [number, number] = [235, 200];
private readonly _formatter = new FlamegraphFormatter();
private readonly formatter = new FlamegraphFormatter();
readonly colors = computed<FlamegraphColor>(() => {
// Represent `dynamic-blue-02` and `dynamic-green-01`
// Represent `dynamic-blue-02` and `dynamic-orange-01`
return this.themeService.currentTheme() === 'dark'
? {
hue: [211, 123],
saturation: [100, 31],
lightness: [65, 49],
red: [75, 255],
green: [162, 150],
blue: [255, 73],
}
: {
hue: [214, 125],
saturation: [85, 37],
lightness: [50, 41],
red: [19, 236],
green: [113, 118],
blue: [234, 33],
};
});
@@ -12,14 +12,29 @@
<ng-tree-map-visualizer [frame]="frame()" />
}
@case (cmpVisualizationModes.BarGraph) {
<ng-bargraph-visualizer [frame]="frame()" (nodeSelect)="selectNode($event)" />
<ng-bargraph-visualizer
[frame]="frame()"
[highlighted]="selectedEntry()?.original ?? null"
(nodeSelect)="selectNode($event)"
/>
}
}
</as-split-area>
@if (selectedEntry(); as entry) {
<as-split-area size="30" minSize="25" class="selected-entry">
<p class="title">{{ entry.label }} details</p>
<div class="header">
<p class="title">{{ entry.label }} details</p>
<button
ng-button
btnType="icon"
class="close-btn"
title="Close details"
(click)="selectNode(null)"
>
<mat-icon>close</mat-icon>
</button>
</div>
<div class="entry-statistics">
<p class="total-time">
Total time spent: <span>{{ entry.value | number }} ms</span>
@@ -6,28 +6,59 @@
height: 100%;
.selected-entry {
padding: 0.75rem;
position: relative;
box-sizing: border-box;
overflow: auto;
display: flex;
flex-direction: column;
.title {
@extend %heading-400;
margin: 0 0 0.75rem 0;
padding: 0;
}
.header {
padding: 0.75rem;
background-color: var(--color-background);
.subtitle {
@extend %body-bold-01;
margin: 2rem 0 0.5rem 0;
.title {
@extend %heading-400;
word-wrap: break-word;
margin: 0;
padding: 0;
padding-right: 1rem;
}
.close-btn {
position: absolute;
top: 0.75rem;
right: 0.75rem;
mat-icon {
font-size: 16px;
width: 16px;
height: 16px;
}
}
}
.entry-statistics {
.total-time > span {
color: var(--dynamic-purple-01);
overflow: auto;
flex: 1;
padding: 0 0.75rem 0.75rem 0.75rem;
display: grid;
align-content: start;
gap: 0;
.subtitle {
@extend %body-bold-01;
margin-top: 2rem;
}
.total-time {
margin-top: 0;
span {
color: var(--dynamic-purple-01);
}
}
ng-execution-details {
margin-top: 1.5rem;
margin-top: 0.25rem;
}
ul {
@@ -8,6 +8,7 @@
import {Component, computed, input, linkedSignal} from '@angular/core';
import {DecimalPipe} from '@angular/common';
import {MatIcon} from '@angular/material/icon';
import {ProfilerFrame} from '../../../../../../../protocol';
@@ -20,6 +21,7 @@ import {TreeMapVisualizerComponent} from './tree-map-visualizer/tree-map-visuali
import {FlamegraphVisualizerComponent} from './flamegraph-visualizer/flamegraph-visualizer.component';
import {SplitComponent} from '../../../../shared/split/split.component';
import {SplitAreaDirective} from '../../../../shared/split/splitArea.directive';
import {ButtonComponent} from '../../../../shared/button/button.component';
@Component({
selector: 'ng-recording-visualizer',
@@ -33,6 +35,8 @@ import {SplitAreaDirective} from '../../../../shared/split/splitArea.directive';
BargraphVisualizerComponent,
ExecutionDetailsComponent,
DecimalPipe,
ButtonComponent,
MatIcon,
],
})
export class RecordingVisualizerComponent {
@@ -42,6 +46,9 @@ export class RecordingVisualizerComponent {
readonly cmpVisualizationModes = VisualizationMode;
// We use this technique in order to:
// - Close the details (i.e. unset the selected node) when the frame is changed
// - Close the details when the visualization mode is changed
private readonly selectedNodeCleanUpDeps = computed(
// We don't care about the output format as long as
// the value is different when a dependency changes
@@ -60,7 +67,7 @@ export class RecordingVisualizerComponent {
readonly selectedDirectives = computed(() => this.selectedNode()?.selectedDirectives ?? []);
readonly parentHierarchy = computed(() => this.selectedNode()?.parentHierarchy ?? []);
selectNode(selected: SelectedEntry): void {
selectNode(selected: SelectedEntry | null): void {
this.selectedNode.set(selected);
}
}
@@ -76,7 +76,7 @@ export class TreeMapVisualizerComponent implements OnDestroy {
private _createTree(): void {
render(this.tree().nativeElement, this.treeMapRecords(), {
padding: [20, 5, 5, 5],
caption: (node) => `${node.id}: ${node.size.toFixed(3)} ms`,
caption: (node) => `${node.id}: ${node.size.toFixed(1)} ms`,
showNode: () => true,
});
}
@@ -8,15 +8,15 @@ ts_project(
)
ts_project(
name = "estimate-frame-rate",
srcs = ["estimate-frame-rate.ts"],
name = "calculate-frame-rate",
srcs = ["calculate-frame-rate.ts"],
)
ts_test_library(
name = "test_lib",
srcs = glob(["*.spec.ts"]),
deps = [
":estimate-frame-rate",
":calculate-frame-rate",
],
)

Some files were not shown because too many files have changed in this diff Show More