summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/parsers/duration.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 17:33:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 17:34:10 +0000
commit83ba6762cc43d9db581b979bb5e3445669e46cc2 (patch)
tree2e69833b43f791ed253a7a20318b767ebe56cdb8 /src/libnetdata/parsers/duration.h
parentReleasing debian version 1.47.5-1. (diff)
downloadnetdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.tar.xz
netdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.zip
Merging upstream version 2.0.3+dfsg (Closes: #923993, #1042533, #1045145).
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/libnetdata/parsers/duration.h')
-rw-r--r--src/libnetdata/parsers/duration.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libnetdata/parsers/duration.h b/src/libnetdata/parsers/duration.h
new file mode 100644
index 000000000..b95da5d2f
--- /dev/null
+++ b/src/libnetdata/parsers/duration.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef LIBNETDATA_PARSERS_DURATION_H
+#define LIBNETDATA_PARSERS_DURATION_H
+
+#include "parsers.h"
+
+int64_t duration_round_to_resolution(int64_t value, int64_t resolution);
+
+// duration (string to number)
+bool duration_parse(const char *duration, int64_t *result, const char *default_unit);
+#define duration_parse_nsec_t(duration, ns_ptr) duration_parse(duration, ns_ptr, "ns")
+#define duration_parse_usec_t(duration, us_ptr) duration_parse(duration, us_ptr, "us")
+#define duration_parse_msec_t(duration, ms_ptr) duration_parse(duration, ms_ptr, "ms")
+#define duration_parse_time_t(duration, secs_ptr) duration_parse(duration, secs_ptr, "s")
+#define duration_parse_mins(duration, mins_ptr) duration_parse(duration, mins_ptr, "m")
+#define duration_parse_hours(duration, hours_ptr) duration_parse(duration, hours_ptr, "h")
+#define duration_parse_days(duration, days_ptr) duration_parse(duration, days_ptr, "d")
+
+// duration (number to string)
+ssize_t duration_snprintf(char *dst, size_t dst_size, int64_t value, const char *unit, bool add_spaces);
+#define duration_snprintf_nsec_t(dst, dst_size, ns) duration_snprintf(dst, dst_size, ns, "ns", false)
+#define duration_snprintf_usec_t(dst, dst_size, us) duration_snprintf(dst, dst_size, us, "us", false)
+#define duration_snprintf_msec_t(dst, dst_size, ms) duration_snprintf(dst, dst_size, ms, "ms", false)
+#define duration_snprintf_time_t(dst, dst_size, secs) duration_snprintf(dst, dst_size, secs, "s", false)
+#define duration_snprintf_mins(dst, dst_size, mins) duration_snprintf(dst, dst_size, mins, "m", false)
+#define duration_snprintf_hours(dst, dst_size, hours) duration_snprintf(dst, dst_size, hours, "h", false)
+#define duration_snprintf_days(dst, dst_size, days) duration_snprintf(dst, dst_size, days, "d", false)
+
+bool duration_parse_seconds(const char *str, int *result);
+
+#endif //LIBNETDATA_PARSERS_DURATION_H