Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
waveform.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_BASE_WAVEFORM_H_
20 #define PAGESPEED_KERNEL_BASE_WAVEFORM_H_
21 
22 #include <utility>
23 
27 
28 namespace net_instaweb {
29 
30 class AbstractMutex;
31 class MessageHandler;
32 class ThreadSystem;
33 class Timer;
34 class UpDownCounter;
35 class Writer;
36 
45 class Waveform {
46  public:
47  Waveform(ThreadSystem* thread_system, Timer* timer, int capacity,
48  UpDownCounter* metric);
49 
50  void Clear();
51  double Average();
52  double Maximum();
53  double Minimum();
54  int Size();
55 
57  void Add(double value);
58 
61  void AddDelta(double delta);
62 
66  static void RenderHeader(Writer* writer, MessageHandler* handler);
67 
69  void Render(const StringPiece& title, const StringPiece& label,
70  Writer* writer, MessageHandler* handler);
71 
72  private:
73  typedef std::pair<int64, double> TimeValue;
74 
75  TimeValue* GetSample(int index);
76  void AddHelper(double value);
77 
78  Timer* timer_;
79  int capacity_;
80  scoped_array<TimeValue> samples_;
81  int start_index_;
82  int size_;
83  int64 first_sample_timestamp_us_;
84  double total_since_clear_;
85  double min_;
86  double max_;
87  double previous_value_;
89 
92  UpDownCounter* metric_;
93 
94 
95 };
96 
97 }
98 
99 #endif
void Render(const StringPiece &title, const StringPiece &label, Writer *writer, MessageHandler *handler)
Renders a waveform into HTML.
static void RenderHeader(Writer *writer, MessageHandler *handler)
Definition: waveform.h:45
Definition: scoped_ptr.h:30
Interface for writing bytes to an output stream.
Definition: writer.h:29
Definition: thread_system.h:40
Definition: statistics.h:73
Definition: message_handler.h:39
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
void AddDelta(double delta)
void Add(double value)
Records a value at the current time using the Timer.