smallint is26;
// 1 if sample delay is not an integer fraction of a second
smallint need_seconds;
+ char final_char;
char *cur_outbuf;
- const char *final_str;
int delta;
int deltanz;
struct timeval tv;
#define is26 (G.is26 )
#define need_seconds (G.need_seconds )
#define cur_outbuf (G.cur_outbuf )
-#define final_str (G.final_str )
#define delta (G.delta )
#define deltanz (G.deltanz )
#define tv (G.tv )
#define INIT_G() do { \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
cur_outbuf = outbuf; \
- final_str = "\n"; \
+ G.final_char = '\n'; \
deltanz = delta = 1000000; \
} while (0)
put(buf);
}
-
#define S_STAT(a) \
typedef struct a { \
struct s_stat *next; \
static s_stat* init_cr(const char *param UNUSED_PARAM)
{
- final_str = "\r";
- return (s_stat*)0;
+ G.final_char = '\r';
+ return NULL;
}
-
// user nice system idle iowait irq softirq (last 3 only in 2.6)
//cpu 649369 0 341297 4336769 11640 7122 1183
//cpuN 649369 0 341297 4336769 11640 7122 1183
S_STAT(cpu_stat)
ullong old[CPU_FIELDCNT];
int bar_sz;
- char *bar;
+ char bar[1];
S_STAT_END(cpu_stat)
-
static void FAST_FUNC collect_cpu(cpu_stat *s)
{
ullong data[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 };
put(s->bar);
}
-
static s_stat* init_cpu(const char *param)
{
int sz;
- cpu_stat *s = xzalloc(sizeof(*s));
- s->collect = collect_cpu;
+ cpu_stat *s;
sz = strtoul(param, NULL, 0); /* param can be "" */
if (sz < 10) sz = 10;
if (sz > 1000) sz = 1000;
- s->bar = xzalloc(sz+1);
+ s = xzalloc(sizeof(*s) + sz);
/*s->bar[sz] = '\0'; - xzalloc did it */
s->bar_sz = sz;
+ s->collect = collect_cpu;
return (s_stat*)s;
}
-
S_STAT(int_stat)
ullong old;
int no;
return (s_stat*)s;
}
-
S_STAT(ctx_stat)
ullong old;
S_STAT_END(ctx_stat)
return (s_stat*)s;
}
-
S_STAT(blk_stat)
const char* lookfor;
ullong old[2];
return (s_stat*)s;
}
-
S_STAT(fork_stat)
ullong old;
S_STAT_END(fork_stat)
return (s_stat*)s;
}
-
S_STAT(if_stat)
ullong old[4];
const char *device;
return (s_stat*)s;
}
-
S_STAT(mem_stat)
char opt;
S_STAT_END(mem_stat)
return (s_stat*)s;
}
-
S_STAT(swp_stat)
S_STAT_END(swp_stat)
return (s_stat*)s;
}
-
S_STAT(fd_stat)
S_STAT_END(fd_stat)
return (s_stat*)s;
}
-
S_STAT(time_stat)
- int prec;
- int scale;
+ unsigned prec;
+ unsigned scale;
S_STAT_END(time_stat)
static void FAST_FUNC collect_time(time_stat *s)
{
char buf[sizeof("12:34:56.123456")];
struct tm* tm;
- int us = tv.tv_usec + s->scale/2;
+ unsigned us = tv.tv_usec + s->scale/2;
time_t t = tv.tv_sec;
if (us >= 1000000) {
}
}
-
typedef s_stat* init_func(const char *param);
// Deprecated %NNNd is to be removed, -d MSEC supersedes it
while (1) {
gettimeofday(&tv, NULL);
collect_info(first);
- put(final_str);
+ put_c(G.final_char);
print_outbuf();
// Negative delta -> no usleep at all