00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_WAVEFORM_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_WAVEFORM_H_
00021
00022 #include <utility>
00023
00024 #include "base/scoped_ptr.h"
00025 #include "net/instaweb/util/public/basictypes.h"
00026 #include "net/instaweb/util/public/string_util.h"
00027
00028 namespace net_instaweb {
00029
00030 class AbstractMutex;
00031 class MessageHandler;
00032 class ThreadSystem;
00033 class Timer;
00034 class Writer;
00035
00044 class Waveform {
00045 public:
00046 Waveform(ThreadSystem* thread_system, Timer* timer, int capacity);
00047
00048 void Clear();
00049 double Average();
00050 double Maximum();
00051 double Minimum();
00052 int Size();
00053
00055 void Add(double value);
00056
00059 void AddDelta(double delta);
00060
00064 static void RenderHeader(Writer* writer, MessageHandler* handler);
00065
00067 void Render(const StringPiece& title, const StringPiece& label,
00068 Writer* writer, MessageHandler* handler);
00069
00070 private:
00071 typedef std::pair<int64, double> TimeValue;
00072
00073 TimeValue* GetSample(int index);
00074 void AddHelper(double value);
00075
00076 Timer* timer_;
00077 int capacity_;
00078 scoped_array<TimeValue> samples_;
00079 int start_index_;
00080 int size_;
00081 int64 first_sample_timestamp_us_;
00082 double total_since_clear_;
00083 double min_;
00084 double max_;
00085 double previous_value_;
00086 scoped_ptr<AbstractMutex> mutex_;
00087
00088 DISALLOW_COPY_AND_ASSIGN(Waveform);
00089 };
00090
00091 }
00092
00093 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_WAVEFORM_H_