Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions turbonfs/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,44 @@ auth_token_cb_res *get_auth_token_and_setargs_cb(struct auth_context *auth)
return cb_res;
}

// Timer callback function called every 5 minutes
void timer_dump_stats(union sigval arg) {
// Call the signal handler to dump stats
handle_usr1(SIGUSR1);
}

// Create a timer to periodically dump statistics to log.
bool create_stats_timer()
{
timer_t timer_id;
struct sigevent sev;
struct itimerspec its;

// Set up the event to call our handler in a separate thread
sev.sigev_notify = SIGEV_THREAD;
sev.sigev_value.sival_ptr = &timer_id;
sev.sigev_notify_function = timer_dump_stats;
sev.sigev_notify_attributes = NULL;

if (timer_create(CLOCK_REALTIME, &sev, &timer_id) == -1) {
AZLogError("Failed to create timer");
return false;
}

// Fire every 5 minutes
its.it_value.tv_sec = 300; // initial expiration
its.it_value.tv_nsec = 0;
its.it_interval.tv_sec = 300; // periodic interval
its.it_interval.tv_nsec = 0;

if (timer_settime(timer_id, 0, &its, NULL) == -1) {
perror("timer_settime");
return false;
}

return true;
}

int main(int argc, char *argv[])
{
// Initialize logger first thing.
Expand Down Expand Up @@ -832,6 +870,12 @@ int main(int argc, char *argv[])
goto err_out4;
}

// Create a timer to periodically dump stats.
if (!create_stats_timer()) {
AZLogError("Failed to create timer to dump stats");
goto err_out4;
}

if (aznfsc_cfg.auth) {
// Set the auth token callback for this connection if auth is enabled.
set_auth_token_callback(get_auth_token_and_setargs_cb);
Expand Down