-
Notifications
You must be signed in to change notification settings - Fork 527
Add article "Customize your performance data with extensibility API" #3406
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
Open
mikehoffms
wants to merge
24
commits into
main
Choose a base branch
from
user/mikehoffms/extensibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
53bad66
draft
mikehoffms 1b10e3e
update detailed toc
mikehoffms 3e20703
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms 5cac39f
whitespace
mikehoffms 3f3d59c
linkfix
mikehoffms f2c2464
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms f1e91ea
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms 17893d9
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms 4a21116
test backticks in link text
mikehoffms ab3c322
backticks in headings
mikehoffms ec76a14
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms c22d23b
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms 0844b6f
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms 2086b7b
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms 8c9380a
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms af24e29
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms 12672ca
fresh re-paste, some pngs
mikehoffms 9673ea3
See Also links
mikehoffms d27511a
***
mikehoffms 22ed295
Merge branch 'main' into user/mikehoffms/extensibility
mikehoffms e4c6745
syntax, Gallery code
mikehoffms 2d9d57f
Customize mark()
mikehoffms 91f822b
linkfix
mikehoffms f40d195
link timeStamp() Ref
mikehoffms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
269 changes: 269 additions & 0 deletions
269
microsoft-edge/devtools-guide-chromium/performance/extension.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
--- | ||
title: Customize your performance data with extensibility API | ||
description: Customize performance data with the extensibility API. | ||
author: MSEdgeTeam | ||
ms.author: msedgedevrel | ||
ms.topic: conceptual | ||
ms.service: microsoft-edge | ||
ms.subservice: devtools | ||
ms.date: 03/13/2025 | ||
--- | ||
<!-- Copyright Andrés Olivares and Sofia Emelianova | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. --> | ||
# Customize your performance data with extensibility API | ||
<!-- https://developer.chrome.com/docs/devtools/performance/extension --> | ||
|
||
**Detailed contents:** | ||
* [Overview](#overview) | ||
* [Key features](#key-features) | ||
* [Inject your data with the User Timings API](#inject-your-data-with-the-user-timings-api) | ||
* [`devtools` object](#devtools-object) | ||
* [Inject your data with `console.timeStamp`](#inject-your-data-with-consoletimestamp) | ||
* [View your data in the timeline](#view-your-data-in-the-timeline) | ||
* [Code examples](#code-examples) | ||
* [User Timings API examples](#user-timings-api-examples) | ||
* [Custom tracks and entries](#custom-tracks-and-entries) | ||
* [Markers](#markers) | ||
* [`console.timeStamp` API examples](#consoletimestamp-api-examples) | ||
* [See also](#see-also) | ||
|
||
|
||
<!-- ====================================================================== --> | ||
## Overview | ||
|
||
The Performance panel supports the performance extensibility API, enabling the addition of custom data to the Performance timeline. This lets you inject your measurements and events directly into the performance timeline as a custom track or in the Timings track. This may be useful for developers of frameworks, libraries, and complex applications with custom instrumentation to gain a more comprehensive understanding of performance. | ||
|
||
This API offers two distinct mechanisms: | ||
|
||
1. The User Timings API (using performance.mark and performance.measure) | ||
|
||
This API leverages the existing User Timings API https://developer.mozilla.org/docs/Web/API/Performance_API/User_timing . It also adds entries to the browser's internal performance timeline https://developer.mozilla.org/docs/Web/API/Performance_API , allowing for further analysis and integration with other performance tools. | ||
|
||
2. The console.timeStamp API (extended for DevTools) | ||
|
||
This API provides a high-performance method for instrumenting applications and surfacing timing data exclusively to the Performance panel in DevTools. It's designed for minimal runtime overhead, making it suitable for instrumenting hot paths and production builds. It does not add entries to the browser's internal performance timeline. | ||
|
||
|
||
|
||
<!-- ====================================================================== --> | ||
## Key features | ||
|
||
Both APIs offer: | ||
|
||
Custom Tracks: Add entries to custom tracks and track groups. | ||
Entries: Populate tracks with entries representing events or measurements. | ||
Color Customization: Color-code entries for visual differentiation. | ||
Key Differences and when to use each API: | ||
|
||
User Timings API (performance.mark, performance.measure): | ||
Adds entries to both the Performance panel and the browser's internal performance timeline. | ||
Allows for rich data, including tooltips and detailed properties. | ||
Allows for adding markers: Highlight specific moments in the timeline with visual markers. | ||
Suitable for detailed performance analysis and when integration with other performance tools is required. | ||
Use when you need to store extra data with each entry, and when you are already using the User Timings API. | ||
console.timeStamp API: | ||
Adds entries only to the Performance panel. | ||
Offers significantly higher performance, especially in production environments. | ||
Ideal for instrumenting hot paths and performance-critical code. | ||
No extra data such as tooltips or properties can be added. | ||
Use when performance overhead is a primary concern, and you need to quickly instrument code. | ||
|
||
|
||
<!-- ====================================================================== --> | ||
## Inject your data with the User Timings API | ||
|
||
To inject custom data, include a devtools object within the detail property of performance.mark https://developer.mozilla.org/docs/Web/API/Performance/mark#detail and performance.measure https://developer.mozilla.org/docs/Web/API/Performance/measure#detail methods. The structure of this devtools object determines how your data is displayed in the Performance panel. | ||
|
||
Use performance.mark https://developer.mozilla.org/docs/Web/API/Performance/mark to record an instant event or timestamp in the timeline. You can mark the start or end of a specific operation or any point of interest that doesn't have a duration. When you include a devtools object within the detail property, the Performance panel shows a custom marker in the Timings track. | ||
|
||
Use performance.measure https://developer.mozilla.org/docs/Web/API/Performance/measure#detail to measure the duration of a task or process. When you include a devtools object within the detail property, the Performance panel shows custom measurement entries in the timeline in a custom track. If you're using performance.mark as a reference point to create a performance.measure, you don't need to include the devtools object in performance.mark calls. | ||
|
||
|
||
<!-- ------------------------------ --> | ||
#### `devtools` object | ||
|
||
These types define the structure of the devtools object for different extension features: | ||
|
||
``` | ||
type DevToolsColor = | ||
"primary" | "primary-light" | "primary-dark" | | ||
"secondary" | "secondary-light" | "secondary-dark" | | ||
"tertiary" | "tertiary-light" | "tertiary-dark" | | ||
"error"; | ||
|
||
interface ExtensionTrackEntryPayload { | ||
dataType?: "track-entry"; // Defaults to "track-entry" | ||
color?: DevToolsColor; // Defaults to "primary" | ||
track: string; // Required: Name of the custom track | ||
trackGroup?: string; // Optional: Group for organizing tracks | ||
properties?: [string, string][]; // Key-value pairs for detailed view | ||
tooltipText?: string; // Short description for tooltip | ||
} | ||
|
||
interface ExtensionMarkerPayload { | ||
dataType: "marker"; // Required: Identifies as a marker | ||
color?: DevToolsColor; // Defaults to "primary" | ||
properties?: [string, string][]; // Key-value pairs for detailed view | ||
tooltipText?: string; // Short description for tooltip | ||
} | ||
``` | ||
|
||
|
||
<!-- ====================================================================== --> | ||
## Inject your data with `console.timeStamp` | ||
|
||
The console.timeStamp API is extended to allow for the creation of custom timing entries in the Performance panel with minimal overhead. | ||
|
||
|
||
``` | ||
console.timeStamp(label: string, start?: string, end?: string, trackName?: string, trackGroup?: string, color?: DevToolsColor); | ||
``` | ||
|
||
label: The label for the timing entry. | ||
start: The name of a previously recorded timestamp (using console.timeStamp(timeStampName)). If undefined, the current time is used. | ||
end: The name of a previously recorded timestamp. If undefined, the current time is used. | ||
trackName: The name of the custom track. | ||
trackGroup: The name of the track group. | ||
color: The color of the entry. | ||
|
||
|
||
<!-- ====================================================================== --> | ||
## View your data in the timeline | ||
|
||
To see your custom data in the timeline, in the Performance panel, turn on settings Capture settings > check_box Extension data. | ||
|
||
 | ||
|
||
Try it on this demo page https://corgi-collage.vercel.app/ . Turn on Extension data, start a performance recording, click Add new Corgi on the demo page, then stop the recording. You'll see a custom track in the trace that contains events with custom tooltips and details in the Summary tab. | ||
|
||
|
||
|
||
<!-- ====================================================================== --> | ||
## Code examples | ||
|
||
Here are a few examples of how to use the API to add your own data to the Performance panel using each available mechanism. | ||
|
||
|
||
|
||
<!-- ------------------------------ --> | ||
#### User Timings API examples | ||
|
||
In the next sections, see the examples of code that showcase how to add the following to the performance timeline: | ||
|
||
Custom tracks and entries to the timeline https://developer.chrome.com/docs/devtools/performance/extension#tracks | ||
Markers to the Timings track https://developer.chrome.com/docs/devtools/performance/extension#markers | ||
|
||
|
||
<!-- ---------- --> | ||
###### Custom tracks and entries | ||
|
||
Create custom tracks and populate them with entries to visualize your performance data in a custom track. For example: | ||
|
||
``` | ||
// Mark used to represent the start of the image processing task | ||
// The start time is defaulted to now | ||
performance.mark("Image Processing Start"); | ||
|
||
// ... later in your code | ||
|
||
// Track entry representing the completion of image processing | ||
// with additional details and a tooltip | ||
// The start time is a marker from earlier | ||
// The end time is defaulted to now | ||
performance.measure("Image Processing Complete", { | ||
start: "Image Processing Start", | ||
detail: { | ||
devtools: { | ||
dataType: "track-entry", | ||
track: "Image Processing Tasks", | ||
trackGroup: "My Tracks", // Group related tracks together | ||
color: "tertiary-dark", | ||
properties: [ | ||
["Filter Type", "Gaussian Blur"], | ||
["Resize Dimensions", "500x300"] | ||
], | ||
tooltipText: "Image processed successfully" | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
This results in the following custom track entry in the performance timeline, along with its tooltip text and properties: | ||
|
||
 | ||
|
||
|
||
<!-- ---------- --> | ||
###### Markers | ||
|
||
Visually highlight specific points of interest in the timeline with custom markers that span across all tracks. For example: | ||
|
||
``` | ||
// Marker indicating when the processed image was uploaded | ||
performance.mark("Image Upload", { | ||
detail: { | ||
devtools: { | ||
dataType: "marker", | ||
color: "secondary", | ||
properties: [ | ||
["Image Size", "2.5MB"], | ||
["Upload Destination", "Cloud Storage"] | ||
], | ||
tooltipText: "Processed image uploaded" | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
This results in the following marker in the Timings track, along with its tooltip text and properties: | ||
|
||
 | ||
|
||
|
||
<!-- ------------------------------ --> | ||
#### `console.timeStamp` API examples | ||
|
||
``` | ||
// Record a start timestamp | ||
console.timeStamp("start"); | ||
|
||
// Measure duration from start to now | ||
console.timeStamp("measure 1", "start", undefined, "My Track", "My Group", "primary-light"); | ||
|
||
// Record an end timestamp | ||
console.timeStamp("end"); | ||
|
||
// Measure duration from start to end | ||
console.timeStamp("measure 2", "start", "end", "My Track", "My Group", "secondary-dark"); | ||
``` | ||
|
||
This results in the following custom track entry in the performance timeline: | ||
|
||
 | ||
|
||
|
||
<!-- ====================================================================== --> | ||
## See also | ||
<!-- all links in article --> | ||
|
||
pending | ||
|
||
|
||
<!-- ====================================================================== --> | ||
> [!NOTE] | ||
> Portions of this page are modifications based on work created and [shared by Google](https://developers.google.com/terms/site-policies) and used according to terms described in the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0). | ||
> The original page is found [here](https://developer.chrome.com/docs/devtools/performance/extension) and is authored by Andrés Olivares and Sofia Emelianova. | ||
|
||
[](https://creativecommons.org/licenses/by/4.0) | ||
This work is licensed under a [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.