/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "net.h"
#include "ioloop.h"
#include "istream.h"
#include "hash.h"
#include "str.h"
#include "strescape.h"
#include "strescape.h"
#include "write-full.h"
#include "doveadm.h"
#include "doveadm-print.h"
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
struct top_line {
char *id;
/* [headers_count] */
};
struct top_context {
const char *path;
int fd;
const char *sort_type;
char **headers;
unsigned int headers_count;
/* id => struct top_line. */
};
static char **
{
const char *line;
return NULL;
}
static const char *const*
{
}
{
const char *const *args;
unsigned int i;
int fd;
/* read header */
i_info("no statistics available");
else {
/* read lines */
do {
T_BEGIN {
doveadm_print(args[i]);
}
} T_END;
}
if (input->stream_errno != 0)
}
static void
{
i_error("Missing type parameter");
return;
}
/* purely optional */
return;
}
static void
{
const char **values;
unsigned int i;
} else {
}
/* line hasn't been updated, keep old values */
line->prev_values =
for (i = 0; i < ctx->headers_count; i++)
}
{
unsigned int i;
char **args;
/* read lines */
/* end of stats */
return;
}
for (i = 0; i < ctx->headers_count; i++)
}
}
}
}
{
char *id;
}
}
{
char *p;
return *p == '\0' ? 0 : -1;
}
{
i_fatal("sorting: invalid last_update value");
i_fatal("sorting: not a double");
i_fatal("sorting: not a double");
}
return diff * time_multiplier;
}
{
return -1;
return 1;
}
{
i_fatal("sorting: not a number");
i_fatal("sorting: not a number");
}
return diff;
}
{
return -1;
return 1;
}
static bool
unsigned int *idx_r)
{
unsigned int i;
*idx_r = i;
return TRUE;
}
}
return FALSE;
}
{
return;
i_fatal("cpu sort type is missing fields");
return;
}
i_fatal("disk sort type is missing fields");
return;
}
}
{
const char *const *args;
/* read header */
return TRUE;
i_fatal("headers changed");
} else {
return FALSE;
}
i_fatal("last_update header missing");
i_fatal("user header missing");
}
return TRUE;
}
static void
{
i_unreached();
/* %CPU */
(int)((cur_double - prev_double) *
i_unreached();
} else {
}
}
{
static const char *names[] = {
"user", "service", "user_cpu", "sys_cpu",
"", ""
};
/* ANSI clear screen and move cursor to top of screen */
doveadm_print_header_simple("SERVICE");
doveadm_print_header_simple("%CPU");
doveadm_print_header_simple("%SYS");
doveadm_print_header_simple("DISKIN");
doveadm_print_header_simple("DISKOUT");
if (!stats_top_round(ctx)) {
/* no connections yet */
return;
}
for (i = 0; i < N_ELEMENTS(names); i++) {
}
for (j = 0; j < N_ELEMENTS(names); j++) {
doveadm_print("?");
else
}
}
}
{
timeout_remove(&to);
}
{
else
}
{
const char *line;
/* XXX: Not supported yet.
for(ptr = items; *ptr; ptr++)
{
str_append_c(cmd, '\t');
str_append(cmd, *ptr);
}
*/
/* send command */
if (ret < 0) {
i_close_fd(&fd);
return;
}
} else {
i_info("Stats reset");
}
i_close_fd(&fd);
}
{
int c;
switch (c) {
case 'b':
disk_input_field = "read_bytes";
disk_output_field = "write_bytes";
break;
case 's':
break;
default:
}
}
sort_type = "disk";
else
}
{
const char *path;
int c;
switch (c) {
case 's':
break;
default:
}
}
/* items is now argv */
/* if (optind >= argc) {
i_fatal("missing item(s) to reset");
}
*/
}
.name = "oldstats dump",
.usage = "[-s <stats socket path>] <type> [<filter>]",
};
.old_cmd = cmd_stats_top,
.name = "oldstats top",
.usage = "[-s <stats socket path>] [-b] [<sort field>]",
};
.name = "oldstats reset",
.usage = "[-s <stats socket path>]",
};