diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-04-25 21:52:09 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-04-25 22:00:26 +0300 |
commit | fbb142ae5a57ab227e46ff6ffeb4b29db000034f (patch) | |
tree | cc237b384f298a892a64848a2631c96432cceab7 /src/wydawca.c | |
parent | 68d0e67d55882d1298bb0bf89c954c0ff2b1b823 (diff) | |
download | wydawca-fbb142ae5a57ab227e46ff6ffeb4b29db000034f.tar.gz wydawca-fbb142ae5a57ab227e46ff6ffeb4b29db000034f.tar.bz2 |
Keep statistic items in global array. Use special thread for periodic reporting
* src/config.c: New configuration statement stat-report-interval
* src/directive.c
* src/timer.c: Rewrite statistic counters and functions
(wydawca_stat_log,wydawca_stat_init,wydawca_stat_update)
(wydawca_stat_notify,wydawca_stat_add): New functions.
(wy_thr_stat): New thread (statistics reporter.
* src/triplet.c: Remove per-thread statistic counters.
* src/wydawca.c (wy_main): Use new statistic calls. Force
statistic logging at the end of the run.
* src/wydawca.h (DEFAULT_STAT_REPORT_INTERVAL): New constant.
(stat_report_interval): New extern.
(wy_get_stat_array, wy_get_stat_slot)
(wy_get_stat_counter): Remove.
(wydawca_stat_log,wydawca_stat_init,wydawca_stat_update)
(wydawca_stat_notify,wydawca_stat_add)
(wydawca_stat_incr): New protos.
(stat_mask_p,logstats,wydawca_stats_export)
(wydawca_stats_update): Remove protos.
Diffstat (limited to 'src/wydawca.c')
-rw-r--r-- | src/wydawca.c | 100 |
1 files changed, 11 insertions, 89 deletions
diff --git a/src/wydawca.c b/src/wydawca.c index b7ccc7d..2e9c952 100644 --- a/src/wydawca.c +++ b/src/wydawca.c @@ -110,11 +110,11 @@ wy_vlog(int prio, char const *fmt, va_list ap) case LOG_ALERT: case LOG_CRIT: case LOG_ERR: - increase_stat_counter(WY_STAT_ERRORS); + wydawca_stat_incr(WY_STAT_ERRORS); break; case LOG_WARNING: - increase_stat_counter(WY_STAT_WARNINGS); + wydawca_stat_incr(WY_STAT_WARNINGS); } log_printer(prio, fmt, ap); @@ -139,87 +139,6 @@ wy_dbg(char const *fmt, ...) va_end(ap); } - -static char *stat_name[WY_MAX_STAT] = { - N_("errors"), - N_("warnings"), - N_("bad signatures"), - N_("access violation attempts"), - N_("complete triplets"), - N_("incomplete triplets"), - N_("bad triplets"), - N_("expired triplets"), - N_("triplet successes"), - N_("files uploaded"), - N_("files archived"), - N_("symlinks created"), - N_("symlinks removed"), - N_("check failures"), -}; - -static char *stat_kwname[WY_MAX_STAT] = { - "stat:errors", - "stat:warnings", - "stat:bad_signatures", - "stat:access_violations", - "stat:complete_triplets", - "stat:incomplete_triplets", - "stat:bad_triplets", - "stat:expired_triplets", - "stat:triplet_success", - "stat:uploads", - "stat:archives", - "stat:symlinks", - "stat:rmsymlinks", - "stat:check_failures" -}; - -int -wy_stat_mask_p(unsigned long mask) -{ - int i; - WY_STAT_COUNTER *stat = wy_get_stat_array(); - - for (i = 0; i < WY_MAX_STAT; i++) - if (stat[i] != 0 && (mask && WY_STAT_MASK(i))) - return 1; - return 0; -} - -int -wy_stat_expansion(char **ret, char const *name, size_t len) -{ - int i; - - for (i = 0; i < WY_MAX_STAT; i++) { - if (strlen(stat_kwname[i]) == len - && memcmp(stat_kwname[i], name, len) == 0) { - size_t size = 0; - *ret = NULL; - if (grecs_asprintf(ret, &size, "%u", wy_get_stat_counter(i))) - return WRDSE_NOSPACE; - else - return WRDSE_OK; - } - } - return WRDSE_UNDEF; -} - -void -logstats(void) -{ - int i; - - if (wy_stat_mask_p(print_stats)) { - for (i = 0; i < WY_MAX_STAT; i++) - if (print_stats & WY_STAT_MASK(i)) - wy_log(LOG_INFO, "%s: %u", - gettext(stat_name[i]), wy_get_stat_counter(i)); - } - - notify_finish(); -} - void grecs_print_diag(grecs_locus_t * locus, int err, int errcode, const char *msg) @@ -320,9 +239,6 @@ wy_main(void) sigaddset(&sigs, SIGCHLD); pthread_sigmask(SIG_BLOCK, &sigs, NULL); - wydawca_stats_export(); - scan_all_spools(); - if (wy_mode == WY_MODE_DAEMON) { if (!foreground) { if (daemon(0, 0)) { @@ -331,12 +247,16 @@ wy_main(void) } wy_log(LOG_NOTICE, _("daemon launched")); } + + wydawca_stat_init(); + scan_all_spools(); + pidfile_update(); - // Start cleaner thread + /* Start cleaner thread */ pthread_create(&tid, NULL, wy_thr_cleaner, NULL); - // Start listener thread + /* Start listener thread */ pthread_create(&tid, NULL, wy_thr_listen, NULL); /* Unblock only the fatal signals */ @@ -350,6 +270,8 @@ wy_main(void) sigwait(&sigs, &i); wy_log(LOG_NOTICE, "shutting down on signal \"%s\"", strsignal(i)); } else { + wydawca_stat_init(); + scan_all_spools(); /* Unblock only the fatal signals */ sigemptyset(&sigs); for (i = 0; fatal_signals[i]; i++) { @@ -357,8 +279,8 @@ wy_main(void) } pthread_sigmask(SIG_UNBLOCK, &sigs, NULL); wy_triplet_wait(); - logstats(); } + wydawca_stat_notify(1); } int |