Closed Bug 1817834 Opened 1 year ago Closed 1 year ago

Allow starting javascript tracing via an API from privileged codebases

Categories

(DevTools :: Debugger, task)

task

Tracking

(firefox114 fixed)

RESOLVED FIXED
114 Branch
Tracking Status
firefox114 --- fixed

People

(Reporter: ochameau, Assigned: ochameau)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 2 obsolete files)

Bug 1803616 is introducing Javascript tracing, but this can only be enable from the debugger on-demand by clicking on a debugger button.
So that we can't control precisely when to start tracing.
This can be quite problematic as javascript tracing can quickly become very verbose.

It would be handy if we could call some API to control start and stop of JS tracing.
It would be similar to debugger; statement.

In https://phabricator.services.mozilla.com/D168300 I experimented re-using console.profile/profileEnd methods which aren't used in Firefox. console is an handy object as it is easily available from privileged as well as webpages.

These two methods are defunct since we removed the old performance panel.
You can toggle tracing via "log breakpoints" by calling these methods:

  • start tracing => console.profile()
  • stop tracing => console.profileEnd()

You may pass "webconsole" or "stdout" at first agument to console.profile()
to choose where to log the traces.

See Also: → 1817838
Attachment #9318772 - Attachment description: Bug 1803616 - [devtools] Allows to start/stop tracing via console.profile()/console.profileEnd(). → Bug 1817834 - [devtools] Allows to start/stop tracing via console.profile()/console.profileEnd().

For now, you could only toggle tracing from the debugger interface.
Having an API would help debugging tests and start'n stop tracing
from precise locations.
This would also ease passing parameters to have configurable traces.

Assignee: nobody → poirot.alex
Status: NEW → ASSIGNED
Summary: Allow starting javascript tracing via an API → Allow starting javascript tracing via an API from privileged codebases
Blocks: 1826389

Comment on attachment 9326918 [details]
Bug 1817834 - [devtools] Allow to start and stop JavaScript tracing via console.jsTrace() and console.jsTraceEnd().

Revision D174649 was moved to bug 1826389. Setting attachment 9326918 [details] to obsolete.

Attachment #9326918 - Attachment is obsolete: true

For now, you could only toggle tracing from the debugger interface.

Having an API would help debugging tests by start'n stop tracing from precise locations in code.
This would also ease passing parameters to have configurable traces.

With the following snipper you can toggle tracing without devtools opened by logging traces to stdout:

{
  const { startTracing, stopTracing } = ChromeUtils.importESModule(
    "resource://devtools/server/tracer/tracer.sys.mjs"
  );
  startTracing({ prefix: "prefix" });
    function bar() {}; function foo() {bar()}; foo();
  stopTracing();
}

It will log this to the terminal:

[prefix] Start tracing JavaScript
[prefix] —[interpreter]—> debugger eval code @ 6:43 - λ foo
[prefix] ——[interpreter]—> debugger eval code @ 6:24 - λ bar
[prefix] Stop tracing JavaScript

This typically allows to use traces on automation.

Note that if tracing is toggled by DevTools, it will integrate into this new ES Module
and will be able to log the traces to the web console.

Blocks: 1827382
Attachment #9318772 - Attachment is obsolete: true
Pushed by apoirot@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/77ab46da6605
[devtools] Allow to start and stop JavaScript tracing from privileged codebases. r=devtools-reviewers,nchevobbe
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 114 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: