"Fossies" - the Fresh Open Source Software Archive

Member "tcpflow-1.6.1/src/netviz/time_histogram_view.h" (19 Feb 2021, 2947 Bytes) of package /linux/misc/tcpflow-1.6.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "time_histogram_view.h" see the Fossies "Dox" file reference documentation.

    1 /**
    2  * time_histogram_view.h: 
    3  * Make fancy time histograms
    4  *
    5  * This source file is public domain, as it is not based on the original tcpflow.
    6  *
    7  * Author: Michael Shick <mike@shick.in>
    8  *
    9  */
   10 
   11 
   12 #ifndef TIME_HISTOGRAM_VIEW_H
   13 #define TIME_HISTOGRAM_VIEW_H
   14 
   15 #include "config.h"
   16 #ifdef HAVE_LIBCAIRO
   17 
   18 #include "plot_view.h"
   19 #include "time_histogram.h"
   20 
   21 #define SECOND_NAME "second"
   22 #define MINUTE_NAME "minute"
   23 #define HOUR_NAME "hour"
   24 #define DAY_NAME "day"
   25 #define WEEK_NAME "week"
   26 #define MONTH_NAME "month"
   27 #define YEAR_NAME "year"
   28 
   29 class time_histogram_view : public plot_view {
   30 public:
   31     typedef std::map<in_port_t, rgb_t> colormap_t;
   32     time_histogram_view(const time_histogram &histogram_,
   33             const colormap_t &port_colors_,
   34             const rgb_t &default_color_, const rgb_t &cdf_color_);
   35 
   36     class time_unit {
   37     public:
   38         time_unit(std::string name_, uint64_t seconds_) :
   39             name(name_), seconds(seconds_) {}
   40         std::string name;
   41         uint64_t seconds;
   42     };
   43     class si_prefix {
   44     public:
   45         si_prefix(std::string prefix_, uint64_t magnitude_) :
   46             prefix(prefix_), magnitude(magnitude_) {}
   47         std::string prefix;
   48         uint64_t magnitude;
   49     };
   50     class bucket_view {
   51     public:
   52         bucket_view(const time_histogram::bucket &bucket_,
   53                 const colormap_t &color_map_,
   54                 const rgb_t &default_color_) :
   55             bucket(bucket_), color_map(color_map_), default_color(default_color_) {}
   56 
   57         const time_histogram::bucket &bucket;
   58         const colormap_t &color_map;
   59         const rgb_t &default_color;
   60 
   61         void render(cairo_t *cr, const bounds_t &bounds);
   62     };
   63 
   64     const time_histogram &histogram;
   65     const colormap_t port_colors;
   66     const rgb_t default_color;
   67     const rgb_t cdf_color;
   68 
   69     static const uint8_t y_tick_count;
   70     static const double bar_space_factor;
   71     static const double cdf_line_width;
   72     static const std::vector<time_unit> time_units;
   73     static const std::vector<si_prefix> si_prefixes;
   74     static const double blank_bar_line_width;
   75     static const rgb_t blank_bar_line_color;
   76     static const double bar_label_font_size;
   77     static const double bar_label_width_factor;
   78     static const rgb_t bar_label_normal_color;
   79     static const rgb_t bar_label_highlight_color;
   80 
   81     void render(cairo_t *cr, const bounds_t &bounds);
   82     void render_data(cairo_t *cr, const bounds_t &bounds);
   83     static std::string next_bar_label(const std::string &unit, unsigned &numeric_label, unsigned delta,
   84             rgb_t &label_color);
   85 
   86 private:
   87     // for labelling purposes, a bar is <value> <unit>s wide
   88     std::string bar_time_unit;
   89     uint32_t bar_time_value;
   90     // if the bar time unit isn't exact, we can't label bars because they'll drift
   91     uint32_t bar_time_remainder;
   92 
   93     static std::vector<time_unit> build_time_units();
   94     static std::vector<si_prefix> build_si_prefixes();
   95 };
   96 
   97 #endif
   98 #endif