~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/cache/cache_stats.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 2012 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_CACHE_CACHE_STATS_H_
20
 
#define PAGESPEED_KERNEL_CACHE_CACHE_STATS_H_
21
 
 
22
 
#include "pagespeed/kernel/base/atomic_bool.h"
23
 
#include "pagespeed/kernel/base/basictypes.h"
24
 
#include "pagespeed/kernel/base/string.h"
25
 
#include "pagespeed/kernel/base/string_util.h"
26
 
#include "pagespeed/kernel/cache/cache_interface.h"
27
 
 
28
 
namespace net_instaweb {
29
 
 
30
 
class Histogram;
31
 
class SharedString;
32
 
class Statistics;
33
 
class Timer;
34
 
class Variable;
35
 
 
36
 
// Wrapper around a CacheInterface that adds statistics and histograms
37
 
// for hit-rate, latency, etc.  As there can be multiple caches in a
38
 
// system (l1, l2, etc), the constructor takes a string prefix so they
39
 
// can be measured independently.
40
 
class CacheStats : public CacheInterface {
41
 
 public:
42
 
  // Doees not takes ownership of the cache, timer, or statistics.
43
 
  CacheStats(StringPiece prefix,
44
 
             CacheInterface* cache,
45
 
             Timer* timer,
46
 
             Statistics* statistics);
47
 
  virtual ~CacheStats();
48
 
 
49
 
  // This must be called once for every unique cache prefix.
50
 
  static void InitStats(StringPiece prefix, Statistics* statistics);
51
 
 
52
 
  virtual void Get(const GoogleString& key, Callback* callback);
53
 
  virtual void MultiGet(MultiGetRequest* request);
54
 
  virtual void Put(const GoogleString& key, SharedString* value);
55
 
  virtual void Delete(const GoogleString& key);
56
 
  virtual CacheInterface* Backend() { return cache_; }
57
 
  virtual bool IsBlocking() const { return cache_->IsBlocking(); }
58
 
 
59
 
  virtual bool IsHealthy() const {
60
 
    return !shutdown_.value() && cache_->IsHealthy();
61
 
  }
62
 
 
63
 
  virtual void ShutDown() {
64
 
    shutdown_.set_value(true);
65
 
    cache_->ShutDown();
66
 
  }
67
 
 
68
 
  virtual GoogleString Name() const {
69
 
    return FormatName(prefix_, cache_->Name());
70
 
  }
71
 
  static GoogleString FormatName(StringPiece prefix, StringPiece cache);
72
 
 
73
 
 private:
74
 
  class StatsCallback;
75
 
  friend class StatsCallback;
76
 
 
77
 
  CacheInterface* cache_;
78
 
  Timer* timer_;
79
 
  Histogram* get_count_histogram_;
80
 
  Histogram* hit_latency_us_histogram_;
81
 
  Histogram* insert_latency_us_histogram_;
82
 
  Histogram* insert_size_bytes_histogram_;
83
 
  Histogram* lookup_size_bytes_histogram_;
84
 
  Variable* deletes_;
85
 
  Variable* hits_;
86
 
  Variable* inserts_;
87
 
  Variable* misses_;
88
 
  GoogleString prefix_;
89
 
  AtomicBool shutdown_;
90
 
 
91
 
  DISALLOW_COPY_AND_ASSIGN(CacheStats);
92
 
};
93
 
 
94
 
}  // namespace net_instaweb
95
 
 
96
 
#endif  // PAGESPEED_KERNEL_CACHE_CACHE_STATS_H_