00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_STATS_TFI_PLOT_HXX_
00023 # define WIFI_STATS_TFI_PLOT_HXX_
00024
00025 # include <wipal/wifi/stats/tfi_plot.hh>
00026
00027 namespace wpl
00028 {
00029
00030 namespace wifi
00031 {
00032
00033 namespace stats
00034 {
00035
00036 inline
00037 tfi_plot::tfi_plot(const void*):
00038 tfi_ (boost::extents[100 / score_step + 1][load_max / load_step]),
00039 epoch_start_ (0),
00040 total_ (0),
00041 missed_ (0)
00042 {
00043 };
00044
00045 template <class Frame>
00046 void
00047 tfi_plot::account_frame(const Frame& frame,
00048 const size_t& ,
00049 const type::frame_type& ,
00050 const unsigned& ,
00051 const bool& ,
00052 const addr* const& ,
00053 const addr* const& ,
00054 const bool& )
00055 {
00056
00057 const tool::microseconds& stamp = frame.microseconds();
00058
00059 if (0 == epoch_start_)
00060 epoch_start_ = stamp;
00061 else
00062 {
00063 if (stamp < epoch_start_)
00064 {
00065 std::cerr << frame << ": Out of sequence." << std::endl;
00066 return;
00067 }
00068
00069 const tool::microseconds dt = stamp - epoch_start_;
00070
00071 if (dt > epoch_length)
00072 {
00073 const tool::microseconds el (epoch_length);
00074 const unsigned k = dt.get_div_by(epoch_length);
00075
00076 end_epoch(epoch_start_ + el * k);
00077 }
00078 }
00079 ++total_;
00080 }
00081
00082 inline
00083 void
00084 tfi_plot::account_gap(const unsigned& gap_length)
00085 {
00086 missed_ += gap_length;
00087 }
00088
00089 inline
00090 void
00091 tfi_plot::account_miss()
00092 {
00093 ++missed_;
00094 }
00095
00096 inline
00097 std::ostream&
00098 tfi_plot::print(std::ostream& o) const
00099 {
00100 o << "begin T-Fi plot\n";
00101
00102 for (unsigned i = 0; i < 100 / score_step + 1; ++i)
00103 for (unsigned k = 0; k < 2; ++k)
00104 {
00105 if (i or k)
00106 o << '\n';
00107
00108 unsigned x = 0;
00109 const double y = (i + k) * score_step / 100.l;
00110
00111 for (unsigned j = 0; j < load_max / load_step; ++j)
00112 {
00113 o << " " << x << '\t' << y << '\t' << tfi_[i][j] << '\n';
00114 x += load_step;
00115 o << " " << x << '\t' << y << '\t' << tfi_[i][j] << '\n';
00116 }
00117 }
00118 return o << "end T-Fi plot" << std::endl;
00119 }
00120
00121 inline
00122 void
00123 tfi_plot::restart()
00124 {
00125 end_epoch(0);
00126 }
00127
00128 inline
00129 void
00130 tfi_plot::end_epoch(const tool::microseconds& new_epoch_start)
00131 {
00132 if (total_ + missed_)
00133 {
00134 const double load = total_ + missed_;
00135 const double score = total_ / load;
00136
00137 if (load < load_max)
00138 ++tfi_[unsigned (score * 100 / score_step)][load / load_step];
00139 }
00140 epoch_start_ = new_epoch_start;
00141 total_ = 0;
00142 missed_ = 0;
00143 }
00144
00145
00146 }
00147
00148 }
00149
00150 }
00151
00152 #endif // ! WIFI_STATS_TFI_PLOT_HXX_