From: Willy Tarreau Date: Mon, 11 Jan 2016 17:27:29 +0000 (+0100) Subject: MINOR: stats: add stats_dump_info_fields() to dump one field per line X-Git-Tag: v1.7-dev2~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf95cba0e4bc9e2c719da579535265291fdd6662;p=thirdparty%2Fhaproxy.git MINOR: stats: add stats_dump_info_fields() to dump one field per line This function dumps non-empty fields, one per line with their name and values, in the same format as is currently used by "show info". It relies on previously added stats_emit_raw_data_field(). --- diff --git a/src/dumpstats.c b/src/dumpstats.c index 4f21eea938..05facda7df 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -2824,6 +2824,25 @@ static int stats_emit_raw_data_field(struct chunk *out, const struct field *f) } } +/* Dump all fields from into using the "show info" format (name: value) */ +static int stats_dump_info_fields(struct chunk *out, const struct field *info) +{ + int field; + + for (field = 0; field < INF_TOTAL_FIELDS; field++) { + if (!field_format(info, field)) + continue; + + if (!chunk_appendf(out, "%s: ", info_field_names[field])) + return 0; + if (!stats_emit_raw_data_field(out, &info[field])) + return 0; + if (!chunk_strcat(out, "\n")) + return 0; + } + return 1; +} + /* This function dumps information onto the stream interface's read buffer. * It returns 0 as long as it does not complete, non-zero upon completion. * No state is used.