From: claudio Date: Mon, 12 Dec 2022 09:51:04 +0000 (+0000) Subject: Since bgpctl uses clock_gettime() and struct timespec switch ometric code X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=81e584e859986614df9cc99f354526771f10acfe;p=openbsd Since bgpctl uses clock_gettime() and struct timespec switch ometric code over to handle struct timespec instead of struct timeval. This way no extra conversion is needed. OK tb@ --- diff --git a/usr.sbin/bgpctl/ometric.c b/usr.sbin/bgpctl/ometric.c index 10341f83b5a..b2a9d80599a 100644 --- a/usr.sbin/bgpctl/ometric.c +++ b/usr.sbin/bgpctl/ometric.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ometric.c,v 1.7 2022/12/06 17:38:41 claudio Exp $ */ +/* $OpenBSD: ometric.c,v 1.8 2022/12/12 09:51:04 claudio Exp $ */ /* * Copyright (c) 2022 Claudio Jeker @@ -43,7 +43,7 @@ struct olabels { enum ovalue_type { OVT_INTEGER, OVT_DOUBLE, - OVT_TIMEVAL, + OVT_TIMESPEC, }; struct ovalue { @@ -52,7 +52,7 @@ struct ovalue { union { unsigned long long i; double f; - struct timeval tv; + struct timespec ts; } value; enum ovalue_type valtype; }; @@ -316,9 +316,9 @@ ometric_output_value(FILE *out, const struct ovalue *ov) return fprintf(out, "%llu", ov->value.i); case OVT_DOUBLE: return fprintf(out, "%g", ov->value.f); - case OVT_TIMEVAL: - return fprintf(out, "%lld.%06ld", - (long long)ov->value.tv.tv_sec, (long)ov->value.tv.tv_usec); + case OVT_TIMESPEC: + return fprintf(out, "%lld.%09ld", + (long long)ov->value.ts.tv_sec, ov->value.ts.tv_nsec); } return -1; } @@ -430,10 +430,10 @@ ometric_set_float(struct ometric *om, double val, struct olabels *ol) } /* - * Set an timeval value with label ol. ol can be NULL. + * Set an timespec value with label ol. ol can be NULL. */ void -ometric_set_timeval(struct ometric *om, const struct timeval *tv, +ometric_set_timespec(struct ometric *om, const struct timespec *ts, struct olabels *ol) { struct ovalue *ov; @@ -444,8 +444,8 @@ ometric_set_timeval(struct ometric *om, const struct timeval *tv, if ((ov = malloc(sizeof(*ov))) == NULL) err(1, NULL); - ov->value.tv = *tv; - ov->valtype = OVT_TIMEVAL; + ov->value.ts = *ts; + ov->valtype = OVT_TIMESPEC; ov->labels = olabels_ref(ol); STAILQ_INSERT_TAIL(&om->vals, ov, entry); @@ -512,12 +512,12 @@ ometric_set_int_with_labels(struct ometric *om, uint64_t val, } void -ometric_set_timeval_with_labels(struct ometric *om, struct timeval *tv, +ometric_set_timespec_with_labels(struct ometric *om, struct timespec *ts, const char **keys, const char **values, struct olabels *ol) { struct olabels *extra; extra = olabels_add_extras(ol, keys, values); - ometric_set_timeval(om, tv, extra); + ometric_set_timespec(om, ts, extra); olabels_free(extra); } diff --git a/usr.sbin/bgpctl/ometric.h b/usr.sbin/bgpctl/ometric.h index 0e66857bd85..b4c64b4c705 100644 --- a/usr.sbin/bgpctl/ometric.h +++ b/usr.sbin/bgpctl/ometric.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ometric.h,v 1.4 2022/12/06 11:27:58 claudio Exp $ */ +/* $OpenBSD: ometric.h,v 1.5 2022/12/12 09:51:04 claudio Exp $ */ /* * Copyright (c) 2022 Claudio Jeker @@ -41,13 +41,13 @@ int ometric_output_all(FILE *); /* functions to set gauge and counter metrics */ void ometric_set_int(struct ometric *, uint64_t, struct olabels *); void ometric_set_float(struct ometric *, double, struct olabels *); -void ometric_set_timeval(struct ometric *, const struct timeval *, +void ometric_set_timespec(struct ometric *, const struct timespec *, struct olabels *); void ometric_set_info(struct ometric *, const char **, const char **, struct olabels *); void ometric_set_state(struct ometric *, const char *, struct olabels *); void ometric_set_int_with_labels(struct ometric *, uint64_t, const char **, const char **, struct olabels *); -void ometric_set_timeval_with_labels(struct ometric *, struct timeval *, +void ometric_set_timespec_with_labels(struct ometric *, struct timespec *, const char **, const char **, struct olabels *); #define OKV(...) (const char *[]){ __VA_ARGS__, NULL } diff --git a/usr.sbin/bgpctl/output_ometric.c b/usr.sbin/bgpctl/output_ometric.c index e286d0616c7..afd9b259fb5 100644 --- a/usr.sbin/bgpctl/output_ometric.c +++ b/usr.sbin/bgpctl/output_ometric.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output_ometric.c,v 1.9 2022/12/08 17:24:39 cheloha Exp $ */ +/* $OpenBSD: output_ometric.c,v 1.10 2022/12/12 09:51:04 claudio Exp $ */ /* * Copyright (c) 2022 Claudio Jeker @@ -322,13 +322,11 @@ static void ometric_tail(void) { struct timespec elapsed_time; - struct timeval tv; clock_gettime(CLOCK_MONOTONIC, &end_time); timespecsub(&end_time, &start_time, &elapsed_time); - TIMESPEC_TO_TIMEVAL(&tv, &elapsed_time); - ometric_set_timeval(bgpd_scrape_time, &tv, NULL); + ometric_set_timespec(bgpd_scrape_time, &elapsed_time, NULL); ometric_output_all(stdout); ometric_free_all();