Better stats with capdiff
This commit is contained in:
parent
62f296914e
commit
611feaa03b
1 changed files with 19 additions and 1 deletions
|
@ -31,6 +31,8 @@ struct pkt_stats {
|
||||||
gint port;
|
gint port;
|
||||||
uint64_t count;
|
uint64_t count;
|
||||||
double cumulated_size;
|
double cumulated_size;
|
||||||
|
struct timespec first;
|
||||||
|
struct timespec last;
|
||||||
};
|
};
|
||||||
|
|
||||||
void destroy_pkt_stats(gpointer data) {
|
void destroy_pkt_stats(gpointer data) {
|
||||||
|
@ -50,8 +52,10 @@ void update_stats(struct buffer_packet *bp, GHashTable* stat_elem) {
|
||||||
ps->port = port;
|
ps->port = port;
|
||||||
ps->count = 0;
|
ps->count = 0;
|
||||||
ps->cumulated_size = 0;
|
ps->cumulated_size = 0;
|
||||||
|
ps->first = bp->seen;
|
||||||
g_hash_table_insert (stat_elem, &ps->port, ps);
|
g_hash_table_insert (stat_elem, &ps->port, ps);
|
||||||
}
|
}
|
||||||
|
ps->last = bp->seen;
|
||||||
ps->count++;
|
ps->count++;
|
||||||
ps->cumulated_size += bp->ip.ap.fmt.headers.size;
|
ps->cumulated_size += bp->ip.ap.fmt.headers.size;
|
||||||
}
|
}
|
||||||
|
@ -86,6 +90,10 @@ void reconstruct_action(struct cap_file cf[], struct pkt_reconstruct* pr, GHashT
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
double timespec2double (struct timespec* ts) {
|
||||||
|
return (long long) ts->tv_sec + (double) ts->tv_nsec / (double)1e9;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
printf("~ capdiff ~\n");
|
printf("~ capdiff ~\n");
|
||||||
|
@ -162,8 +170,18 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
double drop = ps->count > ps2->count ? (double)(ps->count - ps2->count) / (double)ps->count : (double)(ps2->count - ps->count) / (double)ps2->count;
|
double drop = ps->count > ps2->count ? (double)(ps->count - ps2->count) / (double)ps->count : (double)(ps2->count - ps->count) / (double)ps2->count;
|
||||||
|
double delta_time = timespec2double (&ps->last) - timespec2double (&ps->first);
|
||||||
|
|
||||||
fprintf(stdout, "port=%d, avg_size=%lf, count=%ld, drop=%lf\n", *port, ps->cumulated_size / ps->count, ps->count, drop);
|
fprintf(
|
||||||
|
stdout,
|
||||||
|
"port=%d, avg_size=%lf, count=%ld, drop=%lf, duration=%lf, bandwidth=%lf kB/s, rate=%lf pkt/s\n",
|
||||||
|
*port,
|
||||||
|
ps->cumulated_size / ps->count,
|
||||||
|
ps->count,
|
||||||
|
drop,
|
||||||
|
delta_time,
|
||||||
|
ps->cumulated_size / delta_time / 1024,
|
||||||
|
ps->count / delta_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) cap_unload (&cf[i]);
|
for (int i = 0; i < 2; i++) cap_unload (&cf[i]);
|
||||||
|
|
Loading…
Reference in a new issue