source: tools/tracertstats/output.c @ 5261dbd

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 5261dbd was 65cdb7f, checked in by Perry Lorier <perry@…>, 16 years ago

Add a "realtime" statistics module. This can display stats every "n" seconds,
or every "n" packets.

Has "csv", "html" and "png" output formats currently. (png output module
really should be autoconf'd out if the required modules don't exist).

I'd like to add odoc formats, and I probably should add a "plain text" one
too.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include <inttypes.h>
2#include <stdio.h>
3#include <assert.h>
4#include <stdlib.h>
5#include <string.h>
6
7#include "output.h"
8
9struct output_type_t *output_formats[] = {
10        &output_csv,
11        &output_html,
12        &output_png,
13        NULL
14};
15
16struct output_data_t *output_init(char *title,char *type)
17{
18        output_data_t *data = malloc(sizeof(output_data_t));
19        int i=0;
20        data->title=strdup(title);
21        data->labels=NULL;
22        data->columns=0;
23        data->data=NULL;
24        while(output_formats[i]) {
25                if (strcmp(output_formats[i]->name,type)==0) {
26                        data->format = output_formats[i];
27                        return data;
28                }
29                ++i;
30        }
31        /* Not found */
32        free(data);
33        return NULL;
34}
35
36void output_add_column(struct output_data_t *out,char *col)
37{
38        ++out->columns;
39        out->labels=realloc(out->labels,out->columns*sizeof(char *));
40        out->labels[out->columns-1]=strdup(col);
41        out->data=realloc(out->data,out->columns*sizeof(struct data_t));
42}
43
44void output_flush_headings(struct output_data_t *out)
45{
46        out->format->init(out);
47}
48
49#define output_set_data(type_) \
50        void output_set_data_ ## type_(struct output_data_t *out,       \
51                        int col,TYPE__ ## type_ data)\
52        {       \
53                assert(col>=0 && col<out->columns); \
54                out->data[col].type=TYPE_ ## type_; \
55                out->data[col].d_ ## type_ = data; \
56        }
57
58output_set_data(str)
59output_set_data(int)
60output_set_data(float)
61output_set_data(time)
62#undef output_set_data
63
64void output_flush_row(struct output_data_t *out)
65{
66        out->format->flush(out);
67}
68
69void output_destroy(struct output_data_t *out)
70{
71        int i;
72        out->format->destroy(out);
73        for(i=0;i<out->columns;++i) {
74                free(out->labels[i]);
75        }
76        free(out->data);
77        free(out->labels);
78        free(out);
79}
80
Note: See TracBrowser for help on using the repository browser.