summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4f05ee0)
raw | patch | inline | side by side (parent: 4f05ee0)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 17 Jan 2009 09:37:50 +0000 (10:37 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 17 Jan 2009 09:37:50 +0000 (10:37 +0100) |
It's not just a simple (old - new), because wrap-around is handled, too.
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index ae89c44f9aee71ceaf5ceb8df2e117ef418d2d1f..aeea28d3529e6b4ef766de64e4688adc10ca7e46 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return n;
}
+counter_t counter_diff (counter_t old_value, counter_t new_value)
+{
+ counter_t diff;
+
+ if (old_value > new_value)
+ {
+ if (old_value <= 4294967295U)
+ diff = (4294967295U - old_value) + new_value;
+ else
+ diff = (18446744073709551615ULL - old_value)
+ + new_value;
+ }
+ else
+ {
+ diff = new_value - old_value;
+ }
+ return (diff);
+} /* counter_t counter_to_gauge */
diff --git a/src/common.h b/src/common.h
index f463b77e0c3b6f95707a4092d8f5310979ce3b5e..aefc2cc602589a7128616ecd0b2a5787cd4bdaea 100644 (file)
--- a/src/common.h
+++ b/src/common.h
void *user_data);
int read_file_contents (const char *filename, char *buf, int bufsize);
+counter_t counter_diff (counter_t old_value, counter_t new_value);
+
#endif /* COMMON_H */