Skip to content

Commit

Permalink
Create jl_clear_coverage_data to dynamically reset coverage (#54358)
Browse files Browse the repository at this point in the history
There are some use-cases that would benefit from being able to
reset the code coverage information during runtime. This creates
the function `jl_clear_coverage_data` to reset the `coverageData`
global.
  • Loading branch information
MilesCranmer committed May 24, 2024
1 parent eec6866 commit 018770d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,37 @@ JL_DLLEXPORT uint64_t *jl_malloc_data_pointer(StringRef filename, int line)
return allocLine(mallocData[filename], line);
}

// Resets the malloc counts.
extern "C" JL_DLLEXPORT void jl_clear_malloc_data(void)
static void clear_log_data(logdata_t &logData, int resetValue)
{
logdata_t::iterator it = mallocData.begin();
for (; it != mallocData.end(); it++) {
logdata_t::iterator it = logData.begin();
for (; it != logData.end(); it++) {
SmallVector<logdata_block*, 0> &bytes = (*it).second;
SmallVector<logdata_block*, 0>::iterator itb;
for (itb = bytes.begin(); itb != bytes.end(); itb++) {
if (*itb) {
logdata_block &data = **itb;
for (int i = 0; i < logdata_blocksize; i++) {
if (data[i] > 0)
data[i] = 1;
data[i] = resetValue;
}
}
}
}
jl_gc_sync_total_bytes(0);
}

// Resets the malloc counts.
extern "C" JL_DLLEXPORT void jl_clear_malloc_data(void)
{
clear_log_data(mallocData, 1);
}

// Resets the code coverage
extern "C" JL_DLLEXPORT void jl_clear_coverage_data(void)
{
clear_log_data(coverageData, 0);
}

static void write_log_data(logdata_t &logData, const char *extension)
{
std::string base = std::string(jl_options.julia_bindir);
Expand Down

0 comments on commit 018770d

Please sign in to comment.