]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: support rate in stats-file
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 29 Apr 2024 14:34:22 +0000 (16:34 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 2 May 2024 08:55:25 +0000 (10:55 +0200)
Implement support for FN_RATE stat column into stat-file.

For the output part, only minimal change is required. Reuse the function
read_freq_ctr() to print the same value in both stats output and
stats-file dump.

For counter preloading, define a new utility function
preload_freq_ctr(). This can be used to initialize a freq-ctr type by
preloading previous period value. Reuse this function in load_ctr()
during stats-file parsing.

At the moment, no rate column is defined as generic. Thus, this commit
does not have functional change. This will be changed as soon as FN_RATE
are converted to generic columns.

include/haproxy/freq_ctr.h
src/stats-file.c
src/stats.c

index f3f69039038bed71419c1373c10000b02e4fa4e7..f037cbbade57391e18eb1def0b05b008ff6c2f86 100644 (file)
@@ -32,6 +32,14 @@ ullong freq_ctr_total(const struct freq_ctr *ctr, uint period, int pend);
 int freq_ctr_overshoot_period(const struct freq_ctr *ctr, uint period, uint freq);
 uint update_freq_ctr_period_slow(struct freq_ctr *ctr, uint period, uint inc);
 
+/* Only usable during single threaded startup phase. */
+static inline void preload_freq_ctr(struct freq_ctr *ctr, uint value)
+{
+       ctr->curr_ctr = 0;
+       ctr->prev_ctr = value;
+       ctr->curr_tick = now_ms & ~1;
+}
+
 /* Update a frequency counter by <inc> incremental units. It is automatically
  * rotated if the period is over. It is important that it correctly initializes
  * a null area.
index 828c0a1bf2b2c05fd72ee807409c2357bd5e1623..4f07ddc903b82da635e33a160cb01da06522b37d 100644 (file)
@@ -211,6 +211,10 @@ static int load_ctr(const struct stat_col *col, const struct ist token,
                value.u.u64 = read_uint64(&ptr, istend(token));
                break;
 
+       case FF_U32:
+               value.u.u32 = read_uint(&ptr, istend(token));
+               break;
+
        default:
                /* Unsupported field nature. */
                return 1;
@@ -223,6 +227,9 @@ static int load_ctr(const struct stat_col *col, const struct ist token,
        if (fn == FN_COUNTER && ff == FF_U64) {
                *(uint64_t *)counter = value.u.u64;
        }
+       else if (fn == FN_RATE && ff == FF_U32) {
+               preload_freq_ctr(counter, value.u.u32);
+       }
        else {
                /* Unsupported field format/nature combination. */
                return 1;
index 65b701fdb6de69270828909e5570bfe627ed716a..0a26a01ec5329bed40d8ce00e3ec29b7e7d473bf 100644 (file)
@@ -801,6 +801,11 @@ static struct field me_generate_field(const struct stat_col *col,
                        ABORT_NOW();
                }
        }
+       else if (fn == FN_RATE) {
+               /* freq-ctr always uses FF_U32 */
+               BUG_ON(stcol_format(col) != FF_U32);
+               value = mkf_u32(FN_RATE, read_freq_ctr(counter));
+       }
        else {
                /* No generic column available for other field nature. */
                ABORT_NOW();