summaryrefslogtreecommitdiff
path: root/ui/cli/tap-iostat.c
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2012-08-31 07:30:01 +0000
committerAnders Broman <anders.broman@ericsson.com>2012-08-31 07:30:01 +0000
commit9d6e58a52be929a3528f114547db0a6c3096d102 (patch)
treee72817c65592f98ea1dff359673d321aedf136cd /ui/cli/tap-iostat.c
parent3e976d69d1e03eb112b15bd5b3eb78ffd64d2544 (diff)
downloadwireshark-9d6e58a52be929a3528f114547db0a6c3096d102.tar.gz
From Cal Turney: Fix Performance regression in tshark -z io,stat https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7674
svn path=/trunk/; revision=44707
Diffstat (limited to 'ui/cli/tap-iostat.c')
-rw-r--r--ui/cli/tap-iostat.c240
1 files changed, 124 insertions, 116 deletions
diff --git a/ui/cli/tap-iostat.c b/ui/cli/tap-iostat.c
index 99439d4918..8d7dbf80ba 100644
--- a/ui/cli/tap-iostat.c
+++ b/ui/cli/tap-iostat.c
@@ -23,7 +23,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include "config.h"
#endif
#include <stdio.h>
@@ -542,11 +542,11 @@ iostat_draw(void *arg)
borderlen, invl_col_w, numpad=1, namelen, len_filt, type, maxfltr_w, ftype;
int fr_mag; /* The magnitude of the max frame number in this column */
int val_mag; /* The magnitude of the max value in this column */
- gboolean last_row=FALSE;
char *spaces, *spaces_s, *filler_s=NULL, **fmts, *fmt=NULL;
const char *filter;
static gchar dur_mag_s[3], invl_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;
+ io_stat_item_t *mit, **stat_cols, *item, **item_in_column;
+ gboolean last_row=FALSE;
io_stat_t *iot;
column_width *col_w;
struct tm * tm_time;
@@ -933,7 +933,14 @@ iostat_draw(void *arg)
full_fmt = g_strconcat("| ", invl_fmt, " <> ", invl_fmt, " |", NULL);
num_rows = (int)(duration/interval) + (((duration%interval+500000)/1000000) > 0 ? 1 : 0);
- /* Display the table values.
+ /* Load item_in_column with the first item in each column */
+ item_in_column = (io_stat_item_t **) g_malloc(sizeof(io_stat_item_t) * num_cols);
+ for (j=0; j<num_cols; j++) {
+ item_in_column[j] = stat_cols[j];
+ }
+
+ /* Display the table values
+ *
* The outer loop is for time interval rows and the inner loop is for stat column items.*/
for (i=0; i<num_rows; i++) {
@@ -947,144 +954,138 @@ iostat_draw(void *arg)
invl_end = duration;
}
- /* Patch for Absolute Time */
- the_time=iot->start_time+(guint32)(t/1000000);
- tm_time = localtime(&the_time);
-
- /* Display the interval for this row */
- switch (timestamp_get_type()) {
- case TS_ABSOLUTE:
- printf("| %02d:%02d:%02d |",
- tm_time->tm_hour,
- tm_time->tm_min,
- tm_time->tm_sec);
- break;
-
- case TS_ABSOLUTE_WITH_DATE:
- printf("| %04d-%02d-%02d %02d:%02d:%02d |",
- tm_time->tm_year + 1900,
- tm_time->tm_mon + 1,
- tm_time->tm_mday,
- tm_time->tm_hour,
- tm_time->tm_min,
- tm_time->tm_sec);
- break;
-
- case TS_RELATIVE:
- case TS_NOT_SET:
+ /* Patch for Absolute Time */
+ the_time=iot->start_time+(guint32)(t/1000000);
+ tm_time = localtime(&the_time);
+
+ /* Display the interval for this row */
+ switch (timestamp_get_type()) {
+ case TS_ABSOLUTE:
+ printf("| %02d:%02d:%02d |",
+ tm_time->tm_hour,
+ tm_time->tm_min,
+ tm_time->tm_sec);
+ break;
+
+ case TS_ABSOLUTE_WITH_DATE:
+ printf("| %04d-%02d-%02d %02d:%02d:%02d |",
+ tm_time->tm_year + 1900,
+ tm_time->tm_mon + 1,
+ tm_time->tm_mday,
+ tm_time->tm_hour,
+ tm_time->tm_min,
+ tm_time->tm_sec);
+ break;
+
+ case TS_RELATIVE:
+ case TS_NOT_SET:
if (invl_prec==0) {
printf(full_fmt, (guint32)(t/1000000),
- (guint32)(invl_end/1000000));
+ (guint32)(invl_end/1000000));
} else {
printf(full_fmt, (guint32)(t/1000000),
- (guint32)(t%1000000) / dv,
- (guint32) (invl_end/1000000),
- (guint32)((invl_end%1000000) / dv));
+ (guint32)(t%1000000) / dv,
+ (guint32) (invl_end/1000000),
+ (guint32)((invl_end%1000000) / dv));
}
- break;
- /* case TS_DELTA:
- case TS_DELTA_DIS:
- case TS_EPOCH:
- case TS_UTC:
- case TS_UTC_WITH_DATE:
- are not implemented */
+ break;
+ /* case TS_DELTA:
+ case TS_DELTA_DIS:
+ case TS_EPOCH:
+ case TS_UTC:
+ case TS_UTC_WITH_DATE:
+ are not implemented */
default:
break;
}
- /* Display all the stat values in this row */
+ /* Display stat values in each column for this row */
for (j=0; j<num_cols; j++) {
- /*
- * Point to the list for this stat (column). */
- item = stat_cols[j];
- /*
- * Point to the item in the current row (time interval i) within this list. */
- for (k=0; k<i; k++)
- if (item && item->next)
- item = item->next;
- else
- item = NULL;
fmt = fmts[j];
+ item = item_in_column[j];
if (item) {
switch(item->calc_type) {
- case CALC_TYPE_FRAMES:
- printf(fmt, item->frames);
+ case CALC_TYPE_FRAMES:
+ printf(fmt, item->frames);
+ break;
+ case CALC_TYPE_BYTES:
+ case CALC_TYPE_COUNT:
+ printf(fmt, item->counter);
+ break;
+ case CALC_TYPE_FRAMES_AND_BYTES:
+ printf(fmt, item->frames, item->counter);
+ break;
+
+ case CALC_TYPE_SUM:
+ case CALC_TYPE_MIN:
+ case CALC_TYPE_MAX:
+ ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
+ switch(ftype){
+ case FT_FLOAT:
+ printf(fmt, item->float_counter);
break;
- case CALC_TYPE_BYTES:
- case CALC_TYPE_COUNT:
- printf(fmt, item->counter);
+ case FT_DOUBLE:
+ printf(fmt, item->double_counter);
break;
- case CALC_TYPE_FRAMES_AND_BYTES:
- printf(fmt, item->frames, item->counter);
+ case FT_RELATIVE_TIME:
+ item->counter = (item->counter + 500) / 1000;
+ printf(fmt, (int)(item->counter/1000000), (int)(item->counter%1000000));
break;
-
- case CALC_TYPE_SUM:
- case CALC_TYPE_MIN:
- case CALC_TYPE_MAX:
- ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
- switch(ftype){
- case FT_FLOAT:
- printf(fmt, item->float_counter);
- break;
- case FT_DOUBLE:
- printf(fmt, item->double_counter);
- break;
- case FT_RELATIVE_TIME:
- item->counter = (item->counter + 500) / 1000;
- printf(fmt, (int)(item->counter/1000000), (int)(item->counter%1000000));
- break;
- default:
- printf(fmt, item->counter);
- break;
- }
+ default:
+ printf(fmt, item->counter);
break;
+ }
+ break;
- case CALC_TYPE_AVG:
- num = item->num;
- if(num==0)
- num=1;
- ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
- switch(ftype){
- case FT_FLOAT:
- printf(fmt, item->float_counter/num);
- break;
- case FT_DOUBLE:
- printf(fmt, item->double_counter/num);
- break;
- case FT_RELATIVE_TIME:
- item->counter = ((item->counter/num) + 500) / 1000;
- printf(fmt,
- (int)(item->counter/1000000), (int)(item->counter%1000000));
- break;
- default:
- printf(fmt, item->counter/num);
- break;
- }
+ case CALC_TYPE_AVG:
+ num = item->num;
+ if(num==0)
+ num=1;
+ ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
+ switch(ftype){
+ case FT_FLOAT:
+ printf(fmt, item->float_counter/num);
+ break;
+ case FT_DOUBLE:
+ printf(fmt, item->double_counter/num);
+ break;
+ case FT_RELATIVE_TIME:
+ item->counter = ((item->counter/num) + 500) / 1000;
+ printf(fmt,
+ (int)(item->counter/1000000), (int)(item->counter%1000000));
break;
+ default:
+ printf(fmt, item->counter/num);
+ break;
+ }
+ break;
- case CALC_TYPE_LOAD:
- ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
- switch(ftype){
- case FT_RELATIVE_TIME:
- if (!last_row) {
- printf(fmt,
- (int) (item->counter/interval),
- (int)((item->counter%interval)*1000000 / interval));
- } else {
- printf(fmt,
- (int) (item->counter/(invl_end-t)),
- (int)((item->counter%(invl_end-t))*1000000 / (invl_end-t)));
- }
- break;
+ case CALC_TYPE_LOAD:
+ ftype = proto_registrar_get_ftype(stat_cols[j]->hf_index);
+ switch(ftype){
+ case FT_RELATIVE_TIME:
+ if (!last_row) {
+ printf(fmt,
+ (int) (item->counter/interval),
+ (int)((item->counter%interval)*1000000 / interval));
+ } else {
+ printf(fmt,
+ (int) (item->counter/(invl_end-t)),
+ (int)((item->counter%(invl_end-t))*1000000 / (invl_end-t)));
}
break;
+ }
+ break;
}
- if (last_row)
+
+ if (last_row) {
if (fmt)
g_free(fmt);
-
+ } else {
+ item_in_column[j] = item_in_column[j]->next;
+ }
} else {
printf(fmt, (guint64)0);
}
@@ -1099,10 +1100,17 @@ iostat_draw(void *arg)
printf("=");
}
printf("\n");
- g_free(invl_fmt);
+ g_free(iot->items);
+ g_free(iot->max_vals);
+ g_free(iot->max_frame);
+ g_free(iot);
g_free(col_w);
+ g_free(invl_fmt);
g_free(full_fmt);
+ g_free(fmts);
g_free(spaces);
+ g_free(stat_cols);
+ g_free(item_in_column);
}