Page Speed Optimization Libraries
1.4.26.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 Variable; 00035 class Writer; 00036 00045 class Waveform { 00046 public: 00047 Waveform(ThreadSystem* thread_system, Timer* timer, int capacity, 00048 Variable* metric); 00049 00050 void Clear(); 00051 double Average(); 00052 double Maximum(); 00053 double Minimum(); 00054 int Size(); 00055 00057 void Add(double value); 00058 00061 void AddDelta(double delta); 00062 00066 static void RenderHeader(Writer* writer, MessageHandler* handler); 00067 00069 void Render(const StringPiece& title, const StringPiece& label, 00070 Writer* writer, MessageHandler* handler); 00071 00072 private: 00073 typedef std::pair<int64, double> TimeValue; 00074 00075 TimeValue* GetSample(int index); 00076 void AddHelper(double value); 00077 00078 Timer* timer_; 00079 int capacity_; 00080 scoped_array<TimeValue> samples_; 00081 int start_index_; 00082 int size_; 00083 int64 first_sample_timestamp_us_; 00084 double total_since_clear_; 00085 double min_; 00086 double max_; 00087 double previous_value_; 00088 scoped_ptr<AbstractMutex> mutex_; 00089 00092 Variable* metric_; 00093 00094 DISALLOW_COPY_AND_ASSIGN(Waveform); 00095 }; 00096 00097 } 00098 00099 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_WAVEFORM_H_