]> git.sesse.net Git - nms/blob - web/ext/graphall.cpp
Add lots of TG06 graph stuff.
[nms] / web / ext / graphall.cpp
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/wait.h>
4 #include <malloc.h>
5 #include <vector>
6 #include <algorithm>
7 #include "graph.h"
8 #include "flowpusher.h"
9 #include "flowutil.h"
10
11 int main(int argc, char **argv)
12 {
13         bool total_only = false;
14         int width = 500, height = 250;
15         
16         std::vector<flow_element> flow, total_flow;
17         FlowPusher fp(flow);
18         int last_port = -1;
19         
20         mallopt(M_TRIM_THRESHOLD, -1);
21         
22         if (argc == 2 && strcmp(argv[1], "--total-only") == 0) {
23                 width = 1000;
24                 height = 500;
25                 total_only = true;
26         }
27
28         int num_total = 0;
29         
30         for ( ;; ) {
31                 int port;
32                 double x;
33                 unsigned long long y1, y2;
34                 
35                 if (scanf("%d %lf %llu %llu", &port, &x, &y1, &y2) != 4)
36                         break;
37
38                 if (port != last_port) {
39                         if (last_port != -1) {
40                                 if (!total_only)
41                                         make_graph(last_port, width, height, fp.get_min_x(), fp.get_max_x(), fp.get_min_y(), fp.get_max_y(), flow);
42                                 total_flow = sum_flows(total_flow, flow);
43                                 fprintf(stderr, "%u (%u)\n", last_port, ++num_total);
44                         }
45
46                         // reset
47                         last_port = port;
48                         fp.reset(x, y1, y2);
49                         continue;
50                 }
51
52                 fp.push(x, y1, y2);
53         }
54
55         // last graph
56         if (!total_only)
57                 make_graph(last_port, width, height, fp.get_min_x(), fp.get_max_x(), fp.get_min_y(), fp.get_max_y(), flow);
58         total_flow = sum_flows(total_flow, flow);
59         
60         // total graph
61         unsigned long long min_y = 0;
62         unsigned long long max_y = 10000000;
63
64         for (unsigned i = 0; i < total_flow.size(); ++i) {
65                 flow_element fe = total_flow[i];
66                 
67                 min_y = std::min(min_y, fe.y1);
68                 max_y = std::max(max_y, fe.y1);
69                 
70                 min_y = std::min(min_y, fe.y2);
71                 max_y = std::max(max_y, fe.y2);
72         }
73         
74         make_graph(65535, width, height, total_flow[0].x, total_flow[total_flow.size() - 1].x, min_y, max_y, total_flow);
75 }