Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shared_mem_statistics.h
Go to the documentation of this file.
1 // Copyright 2010 Google Inc. All Rights Reserved.
16 
17 #ifndef PAGESPEED_KERNEL_SHAREDMEM_SHARED_MEM_STATISTICS_H_
18 #define PAGESPEED_KERNEL_SHAREDMEM_SHARED_MEM_STATISTICS_H_
19 
20 #include <cstddef>
21 
30 
31 namespace net_instaweb {
32 
33 class FileSystem;
34 class MessageHandler;
35 class StatisticsLogger;
36 class Timer;
37 
57  public:
58  SharedMemVariable(StringPiece name, Statistics* stats);
59  virtual ~SharedMemVariable() {}
60  virtual StringPiece GetName() const { return name_; }
61 
62  protected:
63  virtual AbstractMutex* mutex() const;
64  virtual int64 GetLockHeld() const;
65  virtual int64 SetReturningPreviousValueLockHeld(int64 value);
66 
67  private:
68  friend class SharedMemStatistics;
69  friend class SharedMemTimedVariable;
70 
71  explicit SharedMemVariable(const StringPiece& name);
72 
73  void AttachTo(AbstractSharedMemSegment* segment_, size_t offset,
74  MessageHandler* message_handler);
75 
78  void Reset();
79 
81  const GoogleString name_;
82 
85 
87  volatile int64* value_ptr_;
88 
89 
90 };
91 
92 class SharedMemHistogram : public Histogram {
93  public:
94  SharedMemHistogram(StringPiece name, Statistics* stats);
95 
96  virtual ~SharedMemHistogram();
97  virtual void Add(double value);
98  virtual void Clear();
99  virtual int NumBuckets();
103  virtual void EnableNegativeBuckets();
105  virtual void SetMinValue(double value);
109  virtual void SetMaxValue(double value);
110 
115  virtual void SetSuggestedNumBuckets(int i);
116 
119  size_t AllocationSize(AbstractSharedMem* shm_runtime) {
122  return shm_runtime->SharedMutexSize() + sizeof(HistogramBody) +
123  sizeof(double) * NumBuckets();
124  }
125 
126  protected:
127  virtual AbstractMutex* lock() {
128  return mutex_.get();
129  }
130  virtual double AverageInternal();
131  virtual double PercentileInternal(const double perc);
132  virtual double StandardDeviationInternal();
133  virtual double CountInternal();
134  virtual double MaximumInternal();
135  virtual double MinimumInternal();
136  virtual double BucketStart(int index);
137  virtual double BucketCount(int index);
138 
139  private:
140  friend class SharedMemStatistics;
141  void AttachTo(AbstractSharedMemSegment* segment, size_t offset,
142  MessageHandler* message_handler);
143 
146  double BucketWidth();
147 
150  int FindBucket(double value);
151  void Init();
152  void DCheckRanges() const;
153  void Reset();
154  void ClearInternal();
155  const GoogleString name_;
156  scoped_ptr<AbstractMutex> mutex_;
158  struct HistogramBody {
160  bool enable_negative_;
162  double min_value_;
165  double max_value_;
167  double min_;
169  double max_;
170  double count_;
171  double sum_;
172  double sum_of_squares_;
174  double values_[1];
175  };
177  int num_buckets_;
178  HistogramBody* buffer_;
179 
180 };
181 
183  SharedMemVariable, SharedMemHistogram, FakeTimedVariable> {
184  public:
185  SharedMemStatistics(int64 logging_interval_ms,
186  int64 max_logfile_size_kb,
187  const StringPiece& logging_file, bool logging,
188  const GoogleString& filename_prefix,
189  AbstractSharedMem* shm_runtime,
190  MessageHandler* message_handler, FileSystem* file_system,
191  Timer* timer);
192  virtual ~SharedMemStatistics();
193 
204  bool Init(bool parent, MessageHandler* message_handler);
205 
208  void GlobalCleanup(MessageHandler* message_handler);
209 
212  static void GlobalCleanup(AbstractSharedMem* shm_runtime,
213  const GoogleString& segment_name,
214  MessageHandler* message_handler);
215 
216  GoogleString SegmentName() const;
217 
220  return console_logger_.get();
221  }
222 
223  protected:
224  virtual Var* NewVariable(StringPiece name);
225  virtual UpDown* NewUpDownCounter(StringPiece name);
226  virtual Hist* NewHistogram(StringPiece name);
227 
228  private:
231  bool InitMutexes(size_t per_var, MessageHandler* message_handler);
232 
233  friend class SharedMemStatisticsTestBase;
234 
235  AbstractSharedMem* shm_runtime_;
236  GoogleString filename_prefix_;
238  bool frozen_;
240  scoped_ptr<StatisticsLogger> console_logger_;
241 
242 
243 };
244 
245 }
246 
247 #endif
virtual double AverageInternal()
Note that these *Internal interfaces require the mutex to be held.
virtual void SetSuggestedNumBuckets(int i)
TimeDVariable.
Definition: statistics_template.h:358
virtual void Add(double value)
Record a value in its bucket.
bool Init(bool parent, MessageHandler *message_handler)
virtual UpDown * NewUpDownCounter(StringPiece name)
Interface to subclass.
virtual void SetMinValue(double value)
Set the minimum value allowed in histogram.
virtual int64 GetLockHeld() const
Get/Setters that may only be called if you already hold the mutex.
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
Abstract interface for implementing a mutex.
Definition: abstract_mutex.h:28
Definition: shared_mem_statistics.h:182
virtual double BucketStart(int index)
void GlobalCleanup(MessageHandler *message_handler)
Definition: scoped_ptr.h:30
virtual Var * NewVariable(StringPiece name)
Interface to subclass.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual double BucketCount(int index)
Value of a bucket.
Definition: abstract_shared_mem.h:86
Definition: shared_mem_statistics.h:92
virtual int NumBuckets()
Returns number of buckets the histogram actually has.
Definition: file_system.h:76
VarTemplate< SharedMemVariable > Var
Add typedefs for template class args to make them visible to subclasses.
Definition: statistics_template.h:363
Definition: statistics.h:138
Definition: shared_mem_statistics.h:56
Definition: statistics.h:112
virtual size_t SharedMutexSize() const =0
Size of mutexes inside shared memory segments.
Definition: shared_mem_statistics_test_base.h:36
virtual void SetMaxValue(double value)
virtual void Clear()
Throw away all data.
Definition: message_handler.h:39
size_t AllocationSize(AbstractSharedMem *shm_runtime)
Definition: shared_mem_statistics.h:119
Definition: abstract_shared_mem.h:31
virtual StatisticsLogger * console_logger()
Definition: shared_mem_statistics.h:219
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
Definition: statistics_logger.h:42