~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/base/waveform.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
17
 
// Author: jmarantz@google.com (Joshua Marantz)
18
 
 
19
 
#ifndef PAGESPEED_KERNEL_BASE_WAVEFORM_H_
20
 
#define PAGESPEED_KERNEL_BASE_WAVEFORM_H_
21
 
 
22
 
#include <utility>                      // for pair
23
 
 
24
 
#include "pagespeed/kernel/base/basictypes.h"
25
 
#include "pagespeed/kernel/base/scoped_ptr.h"
26
 
#include "pagespeed/kernel/base/string_util.h"
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
 
 
37
 
// Displays a waveform of values over time.  This can run
38
 
// continuously, in which case it will only display waveforms for a
39
 
// bounded number of samples.  Or it can be run as a trigger.
40
 
//
41
 
// However the average, min, and max values will account for all the
42
 
// values seen by the waveform since it was cleared.
43
 
//
44
 
// This class is threadsafe.
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
 
 
56
 
  // Records a value at the current time using the Timer.
57
 
  void Add(double value);
58
 
 
59
 
  // Records a delta relative to the previous value using the Timer.
60
 
  // This is equivalent to calling Add(previous_value + delta).
61
 
  void AddDelta(double delta);
62
 
 
63
 
  // Write script and function to web page. Note that this function
64
 
  // should be called only once for each HTML page, and should not be
65
 
  // used for each waveform.
66
 
  static void RenderHeader(Writer* writer, MessageHandler* handler);
67
 
 
68
 
  // Renders a waveform into HTML.
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);  // Must be called with mutex held.
76
 
  void AddHelper(double value);     // Must be called with mutex held.
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_;
88
 
  scoped_ptr<AbstractMutex> mutex_;  // protects all the above member variables.
89
 
 
90
 
  // Un-owned pointer to a variable to export current waveform values.
91
 
  // May be NULL.
92
 
  UpDownCounter* metric_;
93
 
 
94
 
  DISALLOW_COPY_AND_ASSIGN(Waveform);
95
 
};
96
 
 
97
 
}  // namespace net_instaweb
98
 
 
99
 
#endif  // PAGESPEED_KERNEL_BASE_WAVEFORM_H_