Page Speed Optimization Libraries
1.3.25.1
|
00001 /* 00002 * Copyright 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 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 "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/scoped_ptr.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_