2002-11-01 01:49:40 +00:00
|
|
|
/* tap-iostat.c
|
|
|
|
* iostat 2002 Ronnie Sahlberg
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2002-11-01 01:49:40 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2002-11-01 01:49:40 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
2003-04-24 12:25:33 +00:00
|
|
|
#include "epan/epan_dissect.h"
|
2002-11-01 01:49:40 +00:00
|
|
|
#include "epan/packet_info.h"
|
2004-09-29 00:06:36 +00:00
|
|
|
#include <epan/tap.h>
|
2005-08-20 20:06:05 +00:00
|
|
|
#include <epan/stat_cmd_args.h>
|
2008-03-02 21:12:24 +00:00
|
|
|
#include <epan/strutil.h>
|
2002-11-01 01:49:40 +00:00
|
|
|
#include "register.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _io_stat_t {
|
2003-04-22 09:02:54 +00:00
|
|
|
gint32 interval; /* unit is ms */
|
2002-11-01 01:49:40 +00:00
|
|
|
guint32 num_items;
|
|
|
|
struct _io_stat_item_t *items;
|
2005-08-06 14:03:14 +00:00
|
|
|
const char **filters;
|
2002-11-01 01:49:40 +00:00
|
|
|
} io_stat_t;
|
|
|
|
|
2003-04-24 12:25:33 +00:00
|
|
|
#define CALC_TYPE_BYTES 0
|
|
|
|
#define CALC_TYPE_COUNT 1
|
|
|
|
#define CALC_TYPE_SUM 2
|
|
|
|
#define CALC_TYPE_MIN 3
|
|
|
|
#define CALC_TYPE_MAX 4
|
|
|
|
#define CALC_TYPE_AVG 5
|
|
|
|
|
2002-11-01 01:49:40 +00:00
|
|
|
typedef struct _io_stat_item_t {
|
|
|
|
io_stat_t *parent;
|
|
|
|
struct _io_stat_item_t *next;
|
|
|
|
struct _io_stat_item_t *prev;
|
2003-04-22 09:02:54 +00:00
|
|
|
gint32 time; /* unit is ms since start of capture */
|
2003-04-24 12:25:33 +00:00
|
|
|
int calc_type;
|
|
|
|
int hf_index;
|
2002-11-01 01:49:40 +00:00
|
|
|
guint32 frames;
|
2003-04-24 12:25:33 +00:00
|
|
|
guint32 num;
|
|
|
|
guint32 counter;
|
2002-11-01 01:49:40 +00:00
|
|
|
} io_stat_item_t;
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2009-06-05 22:42:47 +00:00
|
|
|
iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *dummy _U_)
|
2002-11-01 01:49:40 +00:00
|
|
|
{
|
2005-01-01 12:49:54 +00:00
|
|
|
io_stat_item_t *mit = arg;
|
2002-11-01 01:49:40 +00:00
|
|
|
io_stat_item_t *it;
|
2003-04-22 09:02:54 +00:00
|
|
|
gint32 current_time;
|
2003-04-24 12:25:33 +00:00
|
|
|
GPtrArray *gp;
|
|
|
|
guint i;
|
2003-04-22 09:02:54 +00:00
|
|
|
|
2007-03-21 23:14:23 +00:00
|
|
|
current_time=(gint32) ((pinfo->fd->rel_ts.secs*1000)+(pinfo->fd->rel_ts.nsecs/1000000));
|
2002-11-01 01:49:40 +00:00
|
|
|
|
|
|
|
/* the prev item before the main one is always the last interval we saw packets for */
|
|
|
|
it=mit->prev;
|
|
|
|
|
|
|
|
/* XXX for the time being, just ignore all frames that are in the past.
|
|
|
|
should be fixed in the future but hopefully it is uncommon */
|
2003-04-22 09:02:54 +00:00
|
|
|
if(current_time<it->time){
|
2002-11-01 01:49:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have moved into a new interval, we need to create a new struct */
|
2003-04-22 09:02:54 +00:00
|
|
|
if(current_time>=(it->time+mit->parent->interval)){
|
2002-11-01 01:49:40 +00:00
|
|
|
it->next=g_malloc(sizeof(io_stat_item_t));
|
|
|
|
it->next->prev=it;
|
|
|
|
it->next->next=NULL;
|
|
|
|
it=it->next;
|
|
|
|
mit->prev=it;
|
|
|
|
|
2003-04-22 09:02:54 +00:00
|
|
|
it->time=(current_time / mit->parent->interval) * mit->parent->interval;
|
2002-11-01 01:49:40 +00:00
|
|
|
it->frames=0;
|
2003-04-24 12:25:33 +00:00
|
|
|
it->counter=0;
|
|
|
|
it->num=0;
|
|
|
|
it->calc_type=it->prev->calc_type;
|
|
|
|
it->hf_index=it->prev->hf_index;
|
2002-11-01 01:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* it will now give us the current structure to use to store the data in */
|
|
|
|
it->frames++;
|
2003-04-24 12:25:33 +00:00
|
|
|
|
|
|
|
switch(it->calc_type){
|
|
|
|
case CALC_TYPE_BYTES:
|
|
|
|
it->counter+=pinfo->fd->pkt_len;
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_COUNT:
|
|
|
|
gp=proto_get_finfo_ptr_array(edt->tree, it->hf_index);
|
|
|
|
if(gp){
|
|
|
|
it->counter+=gp->len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_SUM:
|
|
|
|
gp=proto_get_finfo_ptr_array(edt->tree, it->hf_index);
|
|
|
|
if(gp){
|
|
|
|
for(i=0;i<gp->len;i++){
|
2007-01-18 11:02:26 +00:00
|
|
|
switch(proto_registrar_get_ftype(it->hf_index)){
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
it->counter+=fvalue_get_uinteger(&((field_info *)gp->pdata[i])->value);
|
|
|
|
break;
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
|
|
|
it->counter+=fvalue_get_sinteger(&((field_info *)gp->pdata[i])->value);
|
|
|
|
break;
|
|
|
|
}
|
2003-04-24 12:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_MIN:
|
|
|
|
gp=proto_get_finfo_ptr_array(edt->tree, it->hf_index);
|
|
|
|
if(gp){
|
|
|
|
int type;
|
|
|
|
guint32 val;
|
|
|
|
nstime_t *new_time;
|
|
|
|
|
|
|
|
type=proto_registrar_get_ftype(it->hf_index);
|
|
|
|
for(i=0;i<gp->len;i++){
|
|
|
|
switch(type){
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
2007-01-18 11:02:26 +00:00
|
|
|
val=fvalue_get_uinteger(&((field_info *)gp->pdata[i])->value);
|
2003-04-24 12:25:33 +00:00
|
|
|
if((it->frames==1)&&(i==0)){
|
|
|
|
it->counter=val;
|
|
|
|
} else if(val<it->counter){
|
|
|
|
it->counter=val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
2007-01-18 11:02:26 +00:00
|
|
|
val=fvalue_get_sinteger(&((field_info *)gp->pdata[i])->value);
|
2003-04-24 12:25:33 +00:00
|
|
|
if((it->frames==1)&&(i==0)){
|
|
|
|
it->counter=val;
|
|
|
|
} else if((gint32)val<(gint32)(it->counter)){
|
|
|
|
it->counter=val;
|
2007-01-18 11:02:26 +00:00
|
|
|
}
|
2003-04-24 12:25:33 +00:00
|
|
|
break;
|
|
|
|
case FT_RELATIVE_TIME:
|
2003-12-02 21:15:49 +00:00
|
|
|
new_time=fvalue_get(&((field_info *)gp->pdata[i])->value);
|
2007-03-21 23:14:23 +00:00
|
|
|
val=(guint32) (new_time->secs*1000+new_time->nsecs/1000000);
|
2003-04-24 12:25:33 +00:00
|
|
|
if((it->frames==1)&&(i==0)){
|
|
|
|
it->counter=val;
|
|
|
|
} else if(val<it->counter){
|
|
|
|
it->counter=val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_MAX:
|
|
|
|
gp=proto_get_finfo_ptr_array(edt->tree, it->hf_index);
|
|
|
|
if(gp){
|
|
|
|
int type;
|
|
|
|
guint32 val;
|
|
|
|
nstime_t *new_time;
|
|
|
|
|
|
|
|
type=proto_registrar_get_ftype(it->hf_index);
|
|
|
|
for(i=0;i<gp->len;i++){
|
|
|
|
switch(type){
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
2007-01-18 11:02:26 +00:00
|
|
|
val=fvalue_get_uinteger(&((field_info *)gp->pdata[i])->value);
|
2003-04-24 12:25:33 +00:00
|
|
|
if((it->frames==1)&&(i==0)){
|
|
|
|
it->counter=val;
|
|
|
|
} else if(val>it->counter){
|
|
|
|
it->counter=val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
2007-01-18 11:02:26 +00:00
|
|
|
val=fvalue_get_sinteger(&((field_info *)gp->pdata[i])->value);
|
2003-04-24 12:25:33 +00:00
|
|
|
if((it->frames==1)&&(i==0)){
|
|
|
|
it->counter=val;
|
|
|
|
} else if((gint32)val>(gint32)(it->counter)){
|
|
|
|
it->counter=val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FT_RELATIVE_TIME:
|
2003-12-02 21:15:49 +00:00
|
|
|
new_time=fvalue_get(&((field_info *)gp->pdata[i])->value);
|
2007-03-21 23:14:23 +00:00
|
|
|
val=(guint32) (new_time->secs*1000+new_time->nsecs/1000000);
|
2003-04-24 12:25:33 +00:00
|
|
|
if((it->frames==1)&&(i==0)){
|
|
|
|
it->counter=val;
|
|
|
|
} else if(val>it->counter){
|
|
|
|
it->counter=val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_AVG:
|
|
|
|
gp=proto_get_finfo_ptr_array(edt->tree, it->hf_index);
|
|
|
|
if(gp){
|
|
|
|
int type;
|
|
|
|
guint32 val;
|
|
|
|
nstime_t *new_time;
|
|
|
|
|
|
|
|
type=proto_registrar_get_ftype(it->hf_index);
|
|
|
|
for(i=0;i<gp->len;i++){
|
|
|
|
it->num++;
|
|
|
|
switch(type){
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
2007-01-18 11:02:26 +00:00
|
|
|
val=fvalue_get_uinteger(&((field_info *)gp->pdata[i])->value);
|
|
|
|
it->counter+=val;
|
|
|
|
break;
|
2003-04-24 12:25:33 +00:00
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
2007-01-18 11:02:26 +00:00
|
|
|
val=fvalue_get_sinteger(&((field_info *)gp->pdata[i])->value);
|
2003-04-24 12:25:33 +00:00
|
|
|
it->counter+=val;
|
|
|
|
break;
|
|
|
|
case FT_RELATIVE_TIME:
|
2003-12-02 21:15:49 +00:00
|
|
|
new_time=fvalue_get(&((field_info *)gp->pdata[i])->value);
|
2007-03-21 23:14:23 +00:00
|
|
|
val=(guint32) (new_time->secs*1000+new_time->nsecs/1000000);
|
2003-04-24 12:25:33 +00:00
|
|
|
it->counter+=val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-11-01 01:49:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-01-01 12:49:54 +00:00
|
|
|
iostat_draw(void *arg)
|
2002-11-01 01:49:40 +00:00
|
|
|
{
|
2005-01-01 12:49:54 +00:00
|
|
|
io_stat_item_t *mit = arg;
|
2002-11-01 01:49:40 +00:00
|
|
|
io_stat_t *iot;
|
|
|
|
io_stat_item_t **items;
|
|
|
|
guint32 *frames;
|
2003-04-24 12:25:33 +00:00
|
|
|
guint32 *counters;
|
|
|
|
guint32 *num;
|
2002-11-01 01:49:40 +00:00
|
|
|
guint32 i,more_items;
|
|
|
|
gint t;
|
|
|
|
|
|
|
|
iot=mit->parent;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
printf("===================================================================\n");
|
|
|
|
printf("IO Statistics\n");
|
2009-03-12 22:44:58 +00:00
|
|
|
if(iot->interval!=G_MAXINT32)
|
|
|
|
printf("Interval: %d.%03d secs\n", iot->interval/1000, iot->interval%1000);
|
2002-11-01 01:49:40 +00:00
|
|
|
for(i=0;i<iot->num_items;i++){
|
|
|
|
printf("Column #%d: %s\n",i,iot->filters[i]?iot->filters[i]:"");
|
|
|
|
}
|
2003-04-22 09:02:54 +00:00
|
|
|
printf(" ");
|
2002-11-01 01:49:40 +00:00
|
|
|
for(i=0;i<iot->num_items;i++){
|
|
|
|
printf("| Column #%-2d ",i);
|
|
|
|
}
|
|
|
|
printf("\n");
|
2003-04-22 09:02:54 +00:00
|
|
|
printf("Time ");
|
2002-11-01 01:49:40 +00:00
|
|
|
for(i=0;i<iot->num_items;i++){
|
2003-04-24 12:25:33 +00:00
|
|
|
switch(iot->items[i].calc_type){
|
|
|
|
case CALC_TYPE_BYTES:
|
|
|
|
printf("|frames| bytes ");
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_COUNT:
|
|
|
|
printf("| COUNT ");
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_SUM:
|
|
|
|
printf("| SUM ");
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_MIN:
|
|
|
|
printf("| MIN ");
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_MAX:
|
|
|
|
printf("| MAX ");
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_AVG:
|
|
|
|
printf("| AVG ");
|
|
|
|
break;
|
|
|
|
}
|
2002-11-01 01:49:40 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
items=g_malloc(sizeof(io_stat_item_t *)*iot->num_items);
|
|
|
|
frames=g_malloc(sizeof(guint32)*iot->num_items);
|
2003-04-24 12:25:33 +00:00
|
|
|
counters=g_malloc(sizeof(guint32)*iot->num_items);
|
|
|
|
num=g_malloc(sizeof(guint32)*iot->num_items);
|
2002-11-01 01:49:40 +00:00
|
|
|
/* preset all items at the first interval */
|
|
|
|
for(i=0;i<iot->num_items;i++){
|
|
|
|
items[i]=&iot->items[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop the items until we run out of them all */
|
|
|
|
t=0;
|
|
|
|
do {
|
|
|
|
more_items=0;
|
|
|
|
for(i=0;i<iot->num_items;i++){
|
|
|
|
frames[i]=0;
|
2003-04-24 12:25:33 +00:00
|
|
|
counters[i]=0;
|
|
|
|
num[i]=0;
|
2002-11-01 01:49:40 +00:00
|
|
|
}
|
|
|
|
for(i=0;i<iot->num_items;i++){
|
|
|
|
if(items[i] && (t>=(items[i]->time+iot->interval))){
|
|
|
|
items[i]=items[i]->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(items[i] && (t<(items[i]->time+iot->interval)) && (t>=items[i]->time) ){
|
|
|
|
frames[i]=items[i]->frames;
|
2003-04-24 12:25:33 +00:00
|
|
|
counters[i]=items[i]->counter;
|
|
|
|
num[i]=items[i]->num;
|
2002-11-01 01:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(items[i]){
|
|
|
|
more_items=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(more_items){
|
2009-03-12 22:44:58 +00:00
|
|
|
if(iot->interval==G_MAXINT32) {
|
|
|
|
printf("000.000- ");
|
|
|
|
} else {
|
|
|
|
printf("%03d.%03d-%03d.%03d ",
|
|
|
|
t/1000,t%1000,
|
|
|
|
(t+iot->interval)/1000,
|
|
|
|
(t+iot->interval)%1000);
|
|
|
|
}
|
2002-11-01 01:49:40 +00:00
|
|
|
for(i=0;i<iot->num_items;i++){
|
2003-04-24 12:25:33 +00:00
|
|
|
switch(iot->items[i].calc_type){
|
|
|
|
case CALC_TYPE_BYTES:
|
|
|
|
printf("%6d %9d ",frames[i],counters[i]);
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_COUNT:
|
|
|
|
printf(" %8d ", counters[i]);
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_SUM:
|
|
|
|
printf(" %8d ", counters[i]);
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_MIN:
|
|
|
|
switch(proto_registrar_get_ftype(iot->items[i].hf_index)){
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
printf(" %8u ", counters[i]);
|
|
|
|
break;
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
|
|
|
printf(" %8d ", counters[i]);
|
|
|
|
break;
|
|
|
|
case FT_RELATIVE_TIME:
|
|
|
|
printf(" %6d.%03d ", counters[i]/1000, counters[i]%1000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_MAX:
|
|
|
|
switch(proto_registrar_get_ftype(iot->items[i].hf_index)){
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
printf(" %8u ", counters[i]);
|
|
|
|
break;
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
|
|
|
printf(" %8d ", counters[i]);
|
|
|
|
break;
|
|
|
|
case FT_RELATIVE_TIME:
|
|
|
|
printf(" %6d.%03d ", counters[i]/1000, counters[i]%1000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CALC_TYPE_AVG:
|
|
|
|
if(num[i]==0){
|
|
|
|
num[i]=1;
|
|
|
|
}
|
|
|
|
switch(proto_registrar_get_ftype(iot->items[i].hf_index)){
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
printf(" %8u ", counters[i]/num[i]);
|
|
|
|
break;
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
|
|
|
printf(" %8d ", counters[i]/num[i]);
|
|
|
|
break;
|
|
|
|
case FT_RELATIVE_TIME:
|
|
|
|
counters[i]/=num[i];
|
|
|
|
printf(" %6d.%03d ", counters[i]/1000, counters[i]%1000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2002-11-01 01:49:40 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
t+=iot->interval;
|
|
|
|
} while(more_items);
|
|
|
|
|
|
|
|
printf("===================================================================\n");
|
|
|
|
|
|
|
|
g_free(items);
|
|
|
|
g_free(frames);
|
2003-04-24 12:25:33 +00:00
|
|
|
g_free(counters);
|
|
|
|
g_free(num);
|
2002-11-01 01:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-27 19:42:24 +00:00
|
|
|
typedef struct {
|
|
|
|
const char *func_name;
|
|
|
|
int calc_type;
|
|
|
|
} calc_type_ent_t;
|
2003-04-24 12:25:33 +00:00
|
|
|
|
2005-10-27 19:42:24 +00:00
|
|
|
static calc_type_ent_t calc_type_table[] = {
|
|
|
|
{ "COUNT", CALC_TYPE_COUNT },
|
|
|
|
{ "SUM", CALC_TYPE_SUM },
|
|
|
|
{ "MIN", CALC_TYPE_MIN },
|
|
|
|
{ "MAX", CALC_TYPE_MAX },
|
|
|
|
{ "AVG", CALC_TYPE_AVG },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
2003-04-24 12:25:33 +00:00
|
|
|
|
2002-11-01 01:49:40 +00:00
|
|
|
static void
|
2005-08-06 14:03:14 +00:00
|
|
|
register_io_tap(io_stat_t *io, int i, const char *filter)
|
2002-11-01 01:49:40 +00:00
|
|
|
{
|
2003-04-23 08:20:06 +00:00
|
|
|
GString *error_string;
|
2005-08-06 14:03:14 +00:00
|
|
|
const char *flt;
|
2005-10-27 19:42:24 +00:00
|
|
|
int j;
|
|
|
|
size_t namelen;
|
|
|
|
const char *p, *parenp;
|
|
|
|
char *field;
|
|
|
|
header_field_info *hfi;
|
2003-04-23 08:20:06 +00:00
|
|
|
|
2002-11-01 01:49:40 +00:00
|
|
|
io->items[i].prev=&io->items[i];
|
|
|
|
io->items[i].next=NULL;
|
|
|
|
io->items[i].parent=io;
|
|
|
|
io->items[i].time=0;
|
2003-04-24 12:25:33 +00:00
|
|
|
io->items[i].calc_type=CALC_TYPE_BYTES;
|
2002-11-01 01:49:40 +00:00
|
|
|
io->items[i].frames=0;
|
2003-04-24 12:25:33 +00:00
|
|
|
io->items[i].counter=0;
|
|
|
|
io->items[i].num=0;
|
2002-11-01 01:49:40 +00:00
|
|
|
io->filters[i]=filter;
|
2003-04-24 12:25:33 +00:00
|
|
|
flt=filter;
|
|
|
|
|
2005-10-27 19:42:24 +00:00
|
|
|
field=NULL;
|
|
|
|
hfi=NULL;
|
|
|
|
for(j=0; calc_type_table[j].func_name; j++){
|
|
|
|
namelen=strlen(calc_type_table[j].func_name);
|
2009-06-05 22:42:47 +00:00
|
|
|
if(filter
|
|
|
|
&& strncmp(filter, calc_type_table[j].func_name, namelen) == 0
|
2005-10-27 19:42:24 +00:00
|
|
|
&& *(filter+namelen)=='('){
|
|
|
|
io->items[i].calc_type=calc_type_table[j].calc_type;
|
|
|
|
|
|
|
|
p=filter+namelen+1;
|
|
|
|
parenp=strchr(p, ')');
|
|
|
|
if(!parenp){
|
2006-05-31 17:38:42 +00:00
|
|
|
fprintf(stderr, "tshark: Closing parenthesis missing from calculated expression.\n");
|
2005-10-27 19:42:24 +00:00
|
|
|
exit(10);
|
|
|
|
}
|
|
|
|
/* bail out if there was no field specified */
|
|
|
|
if(parenp==p){
|
2006-05-31 17:38:42 +00:00
|
|
|
fprintf(stderr, "tshark: You didn't specify a field name for %s(*).\n",
|
2005-10-27 19:42:24 +00:00
|
|
|
calc_type_table[j].func_name);
|
|
|
|
exit(10);
|
|
|
|
}
|
2008-01-24 19:09:30 +00:00
|
|
|
field=g_malloc(parenp-p+1);
|
2005-10-27 19:42:24 +00:00
|
|
|
if(!field){
|
2006-05-31 17:38:42 +00:00
|
|
|
fprintf(stderr, "tshark: Out of memory.\n");
|
2005-10-27 19:42:24 +00:00
|
|
|
exit(10);
|
|
|
|
}
|
|
|
|
memcpy(field, p, parenp-p);
|
|
|
|
field[parenp-p] = '\0';
|
|
|
|
flt=parenp + 1;
|
|
|
|
|
|
|
|
hfi=proto_registrar_get_byname(field);
|
|
|
|
if(!hfi){
|
2006-05-31 17:38:42 +00:00
|
|
|
fprintf(stderr, "tshark: There is no field named '%s'.\n",
|
2005-10-27 19:42:24 +00:00
|
|
|
field);
|
2008-01-24 19:09:30 +00:00
|
|
|
g_free(field);
|
2005-10-27 19:42:24 +00:00
|
|
|
exit(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
io->items[i].hf_index=hfi->id;
|
2003-04-24 12:25:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-10-27 19:42:24 +00:00
|
|
|
}
|
2009-08-05 15:39:29 +00:00
|
|
|
if(hfi && io->items[i].calc_type!=CALC_TYPE_BYTES){
|
2005-10-27 19:42:24 +00:00
|
|
|
/* check that the type is compatible */
|
|
|
|
switch(hfi->type){
|
2003-04-24 12:25:33 +00:00
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
2005-10-27 19:42:24 +00:00
|
|
|
/* these types support all calculations */
|
2003-04-24 12:25:33 +00:00
|
|
|
break;
|
|
|
|
case FT_RELATIVE_TIME:
|
2005-10-27 19:42:24 +00:00
|
|
|
/* this type only supports SUM, COUNT, MAX, MIN, AVG */
|
|
|
|
switch(io->items[i].calc_type){
|
|
|
|
case CALC_TYPE_SUM:
|
|
|
|
case CALC_TYPE_COUNT:
|
|
|
|
case CALC_TYPE_MAX:
|
|
|
|
case CALC_TYPE_MIN:
|
|
|
|
case CALC_TYPE_AVG:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr,
|
2006-05-31 17:38:42 +00:00
|
|
|
"tshark: %s is a relative-time field, so %s(*) calculations are not supported on it.",
|
2005-10-27 19:42:24 +00:00
|
|
|
field,
|
|
|
|
calc_type_table[j].func_name);
|
|
|
|
exit(10);
|
|
|
|
}
|
2003-04-24 12:25:33 +00:00
|
|
|
break;
|
2005-10-27 19:42:24 +00:00
|
|
|
case FT_UINT64:
|
|
|
|
case FT_INT64:
|
|
|
|
/*
|
|
|
|
* XXX - support this if gint64/guint64 are
|
|
|
|
* available?
|
|
|
|
*/
|
|
|
|
if(io->items[i].calc_type!=CALC_TYPE_COUNT){
|
|
|
|
fprintf(stderr,
|
2006-05-31 17:38:42 +00:00
|
|
|
"tshark: %s is a 64-bit integer, so %s(*) calculations are not supported on it.",
|
2005-10-27 19:42:24 +00:00
|
|
|
field,
|
|
|
|
calc_type_table[j].func_name);
|
|
|
|
exit(10);
|
|
|
|
}
|
2003-04-24 12:25:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
2005-10-27 19:42:24 +00:00
|
|
|
/*
|
|
|
|
* XXX - support all operations on floating-point
|
|
|
|
* numbers?
|
|
|
|
*/
|
|
|
|
if(io->items[i].calc_type!=CALC_TYPE_COUNT){
|
|
|
|
fprintf(stderr,
|
2006-05-31 17:38:42 +00:00
|
|
|
"tshark: %s doesn't have integral values, so %s(*) calculations are not supported on it.\n",
|
2005-10-27 19:42:24 +00:00
|
|
|
field,
|
|
|
|
calc_type_table[j].func_name);
|
|
|
|
exit(10);
|
|
|
|
}
|
|
|
|
break;
|
2003-04-24 12:25:33 +00:00
|
|
|
}
|
2008-01-24 19:09:30 +00:00
|
|
|
g_free(field);
|
2003-04-24 12:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CALC_TYPE_SUM 2
|
|
|
|
CALC_TYPE_MIN 3
|
|
|
|
CALC_TYPE_MAX 4
|
|
|
|
CALC_TYPE_AVG 5
|
|
|
|
*/
|
2002-11-01 01:49:40 +00:00
|
|
|
|
2009-06-05 22:42:47 +00:00
|
|
|
error_string=register_tap_listener("frame", &io->items[i], flt, TL_REQUIRES_PROTO_TREE, NULL, iostat_packet, i?NULL:iostat_draw);
|
2003-04-23 08:20:06 +00:00
|
|
|
if(error_string){
|
2002-11-01 01:49:40 +00:00
|
|
|
g_free(io->items);
|
|
|
|
g_free(io);
|
2006-05-31 17:38:42 +00:00
|
|
|
fprintf(stderr, "tshark: Couldn't register io,stat tap: %s\n",
|
2003-04-23 08:20:06 +00:00
|
|
|
error_string->str);
|
|
|
|
g_string_free(error_string, TRUE);
|
2002-11-01 01:49:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-19 14:45:10 +00:00
|
|
|
static void
|
2006-02-11 13:05:24 +00:00
|
|
|
iostat_init(const char *optarg, void* userdata _U_)
|
2002-11-01 01:49:40 +00:00
|
|
|
{
|
2003-04-22 09:02:54 +00:00
|
|
|
float interval_float;
|
|
|
|
gint32 interval;
|
2010-01-29 16:09:25 +00:00
|
|
|
int idx=0;
|
2002-11-01 01:49:40 +00:00
|
|
|
io_stat_t *io;
|
2005-08-06 03:44:55 +00:00
|
|
|
const char *filter=NULL;
|
2002-11-01 01:49:40 +00:00
|
|
|
|
2010-01-29 16:09:25 +00:00
|
|
|
if(sscanf(optarg,"io,stat,%f,%n",&interval_float,&idx)==1){
|
|
|
|
if(idx){
|
|
|
|
filter=optarg+idx;
|
2002-11-01 01:49:40 +00:00
|
|
|
} else {
|
|
|
|
filter=NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2006-05-31 17:38:42 +00:00
|
|
|
fprintf(stderr, "tshark: invalid \"-z io,stat,<interval>[,<filter>]\" argument\n");
|
2002-11-01 01:49:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-03-12 22:44:58 +00:00
|
|
|
/* if interval is 0, calculate statistics over the whole file
|
|
|
|
* by setting the interval to G_MAXINT32
|
|
|
|
*/
|
|
|
|
if(interval_float==0) {
|
|
|
|
interval=G_MAXINT32;
|
|
|
|
} else {
|
|
|
|
/* make interval be number of ms */
|
|
|
|
interval=(gint32)(interval_float*1000.0+0.9);
|
|
|
|
}
|
2003-04-22 09:02:54 +00:00
|
|
|
|
2002-11-01 01:49:40 +00:00
|
|
|
if(interval<1){
|
2009-03-12 22:44:58 +00:00
|
|
|
fprintf(stderr, "tshark: \"-z\" interval must be >=0.001 seconds or 0.\n");
|
2002-11-01 01:49:40 +00:00
|
|
|
exit(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
io=g_malloc(sizeof(io_stat_t));
|
|
|
|
io->interval=interval;
|
|
|
|
if((!filter)||(filter[0]==0)){
|
|
|
|
io->num_items=1;
|
|
|
|
io->items=g_malloc(sizeof(io_stat_item_t)*io->num_items);
|
|
|
|
io->filters=g_malloc(sizeof(char *)*io->num_items);
|
|
|
|
|
|
|
|
register_io_tap(io, 0, NULL);
|
|
|
|
} else {
|
2005-08-06 03:44:55 +00:00
|
|
|
const char *str,*pos;
|
|
|
|
char *tmp;
|
2002-11-01 01:49:40 +00:00
|
|
|
int i;
|
|
|
|
/* find how many ',' separated filters we have */
|
|
|
|
str=filter;
|
|
|
|
io->num_items=1;
|
2002-11-01 09:40:23 +00:00
|
|
|
while((str=strchr(str,','))){
|
2002-11-01 01:49:40 +00:00
|
|
|
io->num_items++;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
io->items=g_malloc(sizeof(io_stat_item_t)*io->num_items);
|
|
|
|
io->filters=g_malloc(sizeof(char *)*io->num_items);
|
|
|
|
|
|
|
|
/* for each filter, register a tap listener */
|
|
|
|
i=0;
|
|
|
|
str=filter;
|
|
|
|
do{
|
2002-11-01 09:40:23 +00:00
|
|
|
pos=strchr(str,',');
|
2002-11-01 01:49:40 +00:00
|
|
|
if(pos==str){
|
|
|
|
register_io_tap(io, i, NULL);
|
|
|
|
} else if(pos==NULL) {
|
2008-02-03 15:38:20 +00:00
|
|
|
tmp=g_strdup(str);
|
2002-11-01 01:49:40 +00:00
|
|
|
register_io_tap(io, i, tmp);
|
|
|
|
} else {
|
|
|
|
tmp=g_malloc((pos-str)+1);
|
2008-03-02 21:12:24 +00:00
|
|
|
g_strlcpy(tmp,str,(pos-str)+1);
|
2002-11-01 01:49:40 +00:00
|
|
|
register_io_tap(io, i, tmp);
|
|
|
|
}
|
|
|
|
str=pos+1;
|
|
|
|
i++;
|
|
|
|
} while(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
register_tap_listener_iostat(void)
|
|
|
|
{
|
2006-02-11 13:05:24 +00:00
|
|
|
register_stat_cmd_arg("io,stat,", iostat_init, NULL);
|
2002-11-01 01:49:40 +00:00
|
|
|
}
|