MINOR: stats: support rate in stats-file

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.
This commit is contained in:
Amaury Denoyelle 2024-04-29 16:34:22 +02:00
parent 639e73f8f2
commit fec2ae9b76
3 changed files with 20 additions and 0 deletions

View 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.

View 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;

View 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();