Skip to content
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

More fine-grained coverage output control #50215

Closed
davidanthoff opened this issue Jun 19, 2023 · 4 comments
Closed

More fine-grained coverage output control #50215

davidanthoff opened this issue Jun 19, 2023 · 4 comments
Labels
domain:code coverage kind:feature Indicates new feature / enhancement requests

Comments

@davidanthoff
Copy link
Contributor

The VS Code test framework is going to get coverage support at some point, and I'd love to use that in the test item framework. For that to work, I would need a much more fine-grained control over coverage output in Julia base, though :)

In particular, Julia processes are re-used across multiple test runs in the test item framework, and I would need to get individual coverage results per test-run. So the model of having just one global coverage output per Julia instance doesn't really work.

I could think of various different ways to solve this.

One could be an API that deletes all accumulated coverage data in the current process and starts writing new coverage data into a new file (a bit like Profile.clear()):

restart_coverage_collection(new_output_filename)

Or maybe even more elegant would be a scoped coverage collection a la:

collect_coverage(output_filename) do
   # Code for which coverage should be collected goes here
end

Or maybe it would even be possible to not write coverage data to disk at all but rather collect in-memory?

coverage_data = collect_coverage() do
     # Code for which coverage should be collected goes here
end

Not sure how big coverage data gets and whether that is a good idea or not.

I think for my purposes any of these would work well, so maybe the first one would be the simplest?

@davidanthoff davidanthoff added the kind:feature Indicates new feature / enhancement requests label Jun 19, 2023
@MilesCranmer
Copy link
Sponsor Member

Reading through the code after your post on the discourse thread (here).

It looks like the coverage data is stored in:

static logdata_t coverageData;

And this gets written to disk here:

write_log_data(coverageData, stm.c_str());

which gets called only when Julia is exiting, here:

jl_write_coverage_data(jl_options.output_code_coverage);

So the first order mechanism for live monitoring would be to have some hook so this coverage variable is accessible to the Julia runtime?

@davidanthoff
Copy link
Contributor Author

Very cool!

Two other thoughts:

  • it would be amazing if there was something like a flag that one could flip at runtime to pause and resume coverage collection.
  • look at the code that @MilesCranmer identified, it also suggests that one could add an API to get access to the coverage information without going through a file on disc, which would also be nice for the VS Code use case.

@Seelengrab
Copy link
Contributor

Seelengrab commented May 5, 2024

Related #50834

One difficulty with just adding a coverage flip is that you'll invalidate everything in your session, as far as I'm aware. This is the reason why every vendored stdlib/sysimage is compiled twice, once with coverage hooks and once without. This can greatly influence performance, effects etc - see #49978 for one such example.

@davidanthoff
Copy link
Contributor Author

For now it looks like #54358 solved this for the VS Code extension, thanks @MilesCranmer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:code coverage kind:feature Indicates new feature / enhancement requests
Projects
None yet
Development

No branches or pull requests

4 participants