Dear DR friends,
How could i 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.
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 below ,in dr_client_main function,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);
}