forked from osmocom/wireshark
Add a "time_stat_init()" routine to initialize the fields of a
"timestat_t". Move "nstime_to_msec()" to "epan/nstime.c", as it has nothing to do with a "timestat_t". Use structure assignment when possible. Fix the "addtime()" macro and use it in "time_stat_update()". Use "timestat_t"s, and the routines to manipulate them, in the service response time table code. svn path=/trunk/; revision=15509
This commit is contained in:
parent
6d52a0369a
commit
86ea8b88f3
|
@ -351,6 +351,7 @@ mtp3_addr_to_str_buf
|
||||||
mtp3_service_indicator_code_short_vals DATA
|
mtp3_service_indicator_code_short_vals DATA
|
||||||
new_create_dissector_handle
|
new_create_dissector_handle
|
||||||
new_register_dissector
|
new_register_dissector
|
||||||
|
nstime_to_msec
|
||||||
nt_cmd_vals DATA
|
nt_cmd_vals DATA
|
||||||
num_tap_filters DATA
|
num_tap_filters DATA
|
||||||
num_tree_types DATA
|
num_tree_types DATA
|
||||||
|
|
|
@ -90,3 +90,14 @@ void get_timesum(nstime_t *sum, const nstime_t *a, const nstime_t *b)
|
||||||
sum->secs--;
|
sum->secs--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* function: nstime_to_msec
|
||||||
|
* converts nstime to double, time base is milli seconds
|
||||||
|
*/
|
||||||
|
|
||||||
|
double nstime_to_msec(const nstime_t *time)
|
||||||
|
{
|
||||||
|
return ((double)time->secs*1000 + (double)time->nsecs/1000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,9 @@ extern void get_timedelta(nstime_t *delta, const nstime_t *b, const nstime_t *a
|
||||||
extern void get_timesum(nstime_t *sum, const nstime_t *b, const nstime_t *a );
|
extern void get_timesum(nstime_t *sum, const nstime_t *b, const nstime_t *a );
|
||||||
|
|
||||||
/* sum += a */
|
/* sum += a */
|
||||||
#define addtime(sum, a) get_timesum(sum, sum, b)
|
#define addtime(sum, a) get_timesum(sum, sum, a)
|
||||||
|
|
||||||
|
/* converts nstime to double, time base is milli seconds*/
|
||||||
|
extern double nstime_to_msec(const nstime_t *time);
|
||||||
|
|
||||||
#endif /* __NSTIME_H__ */
|
#endif /* __NSTIME_H__ */
|
||||||
|
|
|
@ -408,13 +408,13 @@ init_srt_table(srt_stat_table *rst, int num_procs, GtkWidget *vbox, const char *
|
||||||
rst->num_procs=num_procs;
|
rst->num_procs=num_procs;
|
||||||
rst->procedures=g_malloc(sizeof(srt_procedure_t)*num_procs);
|
rst->procedures=g_malloc(sizeof(srt_procedure_t)*num_procs);
|
||||||
for(i=0;i<num_procs;i++){
|
for(i=0;i<num_procs;i++){
|
||||||
rst->procedures[i].num=0;
|
rst->procedures[i].stats.num=0;
|
||||||
rst->procedures[i].min.secs=0;
|
rst->procedures[i].stats.min.secs=0;
|
||||||
rst->procedures[i].min.nsecs=0;
|
rst->procedures[i].stats.min.nsecs=0;
|
||||||
rst->procedures[i].max.secs=0;
|
rst->procedures[i].stats.max.secs=0;
|
||||||
rst->procedures[i].max.nsecs=0;
|
rst->procedures[i].stats.max.nsecs=0;
|
||||||
rst->procedures[i].tot.secs=0;
|
rst->procedures[i].stats.tot.secs=0;
|
||||||
rst->procedures[i].tot.nsecs=0;
|
rst->procedures[i].stats.tot.nsecs=0;
|
||||||
for(j=0;j<6;j++){
|
for(j=0;j<6;j++){
|
||||||
rst->procedures[i].entries[j]=NULL;
|
rst->procedures[i].entries[j]=NULL;
|
||||||
}
|
}
|
||||||
|
@ -436,13 +436,13 @@ init_srt_table_row(srt_stat_table *rst, int index, const char *procedure)
|
||||||
rst->num_procs=index+1;
|
rst->num_procs=index+1;
|
||||||
rst->procedures=g_realloc(rst->procedures, sizeof(srt_procedure_t)*(rst->num_procs));
|
rst->procedures=g_realloc(rst->procedures, sizeof(srt_procedure_t)*(rst->num_procs));
|
||||||
for(i=old_num_procs;i<rst->num_procs;i++){
|
for(i=old_num_procs;i<rst->num_procs;i++){
|
||||||
rst->procedures[i].num=0;
|
rst->procedures[i].stats.num=0;
|
||||||
rst->procedures[i].min.secs=0;
|
rst->procedures[i].stats.min.secs=0;
|
||||||
rst->procedures[i].min.nsecs=0;
|
rst->procedures[i].stats.min.nsecs=0;
|
||||||
rst->procedures[i].max.secs=0;
|
rst->procedures[i].stats.max.secs=0;
|
||||||
rst->procedures[i].max.nsecs=0;
|
rst->procedures[i].stats.max.nsecs=0;
|
||||||
rst->procedures[i].tot.secs=0;
|
rst->procedures[i].stats.tot.secs=0;
|
||||||
rst->procedures[i].tot.nsecs=0;
|
rst->procedures[i].stats.tot.nsecs=0;
|
||||||
for(j=0;j<6;j++){
|
for(j=0;j<6;j++){
|
||||||
rst->procedures[i].entries[j]=NULL;
|
rst->procedures[i].entries[j]=NULL;
|
||||||
}
|
}
|
||||||
|
@ -467,33 +467,6 @@ add_srt_table_data(srt_stat_table *rst, int index, const nstime_t *req_time, pac
|
||||||
|
|
||||||
rp=&rst->procedures[index];
|
rp=&rst->procedures[index];
|
||||||
|
|
||||||
/* calculate time delta between request and reply */
|
|
||||||
t.secs=pinfo->fd->abs_secs;
|
|
||||||
t.nsecs=pinfo->fd->abs_usecs*1000;
|
|
||||||
get_timedelta(&delta, &t, req_time);
|
|
||||||
|
|
||||||
if(rp->num==0){
|
|
||||||
rp->max=delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rp->num==0){
|
|
||||||
rp->min=delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( (delta.secs<rp->min.secs)
|
|
||||||
||( (delta.secs==rp->min.secs)
|
|
||||||
&&(delta.nsecs<rp->min.nsecs) ) ){
|
|
||||||
rp->min=delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( (delta.secs>rp->max.secs)
|
|
||||||
||( (delta.secs==rp->max.secs)
|
|
||||||
&&(delta.nsecs>rp->max.nsecs) ) ){
|
|
||||||
rp->max=delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_timesum(&rp->tot, &rp->tot, &delta);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the count of calls for this procedure is currently zero, it's
|
* If the count of calls for this procedure is currently zero, it's
|
||||||
* going to become non-zero, so add a row for it (we don't want
|
* going to become non-zero, so add a row for it (we don't want
|
||||||
|
@ -504,11 +477,17 @@ add_srt_table_data(srt_stat_table *rst, int index, const nstime_t *req_time, pac
|
||||||
* (Yes, this means that the rows aren't in order by anything
|
* (Yes, this means that the rows aren't in order by anything
|
||||||
* interesting. That's why we have the table sorted by a column.)
|
* interesting. That's why we have the table sorted by a column.)
|
||||||
*/
|
*/
|
||||||
if (rp->num==0){
|
if (rp->stats.num==0){
|
||||||
row=gtk_clist_append(rst->table, rst->procedures[index].entries);
|
row=gtk_clist_append(rst->table, rst->procedures[index].entries);
|
||||||
gtk_clist_set_row_data(rst->table, row, (gpointer) index);
|
gtk_clist_set_row_data(rst->table, row, (gpointer) index);
|
||||||
}
|
}
|
||||||
rp->num++;
|
|
||||||
|
/* calculate time delta between request and reply */
|
||||||
|
t.secs=pinfo->fd->abs_secs;
|
||||||
|
t.nsecs=pinfo->fd->abs_usecs*1000;
|
||||||
|
get_timedelta(&delta, &t, req_time);
|
||||||
|
|
||||||
|
time_stat_update(&rp->stats, &delta, pinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -520,34 +499,34 @@ draw_srt_table_data(srt_stat_table *rst)
|
||||||
|
|
||||||
for(i=0;i<rst->num_procs;i++){
|
for(i=0;i<rst->num_procs;i++){
|
||||||
/* ignore procedures with no calls (they don't have CList rows) */
|
/* ignore procedures with no calls (they don't have CList rows) */
|
||||||
if(rst->procedures[i].num==0){
|
if(rst->procedures[i].stats.num==0){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* scale it to units of 10us.*/
|
/* scale it to units of 10us.*/
|
||||||
/* for long captures with a large tot time, this can overflow on 32bit */
|
/* for long captures with a large tot time, this can overflow on 32bit */
|
||||||
td=(int)rst->procedures[i].tot.secs;
|
td=(int)rst->procedures[i].stats.tot.secs;
|
||||||
td=td*100000+(int)rst->procedures[i].tot.nsecs/10000;
|
td=td*100000+(int)rst->procedures[i].stats.tot.nsecs/10000;
|
||||||
td/=rst->procedures[i].num;
|
td/=rst->procedures[i].stats.num;
|
||||||
|
|
||||||
j=gtk_clist_find_row_from_data(rst->table, (gpointer)i);
|
j=gtk_clist_find_row_from_data(rst->table, (gpointer)i);
|
||||||
strp=g_strdup_printf("%d", rst->procedures[i].num);
|
strp=g_strdup_printf("%d", rst->procedures[i].stats.num);
|
||||||
gtk_clist_set_text(rst->table, j, 2, strp);
|
gtk_clist_set_text(rst->table, j, 2, strp);
|
||||||
g_free(rst->procedures[i].entries[2]);
|
g_free(rst->procedures[i].entries[2]);
|
||||||
rst->procedures[i].entries[2]=strp;
|
rst->procedures[i].entries[2]=strp;
|
||||||
|
|
||||||
|
|
||||||
strp=g_strdup_printf("%3d.%05d",
|
strp=g_strdup_printf("%3d.%05d",
|
||||||
(int)rst->procedures[i].min.secs,
|
(int)rst->procedures[i].stats.min.secs,
|
||||||
rst->procedures[i].min.nsecs/10000);
|
rst->procedures[i].stats.min.nsecs/10000);
|
||||||
gtk_clist_set_text(rst->table, j, 3, strp);
|
gtk_clist_set_text(rst->table, j, 3, strp);
|
||||||
g_free(rst->procedures[i].entries[3]);
|
g_free(rst->procedures[i].entries[3]);
|
||||||
rst->procedures[i].entries[3]=strp;
|
rst->procedures[i].entries[3]=strp;
|
||||||
|
|
||||||
|
|
||||||
strp=g_strdup_printf("%3d.%05d",
|
strp=g_strdup_printf("%3d.%05d",
|
||||||
(int)rst->procedures[i].max.secs,
|
(int)rst->procedures[i].stats.max.secs,
|
||||||
rst->procedures[i].max.nsecs/10000);
|
rst->procedures[i].stats.max.nsecs/10000);
|
||||||
gtk_clist_set_text(rst->table, j, 4, strp);
|
gtk_clist_set_text(rst->table, j, 4, strp);
|
||||||
g_free(rst->procedures[i].entries[4]);
|
g_free(rst->procedures[i].entries[4]);
|
||||||
rst->procedures[i].entries[4]=strp;
|
rst->procedures[i].entries[4]=strp;
|
||||||
|
@ -569,13 +548,7 @@ reset_srt_table_data(srt_stat_table *rst)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i=0;i<rst->num_procs;i++){
|
for(i=0;i<rst->num_procs;i++){
|
||||||
rst->procedures[i].num=0;
|
time_stat_init(&rst->procedures[i].stats);
|
||||||
rst->procedures[i].min.secs=0;
|
|
||||||
rst->procedures[i].min.nsecs=0;
|
|
||||||
rst->procedures[i].max.secs=0;
|
|
||||||
rst->procedures[i].max.nsecs=0;
|
|
||||||
rst->procedures[i].tot.secs=0;
|
|
||||||
rst->procedures[i].tot.nsecs=0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include "epan/nstime.h"
|
#include "epan/nstime.h"
|
||||||
|
#include "../timestats.h"
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
* Helper routines common to all service response time statistics tap.
|
* Helper routines common to all service response time statistics tap.
|
||||||
|
@ -34,10 +35,7 @@
|
||||||
/** Procedure data */
|
/** Procedure data */
|
||||||
typedef struct _srt_procedure_t {
|
typedef struct _srt_procedure_t {
|
||||||
char *entries[6]; /**< column entries */
|
char *entries[6]; /**< column entries */
|
||||||
int num; /**< number of calls seen */
|
timestat_t stats; /**< stats */
|
||||||
nstime_t min; /**< minimum srt */
|
|
||||||
nstime_t max; /**< maximum srt */
|
|
||||||
nstime_t tot; /**< average srt */
|
|
||||||
} srt_procedure_t;
|
} srt_procedure_t;
|
||||||
|
|
||||||
/** Statistics table */
|
/** Statistics table */
|
||||||
|
|
42
timestats.c
42
timestats.c
|
@ -25,55 +25,45 @@
|
||||||
|
|
||||||
#include "timestats.h"
|
#include "timestats.h"
|
||||||
|
|
||||||
/*
|
/* Initialize a timestat_t struct */
|
||||||
* function: nstime_to_msec
|
void
|
||||||
* converts nstime to gdouble, time base is milli seconds
|
time_stat_init(timestat_t *stats)
|
||||||
*/
|
|
||||||
|
|
||||||
gdouble nstime_to_msec(const nstime_t *time)
|
|
||||||
{
|
{
|
||||||
return ((double)time->secs*1000 + (double)time->nsecs/1000000);
|
stats->num = 0;
|
||||||
|
stats->min.secs = 0;
|
||||||
|
stats->min.nsecs = 0;
|
||||||
|
stats->max.secs = 0;
|
||||||
|
stats->max.nsecs = 0;
|
||||||
|
stats->tot.secs = 0;
|
||||||
|
stats->tot.nsecs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A Function to update a timestat_t struct with a new sample*/
|
/* Update a timestat_t struct with a new sample */
|
||||||
|
|
||||||
void
|
void
|
||||||
time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo)
|
time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo)
|
||||||
{
|
{
|
||||||
if(stats->num==0){
|
if(stats->num==0){
|
||||||
stats->max.secs=delta->secs;
|
stats->max=*delta;
|
||||||
stats->max.nsecs=delta->nsecs;
|
|
||||||
stats->max_num=pinfo->fd->num;
|
stats->max_num=pinfo->fd->num;
|
||||||
}
|
stats->min=*delta;
|
||||||
|
|
||||||
if(stats->num==0){
|
|
||||||
stats->min.secs=delta->secs;
|
|
||||||
stats->min.nsecs=delta->nsecs;
|
|
||||||
stats->min_num=pinfo->fd->num;
|
stats->min_num=pinfo->fd->num;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (delta->secs<stats->min.secs)
|
if( (delta->secs<stats->min.secs)
|
||||||
||( (delta->secs==stats->min.secs)
|
||( (delta->secs==stats->min.secs)
|
||||||
&&(delta->nsecs<stats->min.nsecs) ) ){
|
&&(delta->nsecs<stats->min.nsecs) ) ){
|
||||||
stats->min.secs=delta->secs;
|
stats->min=*delta;
|
||||||
stats->min.nsecs=delta->nsecs;
|
|
||||||
stats->min_num=pinfo->fd->num;
|
stats->min_num=pinfo->fd->num;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (delta->secs>stats->max.secs)
|
if( (delta->secs>stats->max.secs)
|
||||||
||( (delta->secs==stats->max.secs)
|
||( (delta->secs==stats->max.secs)
|
||||||
&&(delta->nsecs>stats->max.nsecs) ) ){
|
&&(delta->nsecs>stats->max.nsecs) ) ){
|
||||||
stats->max.secs=delta->secs;
|
stats->max=*delta;
|
||||||
stats->max.nsecs=delta->nsecs;
|
|
||||||
stats->max_num=pinfo->fd->num;
|
stats->max_num=pinfo->fd->num;
|
||||||
}
|
}
|
||||||
|
|
||||||
stats->tot.secs += delta->secs;
|
addtime(&stats->tot, delta);
|
||||||
stats->tot.nsecs += delta->nsecs;
|
|
||||||
if(stats->tot.nsecs>1000000000){
|
|
||||||
stats->tot.nsecs-=1000000000;
|
|
||||||
stats->tot.secs++;
|
|
||||||
}
|
|
||||||
|
|
||||||
stats->num++;
|
stats->num++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,12 @@ typedef struct _timestat_t {
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
|
|
||||||
/* converts nstime to gdouble, time base is milli seconds*/
|
/* Initialize a timestat_t struct */
|
||||||
extern gdouble nstime_to_msec(const nstime_t *time);
|
extern void time_stat_init(timestat_t *stats);
|
||||||
|
|
||||||
|
/* Update a timestat_t struct with a new sample */
|
||||||
extern void time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo);
|
extern void time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo);
|
||||||
|
|
||||||
extern gdouble get_average(const nstime_t *sum, guint32 num);
|
extern gdouble get_average(const nstime_t *sum, guint32 num);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue