X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=web%2Fext%2Fgraphall.cpp;fp=web%2Fext%2Fgraphall.cpp;h=a21fc45294838c80f4de1306e18769e4ba97ee44;hb=9b525f6032627f2d79ae65f9e2b1a97bbad587c0;hp=0000000000000000000000000000000000000000;hpb=695c9e23ff4269be48270335b2fcaf4e8a9dab9a;p=nms diff --git a/web/ext/graphall.cpp b/web/ext/graphall.cpp new file mode 100644 index 0000000..a21fc45 --- /dev/null +++ b/web/ext/graphall.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include "graph.h" +#include "flowpusher.h" +#include "flowutil.h" + +int main(int argc, char **argv) +{ + bool total_only = false; + int width = 500, height = 250; + + std::vector flow, total_flow; + FlowPusher fp(flow); + int last_port = -1; + + mallopt(M_TRIM_THRESHOLD, -1); + + if (argc == 2 && strcmp(argv[1], "--total-only") == 0) { + width = 1000; + height = 500; + total_only = true; + } + + int num_total = 0; + + for ( ;; ) { + int port; + double x; + unsigned long long y1, y2; + + if (scanf("%d %lf %llu %llu", &port, &x, &y1, &y2) != 4) + break; + + if (port != last_port) { + if (last_port != -1) { + if (!total_only) + make_graph(last_port, width, height, fp.get_min_x(), fp.get_max_x(), fp.get_min_y(), fp.get_max_y(), flow); + total_flow = sum_flows(total_flow, flow); + fprintf(stderr, "%u (%u)\n", last_port, ++num_total); + } + + // reset + last_port = port; + fp.reset(x, y1, y2); + continue; + } + + fp.push(x, y1, y2); + } + + // last graph + if (!total_only) + make_graph(last_port, width, height, fp.get_min_x(), fp.get_max_x(), fp.get_min_y(), fp.get_max_y(), flow); + total_flow = sum_flows(total_flow, flow); + + // total graph + unsigned long long min_y = 0; + unsigned long long max_y = 10000000; + + for (unsigned i = 0; i < total_flow.size(); ++i) { + flow_element fe = total_flow[i]; + + min_y = std::min(min_y, fe.y1); + max_y = std::max(max_y, fe.y1); + + min_y = std::min(min_y, fe.y2); + max_y = std::max(max_y, fe.y2); + } + + make_graph(65535, width, height, total_flow[0].x, total_flow[total_flow.size() - 1].x, min_y, max_y, total_flow); +}