summaryrefslogtreecommitdiffstats
path: root/ui/cli/tap-iostat.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:26 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:26 +0000
commitc4e8a3222648fcf22ca207f1815ebbf7cd144eeb (patch)
tree93d5c6aa93d9987680dd1adad5685e2ad698f223 /ui/cli/tap-iostat.c
parentAdding upstream version 4.2.6. (diff)
downloadwireshark-upstream.tar.xz
wireshark-upstream.zip
Adding upstream version 4.4.0.upstream/4.4.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--ui/cli/tap-iostat.c310
1 files changed, 157 insertions, 153 deletions
diff --git a/ui/cli/tap-iostat.c b/ui/cli/tap-iostat.c
index 83810b23..2ba79a2c 100644
--- a/ui/cli/tap-iostat.c
+++ b/ui/cli/tap-iostat.c
@@ -50,34 +50,37 @@ static calc_type_ent_t calc_type_table[] = {
};
typedef struct _io_stat_t {
- guint64 interval; /* The user-specified time interval (us) */
- guint invl_prec; /* Decimal precision of the time interval (1=10s, 2=100s etc) */
+ uint64_t interval; /* The user-specified time interval (us) */
+ unsigned invl_prec; /* Decimal precision of the time interval (1=10s, 2=100s etc) */
unsigned int num_cols; /* The number of columns of stats in the table */
struct _io_stat_item_t *items; /* Each item is a single cell in the table */
time_t start_time; /* Time of first frame matching the filter */
+ /* The following are all per-column fixed information arrays */
const char **filters; /* 'io,stat' cmd strings (e.g., "AVG(smb.time)smb.time") */
- guint64 *max_vals; /* The max value sans the decimal or nsecs portion in each stat column */
- guint32 *max_frame; /* The max frame number displayed in each stat column */
+ uint64_t *max_vals; /* The max value sans the decimal or nsecs portion in each stat column */
+ uint32_t *max_frame; /* The max frame number displayed in each stat column */
+ int *hf_indexes;
+ int *calc_type; /* The statistic type */
} io_stat_t;
typedef struct _io_stat_item_t {
io_stat_t *parent;
struct _io_stat_item_t *next;
struct _io_stat_item_t *prev;
- guint64 start_time; /* Time since start of capture (us)*/
- int calc_type; /* The statistic type */
+ uint64_t start_time; /* Time since start of capture (us)*/
int colnum; /* Column number of this stat (0 to n) */
- int hf_index;
- guint32 frames;
- guint32 num; /* The sample size of a given statistic (only needed for AVG) */
- guint64 counter; /* The accumulated data for the calculation of that statistic */
- gfloat float_counter;
- gdouble double_counter;
+ uint32_t frames;
+ uint32_t num; /* The sample size of a given statistic (only needed for AVG) */
+ union { /* The accumulated data for the calculation of that statistic */
+ uint64_t counter;
+ float float_counter;
+ double double_counter;
+ };
} io_stat_item_t;
-#define NANOSECS_PER_SEC G_GUINT64_CONSTANT(1000000000)
+#define NANOSECS_PER_SEC UINT64_C(1000000000)
-static guint64 last_relative_time;
+static uint64_t last_relative_time;
static tap_packet_status
iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *dummy _U_, tap_flags_t flags _U_)
@@ -85,10 +88,10 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
io_stat_t *parent;
io_stat_item_t *mit;
io_stat_item_t *it;
- guint64 relative_time, rt;
+ uint64_t relative_time, rt;
const nstime_t *new_time;
GPtrArray *gp;
- guint i;
+ unsigned i;
int ftype;
mit = (io_stat_item_t *) arg;
@@ -97,8 +100,8 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
/* If this frame's relative time is negative, set its relative time to last_relative_time
rather than disincluding it from the calculations. */
if ((pinfo->rel_ts.secs >= 0) && (pinfo->rel_ts.nsecs >= 0)) {
- relative_time = ((guint64)pinfo->rel_ts.secs * G_GUINT64_CONSTANT(1000000)) +
- ((guint64)((pinfo->rel_ts.nsecs+500)/1000));
+ relative_time = ((uint64_t)pinfo->rel_ts.secs * UINT64_C(1000000)) +
+ ((uint64_t)((pinfo->rel_ts.nsecs+500)/1000));
last_relative_time = relative_time;
} else {
relative_time = last_relative_time;
@@ -124,37 +127,33 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
it->start_time = it->prev->start_time + parent->interval;
it->frames = 0;
- it->counter = 0;
- it->float_counter = 0;
- it->double_counter = 0;
+ it->counter = 0; /* 64-bit, type-punning with double is fine */
it->num = 0;
- it->calc_type = it->prev->calc_type;
- it->hf_index = it->prev->hf_index;
it->colnum = it->prev->colnum;
}
/* Store info in the current structure */
it->frames++;
- switch (it->calc_type) {
+ switch (parent->calc_type[it->colnum]) {
case CALC_TYPE_FRAMES:
case CALC_TYPE_BYTES:
case CALC_TYPE_FRAMES_AND_BYTES:
it->counter += pinfo->fd->pkt_len;
break;
case CALC_TYPE_COUNT:
- gp = proto_get_finfo_ptr_array(edt->tree, it->hf_index);
+ gp = proto_get_finfo_ptr_array(edt->tree, parent->hf_indexes[it->colnum]);
if (gp) {
it->counter += gp->len;
}
break;
case CALC_TYPE_SUM:
- gp = proto_get_finfo_ptr_array(edt->tree, it->hf_index);
+ gp = proto_get_finfo_ptr_array(edt->tree, parent->hf_indexes[it->colnum]);
if (gp) {
- guint64 val;
+ uint64_t val;
for (i=0; i<gp->len; i++) {
- switch (proto_registrar_get_ftype(it->hf_index)) {
+ switch (proto_registrar_get_ftype(parent->hf_indexes[it->colnum])) {
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
@@ -177,18 +176,18 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
case FT_INT48:
case FT_INT56:
case FT_INT64:
- it->counter += (gint64)fvalue_get_sinteger64(((field_info *)gp->pdata[i])->value);
+ it->counter += (int64_t)fvalue_get_sinteger64(((field_info *)gp->pdata[i])->value);
break;
case FT_FLOAT:
it->float_counter +=
- (gfloat)fvalue_get_floating(((field_info *)gp->pdata[i])->value);
+ (float)fvalue_get_floating(((field_info *)gp->pdata[i])->value);
break;
case FT_DOUBLE:
it->double_counter += fvalue_get_floating(((field_info *)gp->pdata[i])->value);
break;
case FT_RELATIVE_TIME:
new_time = fvalue_get_time(((field_info *)gp->pdata[i])->value);
- val = ((guint64)new_time->secs * NANOSECS_PER_SEC) + (guint64)new_time->nsecs;
+ val = ((uint64_t)new_time->secs * NANOSECS_PER_SEC) + (uint64_t)new_time->nsecs;
it->counter += val;
break;
default:
@@ -203,13 +202,13 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
}
break;
case CALC_TYPE_MIN:
- gp = proto_get_finfo_ptr_array(edt->tree, it->hf_index);
+ gp = proto_get_finfo_ptr_array(edt->tree, parent->hf_indexes[it->colnum]);
if (gp) {
- guint64 val;
- gfloat float_val;
- gdouble double_val;
+ uint64_t val;
+ float float_val;
+ double double_val;
- ftype = proto_registrar_get_ftype(it->hf_index);
+ ftype = proto_registrar_get_ftype(parent->hf_indexes[it->colnum]);
for (i=0; i<gp->len; i++) {
switch (ftype) {
case FT_UINT8:
@@ -235,7 +234,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
case FT_INT24:
case FT_INT32:
val = fvalue_get_sinteger(((field_info *)gp->pdata[i])->value);
- if ((it->frames == 1 && i == 0) || ((gint32)val < (gint32)it->counter)) {
+ if ((it->frames == 1 && i == 0) || ((int32_t)val < (int32_t)it->counter)) {
it->counter = val;
}
break;
@@ -244,12 +243,12 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
case FT_INT56:
case FT_INT64:
val = fvalue_get_sinteger64(((field_info *)gp->pdata[i])->value);
- if ((it->frames == 1 && i == 0) || ((gint64)val < (gint64)it->counter)) {
+ if ((it->frames == 1 && i == 0) || ((int64_t)val < (int64_t)it->counter)) {
it->counter = val;
}
break;
case FT_FLOAT:
- float_val = (gfloat)fvalue_get_floating(((field_info *)gp->pdata[i])->value);
+ float_val = (float)fvalue_get_floating(((field_info *)gp->pdata[i])->value);
if ((it->frames == 1 && i == 0) || (float_val < it->float_counter)) {
it->float_counter = float_val;
}
@@ -262,7 +261,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
break;
case FT_RELATIVE_TIME:
new_time = fvalue_get_time(((field_info *)gp->pdata[i])->value);
- val = ((guint64)new_time->secs * NANOSECS_PER_SEC) + (guint64)new_time->nsecs;
+ val = ((uint64_t)new_time->secs * NANOSECS_PER_SEC) + (uint64_t)new_time->nsecs;
if ((it->frames == 1 && i == 0) || (val < it->counter)) {
it->counter = val;
}
@@ -279,13 +278,13 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
}
break;
case CALC_TYPE_MAX:
- gp = proto_get_finfo_ptr_array(edt->tree, it->hf_index);
+ gp = proto_get_finfo_ptr_array(edt->tree, parent->hf_indexes[it->colnum]);
if (gp) {
- guint64 val;
- gfloat float_val;
- gdouble double_val;
+ uint64_t val;
+ float float_val;
+ double double_val;
- ftype = proto_registrar_get_ftype(it->hf_index);
+ ftype = proto_registrar_get_ftype(parent->hf_indexes[it->colnum]);
for (i=0; i<gp->len; i++) {
switch (ftype) {
case FT_UINT8:
@@ -309,7 +308,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
case FT_INT24:
case FT_INT32:
val = fvalue_get_sinteger(((field_info *)gp->pdata[i])->value);
- if ((gint32)val > (gint32)it->counter)
+ if ((int32_t)val > (int32_t)it->counter)
it->counter = val;
break;
case FT_INT40:
@@ -317,11 +316,11 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
case FT_INT56:
case FT_INT64:
val = fvalue_get_sinteger64(((field_info *)gp->pdata[i])->value);
- if ((gint64)val > (gint64)it->counter)
+ if ((int64_t)val > (int64_t)it->counter)
it->counter = val;
break;
case FT_FLOAT:
- float_val = (gfloat)fvalue_get_floating(((field_info *)gp->pdata[i])->value);
+ float_val = (float)fvalue_get_floating(((field_info *)gp->pdata[i])->value);
if (float_val > it->float_counter)
it->float_counter = float_val;
break;
@@ -332,7 +331,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
break;
case FT_RELATIVE_TIME:
new_time = fvalue_get_time(((field_info *)gp->pdata[i])->value);
- val = ((guint64)new_time->secs * NANOSECS_PER_SEC) + (guint64)new_time->nsecs;
+ val = ((uint64_t)new_time->secs * NANOSECS_PER_SEC) + (uint64_t)new_time->nsecs;
if (val > it->counter)
it->counter = val;
break;
@@ -348,11 +347,11 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
}
break;
case CALC_TYPE_AVG:
- gp = proto_get_finfo_ptr_array(edt->tree, it->hf_index);
+ gp = proto_get_finfo_ptr_array(edt->tree, parent->hf_indexes[it->colnum]);
if (gp) {
- guint64 val;
+ uint64_t val;
- ftype = proto_registrar_get_ftype(it->hf_index);
+ ftype = proto_registrar_get_ftype(parent->hf_indexes[it->colnum]);
for (i=0; i<gp->len; i++) {
it->num++;
switch (ftype) {
@@ -385,14 +384,14 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
it->counter += val;
break;
case FT_FLOAT:
- it->float_counter += (gfloat)fvalue_get_floating(((field_info *)gp->pdata[i])->value);
+ it->float_counter += (float)fvalue_get_floating(((field_info *)gp->pdata[i])->value);
break;
case FT_DOUBLE:
it->double_counter += fvalue_get_floating(((field_info *)gp->pdata[i])->value);
break;
case FT_RELATIVE_TIME:
new_time = fvalue_get_time(((field_info *)gp->pdata[i])->value);
- val = ((guint64)new_time->secs * NANOSECS_PER_SEC) + (guint64)new_time->nsecs;
+ val = ((uint64_t)new_time->secs * NANOSECS_PER_SEC) + (uint64_t)new_time->nsecs;
it->counter += val;
break;
default:
@@ -407,27 +406,27 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
}
break;
case CALC_TYPE_LOAD:
- gp = proto_get_finfo_ptr_array(edt->tree, it->hf_index);
+ gp = proto_get_finfo_ptr_array(edt->tree, parent->hf_indexes[it->colnum]);
if (gp) {
- ftype = proto_registrar_get_ftype(it->hf_index);
+ ftype = proto_registrar_get_ftype(parent->hf_indexes[it->colnum]);
if (ftype != FT_RELATIVE_TIME) {
fprintf(stderr,
"\ntshark: LOAD() is only supported for relative-time fields such as smb.time\n");
exit(10);
}
for (i=0; i<gp->len; i++) {
- guint64 val;
+ uint64_t val;
int tival;
io_stat_item_t *pit;
new_time = fvalue_get_time(((field_info *)gp->pdata[i])->value);
- val = ((guint64)new_time->secs*G_GUINT64_CONSTANT(1000000)) + (guint64)(new_time->nsecs/1000);
+ val = ((uint64_t)new_time->secs*UINT64_C(1000000)) + (uint64_t)(new_time->nsecs/1000);
tival = (int)(val % parent->interval);
it->counter += tival;
val -= tival;
pit = it->prev;
while (val > 0) {
- if (val < (guint64)parent->interval) {
+ if (val < (uint64_t)parent->interval) {
pit->counter += val;
break;
}
@@ -445,12 +444,12 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
* calc the average, round it to the next second and store the seconds. For all other calc types
* of RELATIVE_TIME fields, store the counters without modification.
* fields. */
- switch (it->calc_type) {
+ switch (parent->calc_type[it->colnum]) {
case CALC_TYPE_FRAMES:
case CALC_TYPE_FRAMES_AND_BYTES:
parent->max_frame[it->colnum] =
MAX(parent->max_frame[it->colnum], it->frames);
- if (it->calc_type == CALC_TYPE_FRAMES_AND_BYTES)
+ if (parent->calc_type[it->colnum] == CALC_TYPE_FRAMES_AND_BYTES)
parent->max_vals[it->colnum] =
MAX(parent->max_vals[it->colnum], it->counter);
break;
@@ -462,15 +461,15 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
case CALC_TYPE_SUM:
case CALC_TYPE_MIN:
case CALC_TYPE_MAX:
- ftype = proto_registrar_get_ftype(it->hf_index);
+ ftype = proto_registrar_get_ftype(parent->hf_indexes[it->colnum]);
switch (ftype) {
case FT_FLOAT:
parent->max_vals[it->colnum] =
- MAX(parent->max_vals[it->colnum], (guint64)(it->float_counter+0.5));
+ MAX(parent->max_vals[it->colnum], (uint64_t)(it->float_counter+0.5));
break;
case FT_DOUBLE:
parent->max_vals[it->colnum] =
- MAX(parent->max_vals[it->colnum], (guint64)(it->double_counter+0.5));
+ MAX(parent->max_vals[it->colnum], (uint64_t)(it->double_counter+0.5));
break;
case FT_RELATIVE_TIME:
parent->max_vals[it->colnum] =
@@ -486,19 +485,19 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
case CALC_TYPE_AVG:
if (it->num == 0) /* avoid division by zero */
break;
- ftype = proto_registrar_get_ftype(it->hf_index);
+ ftype = proto_registrar_get_ftype(parent->hf_indexes[it->colnum]);
switch (ftype) {
case FT_FLOAT:
parent->max_vals[it->colnum] =
- MAX(parent->max_vals[it->colnum], (guint64)it->float_counter/it->num);
+ MAX(parent->max_vals[it->colnum], (uint64_t)it->float_counter/it->num);
break;
case FT_DOUBLE:
parent->max_vals[it->colnum] =
- MAX(parent->max_vals[it->colnum], (guint64)it->double_counter/it->num);
+ MAX(parent->max_vals[it->colnum], (uint64_t)it->double_counter/it->num);
break;
case FT_RELATIVE_TIME:
parent->max_vals[it->colnum] =
- MAX(parent->max_vals[it->colnum], ((it->counter/(guint64)it->num) + G_GUINT64_CONSTANT(500000000)) / NANOSECS_PER_SEC);
+ MAX(parent->max_vals[it->colnum], ((it->counter/(uint64_t)it->num) + UINT64_C(500000000)) / NANOSECS_PER_SEC);
break;
default:
/* UINT16-64 and INT8-64 */
@@ -511,7 +510,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
}
static unsigned int
-magnitude (guint64 val, unsigned int max_w)
+magnitude (uint64_t val, unsigned int max_w)
{
unsigned int i, mag = 0;
@@ -553,8 +552,8 @@ typedef struct {
static void
iostat_draw(void *arg)
{
- guint32 num;
- guint64 interval, duration, t, invl_end, dv;
+ uint32_t num;
+ uint64_t interval, duration, t, invl_end, dv;
unsigned int i, j, k, num_cols, num_rows, dur_secs_orig, dur_nsecs_orig, dur_secs, dur_nsecs, dur_mag,
invl_mag, invl_prec, tabrow_w, borderlen, invl_col_w, numpad = 1, namelen, len_filt, type,
maxfltr_w, ftype;
@@ -562,9 +561,9 @@ iostat_draw(void *arg)
unsigned int val_mag; /* The magnitude of the max value in this column */
char *spaces, *spaces_s, *filler_s = NULL, **fmts, *fmt = NULL;
const char *filter;
- static gchar dur_mag_s[3], invl_prec_s[3], fr_mag_s[3], val_mag_s[3], *invl_fmt, *full_fmt;
+ static char dur_mag_s[3], invl_prec_s[3], fr_mag_s[3], val_mag_s[3], *invl_fmt, *full_fmt;
io_stat_item_t *mit, **stat_cols, *item, **item_in_column;
- gboolean last_row = FALSE;
+ bool last_row = false;
io_stat_t *iot;
column_width *col_w;
struct tm *tm_time;
@@ -575,8 +574,8 @@ iostat_draw(void *arg)
num_cols = iot->num_cols;
col_w = g_new(column_width, num_cols);
fmts = (char **)g_malloc(sizeof(char *) * num_cols);
- duration = ((guint64)cfile.elapsed_time.secs * G_GUINT64_CONSTANT(1000000)) +
- (guint64)((cfile.elapsed_time.nsecs + 500) / 1000);
+ duration = ((uint64_t)cfile.elapsed_time.secs * UINT64_C(1000000)) +
+ (uint64_t)((cfile.elapsed_time.nsecs + 500) / 1000);
/* Store the pointer to each stat column */
stat_cols = (io_stat_item_t **)g_malloc(sizeof(io_stat_item_t *) * num_cols);
@@ -585,23 +584,23 @@ iostat_draw(void *arg)
/* The following prevents gross inaccuracies when the user specifies an interval that is greater
* than the capture duration. */
- if (iot->interval > duration || iot->interval == G_MAXUINT64) {
+ if (iot->interval > duration || iot->interval == UINT64_MAX) {
interval = duration;
- iot->interval = G_MAXUINT64;
+ iot->interval = UINT64_MAX;
} else {
interval = iot->interval;
}
/* Calc the capture duration's magnitude (dur_mag) */
- dur_secs = (unsigned int)(duration/G_GUINT64_CONSTANT(1000000));
+ dur_secs = (unsigned int)(duration/UINT64_C(1000000));
dur_secs_orig = dur_secs;
- dur_nsecs = (unsigned int)(duration%G_GUINT64_CONSTANT(1000000));
+ dur_nsecs = (unsigned int)(duration%UINT64_C(1000000));
dur_nsecs_orig = dur_nsecs;
- dur_mag = magnitude((guint64)dur_secs, 5);
+ dur_mag = magnitude((uint64_t)dur_secs, 5);
snprintf(dur_mag_s, 3, "%u", dur_mag);
/* Calc the interval's magnitude */
- invl_mag = magnitude(interval/G_GUINT64_CONSTANT(1000000), 5);
+ invl_mag = magnitude(interval/UINT64_C(1000000), 5);
/* Set or get the interval precision */
if (interval == duration) {
@@ -628,13 +627,13 @@ iostat_draw(void *arg)
if ((duration%dv) > 5*(dv/10)) {
duration += 5*(dv/10);
duration = (duration/dv) * dv;
- dur_secs = (unsigned int)(duration/G_GUINT64_CONSTANT(1000000));
- dur_nsecs = (unsigned int)(duration%G_GUINT64_CONSTANT(1000000));
+ dur_secs = (unsigned int)(duration/UINT64_C(1000000));
+ dur_nsecs = (unsigned int)(duration%UINT64_C(1000000));
/*
* Recalc dur_mag in case rounding has increased its magnitude */
- dur_mag = magnitude((guint64)dur_secs, 5);
+ dur_mag = magnitude((uint64_t)dur_secs, 5);
}
- if (iot->interval == G_MAXUINT64)
+ if (iot->interval == UINT64_MAX)
interval = duration;
/* Calc the width of the time interval column (incl borders and padding). */
@@ -665,7 +664,7 @@ iostat_draw(void *arg)
* is an *integer*. */
tabrow_w = invl_col_w;
for (j=0; j<num_cols; j++) {
- type = iot->items[j].calc_type;
+ type = iot->calc_type[j];
if (type == CALC_TYPE_FRAMES_AND_BYTES) {
namelen = 5;
} else {
@@ -708,7 +707,7 @@ iostat_draw(void *arg)
break;
default:
- ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
+ ftype = proto_registrar_get_ftype(iot->hf_indexes[j]);
switch (ftype) {
case FT_FLOAT:
case FT_DOUBLE:
@@ -723,7 +722,7 @@ iostat_draw(void *arg)
if (type == CALC_TYPE_LOAD) {
iot->max_vals[j] /= interval;
} else if (type != CALC_TYPE_AVG) {
- iot->max_vals[j] = (iot->max_vals[j] + G_GUINT64_CONSTANT(500000000)) / NANOSECS_PER_SEC;
+ iot->max_vals[j] = (iot->max_vals[j] + UINT64_C(500000000)) / NANOSECS_PER_SEC;
}
val_mag = magnitude(iot->max_vals[j], 15);
snprintf(val_mag_s, 3, "%u", val_mag);
@@ -808,7 +807,7 @@ iostat_draw(void *arg)
g_free(full_fmt);
full_fmt = g_strconcat("| Interval: ", invl_fmt, " secs%s|\n", NULL);
spaces_s = &spaces[18 + dur_mag];
- printf(full_fmt, (guint32)(interval/G_GUINT64_CONSTANT(1000000)), spaces_s);
+ printf(full_fmt, (uint32_t)(interval/UINT64_C(1000000)), spaces_s);
} else {
snprintf(invl_prec_s, 3, "%u", invl_prec);
invl_fmt = g_strconcat("%", dur_mag_s, "u.%0", invl_prec_s, "u", NULL);
@@ -819,8 +818,8 @@ iostat_draw(void *arg)
full_fmt = g_strconcat("| Interval: ", invl_fmt, " secs%s|\n", NULL);
spaces_s = &spaces[19 + dur_mag + invl_prec];
- printf(full_fmt, (guint32)(interval/G_GUINT64_CONSTANT(1000000)),
- (guint32)((interval%G_GUINT64_CONSTANT(1000000))/dv), spaces_s);
+ printf(full_fmt, (uint32_t)(interval/UINT64_C(1000000)),
+ (uint32_t)((interval%UINT64_C(1000000))/dv), spaces_s);
}
g_free(full_fmt);
@@ -850,24 +849,24 @@ iostat_draw(void *arg)
}
printf("|\n");
} else {
- gchar *sfilter1, *sfilter2;
- const gchar *pos;
- gsize len;
+ char *sfilter1, *sfilter2;
+ const char *pos;
+ size_t len;
unsigned int next_start, max_w = borderlen-11;
do {
if (len_filt > max_w) {
- sfilter1 = g_strndup(filter, (gsize) max_w);
+ sfilter1 = g_strndup(filter, (size_t) max_w);
/*
* Find the pos of the last space in sfilter1. If a space is found, set
* sfilter2 to the string prior to that space and print it; otherwise, wrap
* the filter at max_w. */
pos = g_strrstr(sfilter1, " ");
if (pos) {
- len = (gsize)(pos-sfilter1);
+ len = (size_t)(pos-sfilter1);
next_start = (unsigned int) len+1;
} else {
- len = (gsize) strlen(sfilter1);
+ len = (size_t) strlen(sfilter1);
next_start = (unsigned int)len;
}
sfilter2 = g_strndup(sfilter1, len);
@@ -899,10 +898,9 @@ iostat_draw(void *arg)
/* Display column number headers */
for (j=0; j<num_cols; j++) {
- item = stat_cols[j];
- if (item->calc_type == CALC_TYPE_FRAMES_AND_BYTES)
+ if (iot->calc_type[j] == CALC_TYPE_FRAMES_AND_BYTES)
spaces_s = &spaces[borderlen - (col_w[j].fr + col_w[j].val)] - 3;
- else if (item->calc_type == CALC_TYPE_FRAMES)
+ else if (iot->calc_type[j] == CALC_TYPE_FRAMES)
spaces_s = &spaces[borderlen - col_w[j].fr];
else
spaces_s = &spaces[borderlen - col_w[j].val];
@@ -939,7 +937,7 @@ iostat_draw(void *arg)
/* Display the stat label in each column */
for (j=0; j<num_cols; j++) {
- type = stat_cols[j]->calc_type;
+ type = iot->calc_type[j];
if (type == CALC_TYPE_FRAMES) {
printcenter (calc_type_table[type].func_name, col_w[j].fr, numpad);
} else if (type == CALC_TYPE_FRAMES_AND_BYTES) {
@@ -985,7 +983,7 @@ iostat_draw(void *arg)
for (i=0; i<num_rows; i++) {
if (i == num_rows-1)
- last_row = TRUE;
+ last_row = true;
/* Compute the interval for this row */
if (!last_row) {
@@ -996,7 +994,7 @@ iostat_draw(void *arg)
/* Patch for Absolute Time */
/* XXX - has a Y2.038K problem with 32-bit time_t */
- the_time = (time_t)(iot->start_time + (t/G_GUINT64_CONSTANT(1000000)));
+ the_time = (time_t)(iot->start_time + (t/UINT64_C(1000000)));
/* Display the interval for this row */
switch (timestamp_get_type()) {
@@ -1087,16 +1085,16 @@ iostat_draw(void *arg)
full_fmt = g_strconcat( dur_mag == 1 ? "| " : "| ",
invl_fmt, " <> ", "%-",
dur_mag_s, "s|", NULL);
- printf(full_fmt, (guint32)(t/G_GUINT64_CONSTANT(1000000)), "Dur");
+ printf(full_fmt, (uint32_t)(t/UINT64_C(1000000)), "Dur");
} else {
- printf(full_fmt, (guint32)(t/G_GUINT64_CONSTANT(1000000)),
- (guint32)(invl_end/G_GUINT64_CONSTANT(1000000)));
+ printf(full_fmt, (uint32_t)(t/UINT64_C(1000000)),
+ (uint32_t)(invl_end/UINT64_C(1000000)));
}
} else {
- printf(full_fmt, (guint32)(t/G_GUINT64_CONSTANT(1000000)),
- (guint32)(t%G_GUINT64_CONSTANT(1000000) / dv),
- (guint32)(invl_end/G_GUINT64_CONSTANT(1000000)),
- (guint32)(invl_end%G_GUINT64_CONSTANT(1000000) / dv));
+ printf(full_fmt, (uint32_t)(t/UINT64_C(1000000)),
+ (uint32_t)(t%UINT64_C(1000000) / dv),
+ (uint32_t)(invl_end/UINT64_C(1000000)),
+ (uint32_t)(invl_end%UINT64_C(1000000) / dv));
}
break;
/* case TS_DELTA:
@@ -1111,9 +1109,10 @@ iostat_draw(void *arg)
for (j=0; j<num_cols; j++) {
fmt = fmts[j];
item = item_in_column[j];
+ type = iot->calc_type[j];
if (item) {
- switch (item->calc_type) {
+ switch (type) {
case CALC_TYPE_FRAMES:
printf(fmt, item->frames);
break;
@@ -1128,7 +1127,7 @@ iostat_draw(void *arg)
case CALC_TYPE_SUM:
case CALC_TYPE_MIN:
case CALC_TYPE_MAX:
- ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
+ ftype = proto_registrar_get_ftype(iot->hf_indexes[j]);
switch (ftype) {
case FT_FLOAT:
printf(fmt, item->float_counter);
@@ -1137,10 +1136,10 @@ iostat_draw(void *arg)
printf(fmt, item->double_counter);
break;
case FT_RELATIVE_TIME:
- item->counter = (item->counter + G_GUINT64_CONSTANT(500)) / G_GUINT64_CONSTANT(1000);
+ item->counter = (item->counter + UINT64_C(500)) / UINT64_C(1000);
printf(fmt,
- (int)(item->counter/G_GUINT64_CONSTANT(1000000)),
- (int)(item->counter%G_GUINT64_CONSTANT(1000000)));
+ (int)(item->counter/UINT64_C(1000000)),
+ (int)(item->counter%UINT64_C(1000000)));
break;
default:
printf(fmt, item->counter);
@@ -1152,7 +1151,7 @@ iostat_draw(void *arg)
num = item->num;
if (num == 0)
num = 1;
- ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
+ ftype = proto_registrar_get_ftype(iot->hf_indexes[j]);
switch (ftype) {
case FT_FLOAT:
printf(fmt, item->float_counter/num);
@@ -1161,29 +1160,29 @@ iostat_draw(void *arg)
printf(fmt, item->double_counter/num);
break;
case FT_RELATIVE_TIME:
- item->counter = ((item->counter / (guint64)num) + G_GUINT64_CONSTANT(500)) / G_GUINT64_CONSTANT(1000);
+ item->counter = ((item->counter / (uint64_t)num) + UINT64_C(500)) / UINT64_C(1000);
printf(fmt,
- (int)(item->counter/G_GUINT64_CONSTANT(1000000)),
- (int)(item->counter%G_GUINT64_CONSTANT(1000000)));
+ (int)(item->counter/UINT64_C(1000000)),
+ (int)(item->counter%UINT64_C(1000000)));
break;
default:
- printf(fmt, item->counter / (guint64)num);
+ printf(fmt, item->counter / (uint64_t)num);
break;
}
break;
case CALC_TYPE_LOAD:
- ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
+ ftype = proto_registrar_get_ftype(iot->hf_indexes[j]);
switch (ftype) {
case FT_RELATIVE_TIME:
if (!last_row) {
printf(fmt,
(int) (item->counter/interval),
- (int)((item->counter%interval)*G_GUINT64_CONSTANT(1000000) / interval));
+ (int)((item->counter%interval)*UINT64_C(1000000) / interval));
} else {
printf(fmt,
(int) (item->counter/(invl_end-t)),
- (int)((item->counter%(invl_end-t))*G_GUINT64_CONSTANT(1000000) / (invl_end-t)));
+ (int)((item->counter%(invl_end-t))*UINT64_C(1000000) / (invl_end-t)));
}
break;
}
@@ -1196,7 +1195,7 @@ iostat_draw(void *arg)
item_in_column[j] = item_in_column[j]->next;
}
} else {
- printf(fmt, (guint64)0, (guint64)0);
+ printf(fmt, (uint64_t)0, (uint64_t)0);
}
}
if (filler_s)
@@ -1210,8 +1209,11 @@ iostat_draw(void *arg)
}
printf("\n");
g_free(iot->items);
+ g_free((gpointer)iot->filters);
g_free(iot->max_vals);
g_free(iot->max_frame);
+ g_free(iot->hf_indexes);
+ g_free(iot->calc_type);
g_free(iot);
g_free(col_w);
g_free(invl_fmt);
@@ -1238,7 +1240,6 @@ register_io_tap(io_stat_t *io, unsigned int i, const char *filter)
io->items[i].next = NULL;
io->items[i].parent = io;
io->items[i].start_time = 0;
- io->items[i].calc_type = CALC_TYPE_FRAMES_AND_BYTES;
io->items[i].frames = 0;
io->items[i].counter = 0;
io->items[i].num = 0;
@@ -1246,12 +1247,13 @@ register_io_tap(io_stat_t *io, unsigned int i, const char *filter)
io->filters[i] = filter;
flt = filter;
+ io->calc_type[i] = CALC_TYPE_FRAMES_AND_BYTES;
field = NULL;
hfi = NULL;
for (j=0; calc_type_table[j].func_name; j++) {
namelen = strlen(calc_type_table[j].func_name);
if (filter && strncmp(filter, calc_type_table[j].func_name, namelen) == 0) {
- io->items[i].calc_type = calc_type_table[j].calc_type;
+ io->calc_type[i] = calc_type_table[j].calc_type;
io->items[i].colnum = i;
if (*(filter+namelen) == '(') {
p = filter+namelen+1;
@@ -1262,7 +1264,7 @@ register_io_tap(io_stat_t *io, unsigned int i, const char *filter)
exit(10);
}
- if (io->items[i].calc_type == CALC_TYPE_FRAMES || io->items[i].calc_type == CALC_TYPE_BYTES) {
+ if (io->calc_type[i] == CALC_TYPE_FRAMES || io->calc_type[i] == CALC_TYPE_BYTES) {
if (parenp != p) {
fprintf(stderr,
"\ntshark: %s does not require or allow a field name within the parens.\n",
@@ -1282,7 +1284,7 @@ register_io_tap(io_stat_t *io, unsigned int i, const char *filter)
memcpy(field, p, parenp-p);
field[parenp-p] = '\0';
flt = parenp + 1;
- if (io->items[i].calc_type == CALC_TYPE_FRAMES || io->items[i].calc_type == CALC_TYPE_BYTES)
+ if (io->calc_type[i] == CALC_TYPE_FRAMES || io->calc_type[i] == CALC_TYPE_BYTES)
break;
hfi = proto_registrar_get_byname(field);
if (!hfi) {
@@ -1292,18 +1294,18 @@ register_io_tap(io_stat_t *io, unsigned int i, const char *filter)
exit(10);
}
- io->items[i].hf_index = hfi->id;
+ io->hf_indexes[i] = hfi->id;
break;
}
} else {
- if (io->items[i].calc_type == CALC_TYPE_FRAMES || io->items[i].calc_type == CALC_TYPE_BYTES)
+ if (io->calc_type[i] == CALC_TYPE_FRAMES || io->calc_type[i] == CALC_TYPE_BYTES)
flt = "";
io->items[i].colnum = i;
}
}
- if (hfi && !(io->items[i].calc_type == CALC_TYPE_BYTES ||
- io->items[i].calc_type == CALC_TYPE_FRAMES ||
- io->items[i].calc_type == CALC_TYPE_FRAMES_AND_BYTES)) {
+ if (hfi && !(io->calc_type[i] == CALC_TYPE_BYTES ||
+ io->calc_type[i] == CALC_TYPE_FRAMES ||
+ io->calc_type[i] == CALC_TYPE_FRAMES_AND_BYTES)) {
/* check that the type is compatible */
switch (hfi->type) {
case FT_UINT8:
@@ -1321,7 +1323,7 @@ register_io_tap(io_stat_t *io, unsigned int i, const char *filter)
case FT_FLOAT:
case FT_DOUBLE:
/* these types only support SUM, COUNT, MAX, MIN, AVG */
- switch (io->items[i].calc_type) {
+ switch (io->calc_type[i]) {
case CALC_TYPE_SUM:
case CALC_TYPE_COUNT:
case CALC_TYPE_MAX:
@@ -1338,7 +1340,7 @@ register_io_tap(io_stat_t *io, unsigned int i, const char *filter)
break;
case FT_RELATIVE_TIME:
/* this type only supports SUM, COUNT, MAX, MIN, AVG, LOAD */
- switch (io->items[i].calc_type) {
+ switch (io->calc_type[i]) {
case CALC_TYPE_SUM:
case CALC_TYPE_COUNT:
case CALC_TYPE_MAX:
@@ -1359,7 +1361,7 @@ register_io_tap(io_stat_t *io, unsigned int i, const char *filter)
* XXX - support all operations on floating-point
* numbers?
*/
- if (io->items[i].calc_type != CALC_TYPE_COUNT) {
+ if (io->calc_type[i] != CALC_TYPE_COUNT) {
fprintf(stderr,
"\ntshark: %s doesn't have integral values, so %s(*) "
"calculations are not supported on it.\n",
@@ -1387,11 +1389,11 @@ register_io_tap(io_stat_t *io, unsigned int i, const char *filter)
static void
iostat_init(const char *opt_arg, void *userdata _U_)
{
- gdouble interval_float;
- guint32 idx = 0;
+ double interval_float;
+ uint32_t idx = 0;
unsigned int i;
io_stat_t *io;
- const gchar *filters, *str, *pos;
+ const char *filters, *str, *pos;
if ((*(opt_arg+(strlen(opt_arg)-1)) == ',') ||
(sscanf(opt_arg, "io,stat,%lf%n", &interval_float, (int *)&idx) != 1) ||
@@ -1427,13 +1429,13 @@ iostat_init(const char *opt_arg, void *userdata _U_)
io = g_new(io_stat_t, 1);
/* If interval is 0, calculate statistics over the whole file by setting the interval to
- * G_MAXUINT64 */
+ * UINT64_MAX */
if (interval_float == 0) {
- io->interval = G_MAXUINT64;
+ io->interval = UINT64_MAX;
io->invl_prec = 0;
} else {
/* Set interval to the number of us rounded to the nearest integer */
- io->interval = (guint64)(interval_float * 1000000.0 + 0.5);
+ io->interval = (uint64_t)(interval_float * 1000000.0 + 0.5);
/*
* Determine what interval precision the user has specified */
io->invl_prec = 6;
@@ -1450,8 +1452,8 @@ iostat_init(const char *opt_arg, void *userdata _U_)
interval of 1 and the last interval becomes "9 <> 9". If the interval is instead set to
1.1, the last interval becomes
last interval is rounded up to value that is greater than the duration. */
- const gchar *invl_start = opt_arg+8;
- gchar *intv_end;
+ const char *invl_start = opt_arg+8;
+ char *intv_end;
int invl_len;
intv_end = g_strstr_len(invl_start, -1, ",");
@@ -1485,10 +1487,12 @@ iostat_init(const char *opt_arg, void *userdata _U_)
}
}
- io->items = g_new(io_stat_item_t, io->num_cols);
- io->filters = (const char **)g_malloc(sizeof(char *) * io->num_cols);
- io->max_vals = g_new(guint64, io->num_cols);
- io->max_frame = g_new(guint32, io->num_cols);
+ io->items = g_new(io_stat_item_t, io->num_cols);
+ io->filters = (const char **)g_malloc(sizeof(char *) * io->num_cols);
+ io->max_vals = g_new(uint64_t, io->num_cols);
+ io->max_frame = g_new(uint32_t, io->num_cols);
+ io->hf_indexes = g_new(int, io->num_cols);
+ io->calc_type = g_new(int, io->num_cols);
for (i=0; i<io->num_cols; i++) {
io->max_vals[i] = 0;
@@ -1499,23 +1503,23 @@ iostat_init(const char *opt_arg, void *userdata _U_)
if ((!filters) || (filters[0] == 0)) {
register_io_tap(io, 0, NULL);
} else {
- gchar *filter;
+ char *filter;
i = 0;
str = filters;
do {
- pos = (gchar*) strchr(str, ',');
+ pos = (char*) strchr(str, ',');
if (pos == str) {
register_io_tap(io, i, NULL);
} else if (pos == NULL) {
- str = (const char*) g_strstrip((gchar*)str);
+ str = (const char*) g_strstrip((char*)str);
filter = g_strdup(str);
if (*filter)
register_io_tap(io, i, filter);
else
register_io_tap(io, i, NULL);
} else {
- filter = (gchar *)g_malloc((pos-str)+1);
- (void) g_strlcpy( filter, str, (gsize) ((pos-str)+1));
+ filter = (char *)g_malloc((pos-str)+1);
+ (void) g_strlcpy( filter, str, (size_t) ((pos-str)+1));
filter = g_strstrip(filter);
register_io_tap(io, i, (char *) filter);
}