Debian Codegraph @

tools/kstats.c

raw
1 /* Copyright (C) 2008 Vincent Penquerc'h.
2 This file is part of the Kate codec library.
3 Written by Vincent Penquerc'h.
4
5 Use, distribution and reproduction of this library is governed
6 by a BSD style source license included with this source in the
7 file 'COPYING'. Please read these terms before distributing. */
8
9
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13 #ifdef HAVE_STDLIB_H
14 #include <stdlib.h>
15 #endif
16 #include <string.h>
17 #include "kate/kate.h"
18 #include "kstream.h"
19 #include "kstats.h"
20
21 void katalyzer_stats_init(katalyzer_stats *stats,kate_stream *ks)
22 {
23 memset(stats,0,sizeof(*stats));
24 stats->ks=ks;
25 }
26
27 katalyzer_stats *katalyzer_stats_create(kate_stream *ks)
28 {
29 katalyzer_stats *stats=(katalyzer_stats*)kate_malloc(sizeof(katalyzer_stats));
30 if (!stats) return NULL;
31 katalyzer_stats_init(stats,ks);
32 return stats;
33 }
34
35 void katalyzer_stats_destroy(katalyzer_stats *stats)
36 {
37 kate_free(stats);
38 }
39
40 void katalyzer_stats_add_packet(katalyzer_stats *stats,kate_packet *kp)
41 {
42 unsigned char type=((const unsigned char*)kp->data)[0];
43
44 stats->stream_length+=kp->nbytes;
45 ++stats->n_packets_total;
46 ++stats->n_packets[type];
47 if (stats->n_packets[type]==1) {
48 stats->min_size[type]=kp->nbytes;
49 stats->max_size[type]=kp->nbytes;
50 }
51 else {
52 if (stats->min_size[type]>kp->nbytes)
53 stats->min_size[type]=kp->nbytes;
54 if (stats->max_size[type]<kp->nbytes)
55 stats->max_size[type]=kp->nbytes;
56 }
57 stats->total_size[type]+=kp->nbytes;
58 }
59
60 int katalyzer_stats_matches(const katalyzer_stats *stats,const kate_stream *ks)
61 {
62 return ks==stats->ks;
63 }
64