00001
00002
00003
00004
00005
00006
00007
00008 #include "EventFilter/StorageManager/interface/SMPerformanceMeter.h"
00009
00010 stor::SMPerfStats::SMPerfStats():
00011 samples_(1000),
00012 period4samples_(5),
00013 maxBandwidth_(0.),
00014 minBandwidth_(999999.),
00015 maxBandwidth2_(0.),
00016 minBandwidth2_(999999.)
00017 {
00018 longTermCounter_.reset(new ForeverCounter());
00019 shortTermCounter_.reset(new RollingSampleCounter(samples_, samples_, samples_,
00020 RollingSampleCounter::INCLUDE_SAMPLES_IMMEDIATELY));
00021 shortPeriodCounter_.reset(new RollingIntervalCounter(10*period4samples_, period4samples_, period4samples_));
00022 }
00023
00024 void stor::SMPerfStats::reset()
00025 {
00026 maxBandwidth_ = 0.;
00027 minBandwidth_ = 999999.;
00028 maxBandwidth2_ = 0.;
00029 minBandwidth2_ = 999999.;
00030 }
00031
00032 void stor::SMPerfStats::fullReset()
00033 {
00034 longTermCounter_.reset(new ForeverCounter());
00035 shortTermCounter_.reset(new RollingSampleCounter(samples_, samples_, samples_,
00036 RollingSampleCounter::INCLUDE_SAMPLES_IMMEDIATELY));
00037 shortPeriodCounter_.reset(new RollingIntervalCounter(10*period4samples_, period4samples_, period4samples_));
00038 maxBandwidth_ = 0.;
00039 minBandwidth_ = 999999.;
00040 maxBandwidth2_ = 0.;
00041 minBandwidth2_ = 999999.;
00042 }
00043
00044 stor::SMOnlyStats::SMOnlyStats():
00045 instantBandwidth_(0.0),
00046 instantRate_(0.0),
00047 instantLatency_(0.0),
00048 totalSamples_(0.0),
00049 duration_(0.0),
00050 meanBandwidth_(0.0),
00051 meanRate_(0.0),
00052 meanLatency_(0.0),
00053 maxBandwidth_(0.0),
00054 minBandwidth_(999999.0),
00055 instantBandwidth2_(0.0),
00056 instantRate2_(0.0),
00057 instantLatency2_(0.0),
00058 totalSamples2_(0.0),
00059 duration2_(0.0),
00060 meanBandwidth2_(0.0),
00061 meanRate2_(0.0),
00062 meanLatency2_(0.0),
00063 maxBandwidth2_(0.0),
00064 minBandwidth2_(999999.0),
00065 receivedVolume_(0.0)
00066 {
00067 }
00068
00069 stor::SMPerformanceMeter::SMPerformanceMeter():
00070 loopCounter_(0)
00071 {
00072 stats_.fullReset();
00073 }
00074
00075 void stor::SMPerformanceMeter::init(unsigned long samples, unsigned long time_period)
00076 {
00077
00078
00079
00080
00081 boost::mutex::scoped_lock sl(data_lock_);
00082 loopCounter_ = 0;
00083 stats_.samples_ = samples;
00084 stats_.period4samples_ = time_period;
00085 stats_.fullReset();
00086 }
00087
00088 bool stor::SMPerformanceMeter::addSample(unsigned long size)
00089 {
00090
00091
00092
00093
00094
00095 boost::mutex::scoped_lock sl(data_lock_);
00096
00097 stats_.longTermCounter_->addSample( (double) size / (double) 0x100000 );
00098 stats_.shortTermCounter_->addSample( (double) size / (double) 0x100000 );
00099 stats_.shortPeriodCounter_->addSample( (double) size / (double) 0x100000 );
00100
00101 if ( stats_.shortPeriodCounter_->hasValidResult() )
00102 {
00103 double testVal = stats_.shortPeriodCounter_->getValueRate();
00104 if (testVal > stats_.maxBandwidth2_)
00105 stats_.maxBandwidth2_ = testVal;
00106 if (testVal < stats_.minBandwidth2_)
00107 stats_.minBandwidth2_ = testVal;
00108 }
00109
00110 if ( loopCounter_ == (stats_.samples_ - 1 ) )
00111 {
00112 loopCounter_ = 0;
00113
00114 double testVal = stats_.shortTermCounter_->getValueRate();
00115 if (testVal > stats_.maxBandwidth_)
00116 stats_.maxBandwidth_ = testVal;
00117 if (testVal < stats_.minBandwidth_)
00118 stats_.minBandwidth_ = testVal;
00119
00120 return true;
00121 }
00122 ++loopCounter_;
00123
00124 return false;
00125 }
00126
00127 void stor::SMPerformanceMeter::setSamples(unsigned long num_samples)
00128 {
00129 boost::mutex::scoped_lock sl(data_lock_);
00130 stats_.samples_ = num_samples;
00131 stats_.fullReset();
00132 }
00133
00134 void stor::SMPerformanceMeter::setPeriod4Samples(unsigned long time_period)
00135 {
00136 boost::mutex::scoped_lock sl(data_lock_);
00137 stats_.period4samples_ = time_period;
00138 stats_.fullReset();
00139 }
00140
00141 stor::SMPerfStats stor::SMPerformanceMeter::getStats()
00142 {
00143 boost::mutex::scoped_lock sl(data_lock_);
00144 return stats_;
00145 }
00146
00147 unsigned long stor::SMPerformanceMeter::samples()
00148 {
00149 boost::mutex::scoped_lock sl(data_lock_);
00150 return stats_.samples_;
00151 }
00152
00153 double stor::SMPerformanceMeter::totalvolumemb()
00154 {
00155 boost::mutex::scoped_lock sl(data_lock_);
00156 return stats_.longTermCounter_->getValueSum();
00157 }
00158
00159