Confirmed users
125
edits
m (→2. Telling the DevTools Frontend About the New Markers: update based on moved directories) |
|||
| (9 intermediate revisions by 2 users not shown) | |||
| Line 17: | Line 17: | ||
'''You can contribute to Operation Instrument by adding more instrumentation!''' | '''You can contribute to Operation Instrument by adding more instrumentation!''' | ||
What is a good candidate for tracing? Any single operation that can take more than a millisecond of time is a good rule of thumb. Parsing HTML is a good example because it can easily take tens of milliseconds or even longer on really big HTML snippets. Flattening a JS rope string is not as good an example, because while it may take up a lot of time in aggregate over a period of time, each individual flattening should be much faster than a millisecond. | |||
= Tutorial: Instrumenting New Operations = | = Tutorial: Instrumenting New Operations = | ||
| Line 26: | Line 28: | ||
== 1. Adding the Instrumentation to Gecko == | == 1. Adding the Instrumentation to Gecko == | ||
The easiest way to trace Gecko events/tasks with start and end timeline markers is to use the '''<code>mozilla::AutoTimelineMarker</code>''' RAII class. It automatically adds the start marker on construction, and adds the end marker on destruction. Don't worry too much about potential performance impact! It only actually adds the markers when the given docshell is being | Depending on the required fine level of control, there's a couple of ways to do this, and more coming soon. Currently, markers may only be added from the main thread, with plans to support them everywhere in the near future (see ''<code>otmt-markers</code>'' [https://bugzilla.mozilla.org/show_bug.cgi?id=1183219 bug 1183219]). | ||
===== Using ''<code>mozilla::AutoTimelineMarker</code>'' ===== | |||
The easiest way to trace Gecko events/tasks with start and end timeline markers is to use the '''<code>mozilla::AutoTimelineMarker</code>''' RAII class. It automatically adds the start marker on construction, and adds the end marker on destruction. Don't worry too much about potential performance impact! It only actually adds the markers when the given docshell is being observed by a timeline consumer, so essentially nothing will happen if a tool to inspect those markers isn't specifically open. | |||
This class may only be used on the main thread, and pointer to a docshell is necessary. If the docshell is a nullptr, nothing happens and this operation fails silently. | |||
Example: | |||
''<code>AutoTimelineMarker marker(aTargetNode->OwnerDoc()->GetDocShell(), "Parse HTML");</code>'' | |||
===== Using ''<code>mozilla::AutoGlobalTimelineMarker</code>'' ===== | |||
Similar to the previous RAII class, but doesn't expect a specific docshell, and the marker will be visible in all timeline consumers. This is useful for generic operations that don't involve a particular dochsell, or where a docshell isn't accessible. May also only be used on the main thread. | |||
Example: | |||
''<code>AutoGlobalTimelineMarker marker("Some global operation");</code>'' | |||
===== Using ''<code>TimelineConsumers</code>'' ===== | |||
A few static methods exist on the [https://dxr.mozilla.org/mozilla-central/source/docshell/base/timeline/TimelineConsumers.h?from=TimelineConsumers <code>TimelineConsumers</code>] class, like ''<code>AddMarkerForDocShell</code>'', ''<code>AddMarkerForDocShellsList</code>'', ''<code>AddMarkerForAllObservedDocShells</code>'' that give you fine grained control over creating the markers and what meta-data is attached to them. | |||
Example: | |||
''<code>TimelineConsumers::AddMarkerToDocShellsList(aDocShells, "Some specific operation", aMetaData);</code>'' | |||
== 2. Telling the DevTools Frontend About the New Markers == | == 2. Telling the DevTools Frontend About the New Markers == | ||
To get your new markers displayed in the performance tool's UI, edit the configuration data in '''<code> | To get your new markers displayed in the performance tool's UI, edit the configuration data in '''<code>devtools/client/performance/modules/markers.js</code>'''. | ||
Add a property to the '''<code>TIMELINE_BLUEPRINT</code>''' object. The property key should be the <code>const char *</code> literal that you added in step 1 ("Parse HTML" in our example). The new property should be an object with the following properties: | Add a property to the '''<code>TIMELINE_BLUEPRINT</code>''' object. The property key should be the <code>const char *</code> literal that you added in step 1 ("Parse HTML" in our example). The new property should be an object with the following properties: | ||
| Line 90: | Line 91: | ||
timeline.label.domevent=DOM Event | timeline.label.domevent=DOM Event | ||
timeline.label.consoleTime=Console | timeline.label.consoleTime=Console | ||
Any of the people [[DevTools/GetInvolved#Communication|listed here under "Performance"]] are good candidates to review the devtools config changes. | |||
= Adding Custom Metadata to Markers = | = Adding Custom Metadata to Markers = | ||
| Line 99: | Line 102: | ||
= Recording Markers in a Different Thread = | = Recording Markers in a Different Thread = | ||
For now, it's not supported. Only operations in the main thread are instrumented. | For now, it's not supported. Only operations in the main thread are instrumented. Follow https://bugzilla.mozilla.org/show_bug.cgi?id=1152988 to watch for support for markers from different threads. | ||