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