cloudflare / cloudflare/workerd

Enable V8 Precise Coverage

Open
#2,065 1 comment 2 reactions 0 assignees View on GitHub
feature request
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

V8 allows to take precise coverage via the Chrome DevTools Protocol, but for some reason unknown to me, `workerd` prevents the standard CPU profiler to work, intercepting calls to `Profiler.enable`, `Profiler.start` and `Profiler.stop`.

Started digging, and from the V8 sources I saw that `Profile.startPreciseCoverage` is tied behind a flag (`m_enabled`) [here](https://github.com/v8/v8/blob/d3beebcabad9478beb01d88203d229ab6fe59e89/src/inspector/v8-profiler-agent-impl.cc#L303-L306).

Digging through the sources, I noticed that `workerd` intercepts most of the `Profiler` calls [here](https://github.com/cloudflare/workerd/blob/main/src/workerd/io/worker.c%2B%2B#L2336-L2363).

I tried a simple patch (inspired by @jasnell's #329) to restore the full `Profile` set of calls, and, to my amazement, it worked perfectly and was able to capture the full precise coverage.

Not knowing the rationale behind intercepting these calls, I'm unsure as to whether to create a PR, but all tests are passing, and having code coverage in tests is fantastic.

(For the records, I'm the author of a [tool](https://github.com/plugjs/plug/tree/main/workspaces/cov8) that analyzes code coverage from V8, so, obviously, I'm biased and would love to have this working)

Attached is a simple patch to showcase the feature: [profile.patch](https://github.com/cloudflare/workerd/files/15135501/profile.patch)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.