00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "simlpy/interpreter_defs.h"
00032
00033 #include "GStatDump.h"
00034 #include "GStatCollect.h"
00035 #include "Measurement.h"
00036 #include "simlpy/Clock.h"
00037 #include <iostream>
00038
00039 GStatDump::GStatDump( std::ostream& s, unsigned long int t ) :
00040 m_stream( s ),
00041 m_period( 0, t )
00042 {
00043 }
00044
00045 GStatDump::~GStatDump()
00046 {
00047 }
00048
00049 Entity*
00050 GStatDump::create() const
00051 {
00052 return 0;
00053 }
00054
00055 void
00056 GStatDump::configure( const ArgList& args )
00057 {
00058 }
00059
00060 void
00061 GStatDump::emit( const ArgList& args )
00062 {
00063 }
00064
00065 bool
00066 GStatDump::handler( GStatTrigger& event )
00067 {
00068 if ( Time(0,0) == m_period ) return false;
00069 Time t = Clock::time() + m_period;
00070 Clock::schedule( new GStatCollect( this, this, t ) );
00071 return true;
00072 }
00073
00074 bool
00075 GStatDump::handler( GStatCollect& event )
00076 {
00077 dump();
00078
00079 if ( Time(0,0) == m_period ) return false;
00080 Time t = Clock::time() + m_period;
00081 if ( 0 != Clock::numEvents() )
00082 {
00083 Clock::schedule( new GStatCollect( this, this, t ) );
00084 }
00085 else
00086 {
00087 Clock::tentative( new GStatCollect( this, this, t ) );
00088 }
00089 return true;
00090 }
00091
00092 void
00093 GStatDump::dump()
00094 {
00096 GlobalStatistics* gs = GlobalStatistics::instance();
00097 if ( 0 == gs )
00098 {
00099 return;
00100 }
00101 Time t = Clock::time();
00102
00103 m_stream << t
00104 << " originated unique ";
00105 dumpStat(gs->since().originated().unique());
00106 m_stream << " ";
00107 dumpStat(gs->total().originated().unique());
00108 m_stream << "\n";
00109
00110 m_stream << t
00111 << " originated duplicate ";
00112 dumpStat(gs->since().originated().duplicate());
00113 m_stream << " ";
00114 dumpStat(gs->total().originated().duplicate());
00115 m_stream << "\n";
00116
00117 m_stream << t
00118 << " delivered unique ";
00119 dumpStat(gs->since().delivered().unique());
00120 m_stream << " ";
00121 dumpStat(gs->total().delivered().unique());
00122 m_stream << "\n";
00123
00124 m_stream << t
00125 << " delivered duplicate ";
00126 dumpStat(gs->since().delivered().duplicate());
00127 m_stream << " ";
00128 dumpStat(gs->total().delivered().duplicate());
00129 m_stream << "\n";
00130
00131 m_stream << t
00132 << " delivered hops ";
00133 dumpStat(gs->since().deliverHops());
00134 m_stream << " ";
00135 dumpStat(gs->total().deliverHops());
00136 m_stream << "\n";
00137
00138 m_stream << t
00139 << " sent ";
00140 dumpStat(gs->since().sent());
00141 m_stream << " ";
00142 dumpStat(gs->total().sent());
00143 m_stream << "\n";
00144
00145 m_stream << t
00146 << " received ";
00147 dumpStat(gs->since().received());
00148 m_stream << " ";
00149 dumpStat(gs->total().received());
00150 m_stream << "\n";
00151
00152 m_stream << t
00153 << " dropped bytes ";
00154 dumpStat(gs->since().dropped());
00155 m_stream << " ";
00156 dumpStat(gs->total().dropped());
00157 m_stream << "\n";
00158
00159 m_stream << t
00160 << " dropped hops ";
00161 dumpStat(gs->since().dropHops());
00162 m_stream << " ";
00163 dumpStat(gs->total().dropHops());
00164 m_stream << "\n";
00165
00166 double ndelv = gs->total().delivered().unique().n();
00167 double norig = gs->total().originated().unique().n();
00168 double ndrop = gs->total().dropped().n();
00169 double nsent = norig + gs->total().delivered().duplicate().n();
00170 Measurement fdelivered( ndelv/norig ,
00171 (ndelv/(norig*norig))*(1-ndelv/norig) );
00172 Measurement fdropped( ndrop/nsent ,
00173 (ndrop/(nsent*nsent))*(1-ndrop/nsent) );
00174 m_stream << t
00175 << " fdelivered "
00176 << fdelivered
00177 << "\n";
00178 m_stream << t
00179 << " fdropped "
00180 << fdropped
00181 << "\n";
00182
00183 m_stream << t
00184 << " storage "
00185 << gs->used()
00186 << " "
00187 << gs->capacity()
00188 << " "
00189 << gs->maxUsed()
00190 << "\n";
00191
00192 m_stream << t
00193 << " exhausted "
00194 << gs->since().exhausted()
00195 << " "
00196 << gs->total().exhausted()
00197 << "\n";
00198
00199 m_stream.flush();
00200 gs->reset();
00201 }
00202
00203 void
00204 GStatDump::dumpStat( const Stat& s )
00205 {
00206 m_stream << s.n() << " " << s.s() << " " << Measurement(s.mean(),s.var());
00207 }