v8 code coverage

162 views
Skip to first unread message

Cecil King

unread,
Sep 20, 2022, 3:39:09 PM9/20/22
to v8-dev

Hello.

My first post here. I'm looking for advice on debugging an issue with the v8 code coverage.

I'm using startPreciseCoverage / takePreciseCoverage to extract code coverage data from Chrome (i.e. v8).

My issue: data from uncovered functions are missing from the dumped data.
For example, assume the handleSubmit function in authors.js is not called. I expect to see this:

{
    "scriptId": "16",
    "url": "file:///home/<user>/v8-chrome-coverage-wdio-sync/public/js/authors.js",
    "functions": [
        {
            "functionName": "",
            "ranges": [{ "startOffset": 0, "endOffset": 828, "count": 1 }],
            "isBlockCoverage": true },
        {
            "functionName": "showContent",
            "ranges": [{ "startOffset": 71, "endOffset": 448, "count": 1 }],
            "isBlockCoverage": true
        },
        {
            "functionName": "",
            "ranges": [{ "startOffset": 274, "endOffset": 444, "count": 3 }],
            "isBlockCoverage": true
        },
        {
            "functionName": "handleSubmit",
            "ranges": [{ "startOffset": 450, "endOffset": 703, "count": 0 }],
            "isBlockCoverage": false
        }
    ]
},

but instead I get this:

{
    "scriptId": "16",
    "url": "file:///home/<user>/v8-chrome-coverage-wdio-sync/public/js/authors.js",
    "functions": [
        {
            "functionName": "",
            "ranges": [{ "startOffset": 0, "endOffset": 828, "count": 1 }],
            "isBlockCoverage": true },
        {
            "functionName": "showContent",
            "ranges": [{ "startOffset": 71, "endOffset": 448, "count": 1 }],
            "isBlockCoverage": true
        },
        {
            "functionName": "",
            "ranges": [{ "startOffset": 274, "endOffset": 444, "count": 3 }],
            "isBlockCoverage": true
        }
    ]
},

i.e. there is no data at all on the uncovered function. This causes the c8 report tool to generate an invalid report.

The above is what I observe on my company's codebase. I tried to create simple reproductions that I could share, however all my simple projects are working fine.

Any suggestions or tips on what I could try to debug the problem would be appreciated.

(FYI ... here's a working version of the flow on a smaller project: https://github.com/cek333/v8-chrome-coverage-wdio-sync)

Thanks.

Jakob Gruber

unread,
Sep 21, 2022, 2:27:24 AM9/21/22
to v8-...@googlegroups.com
Hi Cecil,

it's hard to say much without a repro. I'd start by trying the V8 flag --trace-block-coverage (https://source.chromium.org/chromium/chromium/src/+/main:v8/src/debug/debug-coverage.cc;l=481;drc=5f2ed43ac6add2683505e130be73826cbb3dddfd). If that doesn't help, the next step would be to debug more around Coverage::Collect. 

Also, I'd suggest to file a report at crbug.com/v8/new to continue the conversation since bug reports are easier to track than mails :)

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/22d16033-590f-4de3-86de-a6aa6ebcbb74n%40googlegroups.com.

Cecil King

unread,
Sep 21, 2022, 11:28:12 AM9/21/22
to v8-dev
Thanks Jakob:
I'll give this a try and add any additional information I find to the bug report.

Cecil King

unread,
Oct 5, 2022, 11:40:59 AM10/5/22
to v8-dev
Hello Jakob:
Can you provide some additional advice on collecting the '--trace-block-coverage' output?

If I run chrome directly from the command-line and then enable coverage, then I can see the trace output in the terminal. (I'm on Linux.)

However, when chrome is launched via wdio (webdriver.io), then the trace output is not accessible.

I tried adding `--log-file` to the options for launching chrome from wdio (something equivalent to the following: `chromium --js-flags="--trace-block-coverage" --enable-logging --log-file="./v8-coverage.log"`) but the `--log-file` option doesn't capture the trace output.

I inquired over on the webdriver.io forum ... but there were no immediate solutions. They suggested that perhaps I can implement this feature (https://github.com/giggio/node-chromedriver/issues/313) to have chromedriver capture chrome's output. However our project doesn't use chromedriver (as far as I can tell ... chromedriver is not in the install packages and it's not installed globally).

Upon looking through closed chromium bugs to see if there was an existing solution, I saw mention of the `chrome://tracing` feature, and I can see that `v8` is listed in the `Record Categories`. However on first pass, it doesn't seem this interface is capturing the `trace-block-coverage`.

Any tips on dumping the trace data to a file, so I can include it with a bug report?

Thanks.

Jakob Gruber

unread,
Oct 6, 2022, 2:27:06 AM10/6/22
to v8-dev
You're right, we currently only output --trace-block-coverage through stdout. If redirecting stdout is not possible in your use case (and stdout is not visible/accessible), I'd say the easiest fix is to patch V8 s.t. --trace-block-coverage prints to a file, and rebuild. See all v8_flags.trace_block_coverage occurrences. You'd also have to disable the chrome sandbox with --no-sandbox to have access to the file system. 

Or alternatively, patch whatever runner you use to redirect stdout when spawning chrome.

Cecil King

unread,
Oct 6, 2022, 9:31:42 PM10/6/22
to v8-dev
Thanks Jakob:
I'll explore one of these options.
Reply all
Reply to author
Forward
0 new messages