Skip to content

Commit

Permalink
doveadm stats dump: Add stddev field
Browse files Browse the repository at this point in the history
Include it in default output as well.
  • Loading branch information
sirainen authored and cmouse committed Aug 7, 2018
1 parent c7c7cd4 commit 9113edb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/doveadm/Makefile.am
Expand Up @@ -50,7 +50,8 @@ doveadm_LDADD = \
$(LIBDOVECOT_STORAGE) \
$(LIBDOVECOT) \
$(LIBSODIUM_LIBS) \
$(BINARY_LDFLAGS)
$(BINARY_LDFLAGS) \
-lm

doveadm_DEPENDENCIES = \
$(libs) \
Expand All @@ -62,7 +63,8 @@ doveadm_server_LDADD = \
$(libs) \
$(LIBDOVECOT_STORAGE) \
$(LIBDOVECOT) \
$(BINARY_LDFLAGS)
$(BINARY_LDFLAGS) \
-lm

doveadm_server_DEPENDENCIES = \
$(libs) \
Expand Down
42 changes: 35 additions & 7 deletions src/doveadm/doveadm-stats.c
Expand Up @@ -10,17 +10,38 @@
#include "doveadm.h"
#include "doveadm-print.h"

#include <math.h>

#define DOVEADM_DUMP_DEFAULT_FIELDS \
"count sum min max avg median %95"
"count sum min max avg median stddev %95"

enum doveadm_dump_field_type {
DOVEADM_DUMP_FIELD_TYPE_PASSTHROUGH = 0,
DOVEADM_DUMP_FIELD_TYPE_STDDEV,
};

static void dump_timing(const char *const **args, unsigned int fields_count)
static void dump_timing(const char *const **args,
const enum doveadm_dump_field_type field_types[],
unsigned int fields_count)
{
unsigned int i, args_count = str_array_length(*args);

if (args_count > fields_count)
args_count = fields_count;
for (i = 0; i < args_count; i++)
doveadm_print((*args)[i]);
for (i = 0; i < args_count; i++) {
const char *value = (*args)[i];

switch (field_types[i]) {
case DOVEADM_DUMP_FIELD_TYPE_PASSTHROUGH:
break;
case DOVEADM_DUMP_FIELD_TYPE_STDDEV: {
double variance = strtod(value, NULL);
value = t_strdup_printf("%.02f", sqrt(variance));
break;
}
}
doveadm_print(value);
}
*args += args_count;
}

Expand All @@ -29,16 +50,23 @@ static void stats_dump(const char *path, const char *const *fields, bool reset)
struct istream *input;
string_t *cmd = t_str_new(128);
unsigned int i, fields_count = str_array_length(fields);
enum doveadm_dump_field_type field_types[fields_count];
char *line;
int fd;

fd = doveadm_connect(path);
net_set_nonblock(fd, FALSE);
str_append(cmd, "VERSION\tstats-reader-client\t2\t0\n");
str_append(cmd, reset ? "DUMP-RESET" : "DUMP");
i_zero(field_types);
for (i = 0; i < fields_count; i++) {
str_append_c(cmd, '\t');
str_append_tabescaped(cmd, fields[i]);
if (strcmp(fields[i], "stddev") == 0) {
field_types[i] = DOVEADM_DUMP_FIELD_TYPE_STDDEV;
str_append(cmd, "variance");
} else {
str_append_tabescaped(cmd, fields[i]);
}
}
str_append_c(cmd, '\n');
if (write_full(fd, str_data(cmd), str_len(cmd)) < 0)
Expand Down Expand Up @@ -67,11 +95,11 @@ static void stats_dump(const char *path, const char *const *fields, bool reset)
const char *metric_name = args[0];
doveadm_print(metric_name); args++;
doveadm_print("duration");
dump_timing(&args, fields_count);
dump_timing(&args, field_types, fields_count);
while (*args != NULL) {
doveadm_print(metric_name);
doveadm_print(*args); args++;
dump_timing(&args, fields_count);
dump_timing(&args, field_types, fields_count);
}
} T_END;
}
Expand Down

0 comments on commit 9113edb

Please sign in to comment.