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

Add drcov data dump mid-run via nudge and/or at regular intervals #7153

Open
zmybdnoln opened this issue Dec 18, 2024 · 5 comments
Open

Add drcov data dump mid-run via nudge and/or at regular intervals #7153

zmybdnoln opened this issue Dec 18, 2024 · 5 comments

Comments

@zmybdnoln
Copy link

Describe the solution you'd like
I hope drcov can have a new option, such as flush_interval, which would allow me to control how often data is written to the log file, rather than only writing at the end of the program. This is because my service is an online service, and I do not have the authority to perform start and stop operations.

@derekbruening
Copy link
Contributor

I thought there was already an issue on having a nudge dump the data, but I can't find one: it must have been a users list thread? Did you search the users list? Generally it is best to ask on the users list before filing an issue.

Looks like multiple people attempted to add a nudge trigger to dump coverage info:

For time-based, dr_set_itimer() is an easy method on UNIX.

@derekbruening derekbruening changed the title How to make drcov write to the log file in real-time or at regular intervals Add drcov data dump mid-run via nudge and/or at regular intervals Dec 18, 2024
@derekbruening
Copy link
Contributor

If you end up adding either nudge or timer coverage data dumping, please send a pull request so it can be merged and others can use it: from the prior users list questions it sounds like these features would be appreciated by others.

@zmybdnoln
Copy link
Author

@derekbruening

Thank you very much for your help. Due to the firewall, I'm unable to access the link https://groups.google.com/g/dynamorio-users. I've created a simple example using dr_set_itimer, but I've encountered some problems.
(1) If I call the drcovlib_dump function within the timer callback function, the log file will keep increasing in size. Suppose the size of the log file is X after the normal program ends. Now, after each call to the drcovlib_dump function, the size of the log file will become 1X, 2X, 3X...
(2) Later, I tried to execute drcovlib_exit first and then drcovlib_init within the callback function. I found that different log files, such as 0000.proc.log and 0001.proc.log, would be generated after each timing. This is in line with the expected situation. However, when the timed callback is executed for the second time, the drcovlib_init function will crash.

@zmybdnoln
Copy link
Author

@derekbruening

Thank you very much for your help. Due to the firewall, I'm unable to access the link https://groups.google.com/g/dynamorio-users. I've created a simple example using dr_set_itimer, but I've encountered some problems.
(1) If I call the drcovlib_dump function within the timer callback function, the log file will keep increasing in size. Suppose the size of the log file is X after the normal program ends. Now, after each call to the drcovlib_dump function, the size of the log file will become 1X, 2X, 3X...
(2) Later, I tried to execute drcovlib_exit first and then drcovlib_init within the callback function. I found that different log files, such as 0000.proc.log and 0001.proc.log, would be generated after each timing. This is in line with the expected situation. However, when the timed callback is executed for the second time, the drcovlib_init function will crash.

my code like this,in dr_client_main,drcovlib_init was SUCCESS, in the first coverage_flush_callback, exit_status and init_status was SUCCESS, but in the second coverage_flush_callback, exit_status was SUCCESS, drcovlib_init was crashed

static void coverage_flush_callback(void *drcontext, void *timer_id, int interval) {

drcovlib_status_t exit_status, init_status;


exit_status = drcovlib_exit(); 
dr_fprintf(STDERR, "drcovlib_exit returned: %d\n", exit_status);

if (exit_status != DRCOVLIB_SUCCESS) {
    dr_fprintf(STDERR, "Failed to exit and dump coverage data.\n");
    return;
} else {
    dr_fprintf(STDERR, "Coverage data dumped successfully.\n");
}

drcovlib_options_t cov_opts;
memset(&cov_opts, 0, sizeof(drcovlib_options_t));
cov_opts.struct_size = sizeof(drcovlib_options_t);
cov_opts.logdir = "/tmp";

if (!drcovlib_init(&cov_opts)) {
    dr_fprintf(STDERR, "Failed to initialize drcovlib.\n");
    return;
} else {
    dr_fprintf(STDERR, "drcovlib initialized successfully.\n");
}

}

DR_EXPORT void dr_client_main(client_id_t client_id, int argc, const char *argv[]) {

drcovlib_options_t cov_opts;
memset(&cov_opts, 0, sizeof(drcovlib_options_t));
cov_opts.struct_size = sizeof(drcovlib_options_t);
cov_opts.logdir = "/tmp";

if (!drcovlib_init(&cov_opts)) {
    dr_fprintf(STDERR, "Failed to initialize drcovlib.\n");
    return;
} else {
    dr_fprintf(STDERR, "drcovlib initialized successfully.\n");
}

dr_set_itimer(ITIMER_REAL, 60000, coverage_flush_callback)

}

@derekbruening
Copy link
Contributor

I believe the same questions are in this thread: https://groups.google.com/g/dynamorio-users/c/bSic8P63WwM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants