make #includes consistent
[hiphop-php.git] / hphp / runtime / base / shared / shared_store_stats.h
blobf29411075d1383219158a74284a5ada973264ad8
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_SHARED_STORESTATS_H_
18 #define incl_HPHP_SHARED_STORESTATS_H_
20 #include "tbb/concurrent_hash_map.h"
22 #include "hphp/runtime/base/shared/shared_variant.h"
23 #include "hphp/runtime/base/complex_types.h"
25 namespace HPHP {
26 ///////////////////////////////////////////////////////////////////////////////
28 class SharedValueProfile {
29 private:
30 void init() {
31 key = nullptr;
32 isGroup = false;
33 isPrime = false;
34 isValid = false;
35 totalSize = 0;
36 keySize = 0;
37 keyCount = 0;
38 sizeNoTTL = 0;
39 ttl = 0;
40 fetchCount = 0;
41 lastFetchTime = 0;
42 storeCount = 0;
43 lastStoreTime = 0;
44 deleteCount = 0;
45 lastDeleteTime = 0;
48 public:
49 char *key;
50 SharedVariantStats var;
51 int32_t totalSize;
52 int32_t keySize;
53 bool isGroup;
54 bool isPrime;
55 bool isValid;
56 int32_t keyCount; // valid only for group
57 int32_t sizeNoTTL; // valid only for group
58 int32_t ttl; // valid for both, for group key stats, it's average
59 // Also treat no ttl as 48-hrs.
61 // fetchCount and lastGetTime only valid for individual (so that we don't need
62 // normalize the key for every get)
63 int32_t fetchCount;
64 int32_t storeCount;
65 int32_t deleteCount;
66 time_t lastFetchTime;
67 time_t lastStoreTime;
68 time_t lastDeleteTime;
71 SharedValueProfile() {
72 // For temporary use only
73 init();
76 SharedValueProfile(const char *key) {
77 init();
78 this->key = strdup(key);
79 isGroup = false;
82 ~SharedValueProfile() {
83 if (key) free(key);
86 void calcInd(const StringData *key, const SharedVariant *var);
87 void addToGroup(SharedValueProfile *ind);
88 void removeFromGroup(SharedValueProfile *ind);
91 class SharedStoreStats {
92 public:
93 static void onStore(const StringData *key, const SharedVariant *var,
94 int64_t ttl, bool prime);
95 static void onDelete(const StringData *key, const SharedVariant *var,
96 bool replace, bool noTTL);
97 static void onGet(const StringData *key, const SharedVariant *var);
99 static std::string report_basic();
100 static std::string report_basic_flat();
101 static std::string report_keys();
102 static bool snapshot(const char *filename, std::string& keySample);
104 static void addDirect(int32_t keySize, int32_t dataTotal, bool prime, bool file);
105 static void removeDirect(int32_t keySize, int32_t dataTotal, bool exp);
106 static void updateDirect(int32_t dataTotalOld, int32_t dataTotalNew);
108 static void setExpireQueueSize(int32_t size) {
109 s_expireQueueSize = size;
111 static void addPurgingTime(int64_t purgingTime);
113 protected:
114 static ReadWriteMutex s_rwlock;
116 static std::atomic<int32_t> s_keyCount; // how many distinct keys
117 static std::atomic<int32_t> s_keySize; // how much space these keys take
118 static int32_t s_variantCount; // how many variant
119 static int64_t s_dataSize; // how large is the data
120 static std::atomic<int64_t> s_dataTotalSize; // how much space to hold data
121 // including structures
122 static int64_t s_deleteSize;
123 static int64_t s_replaceSize;
125 static std::atomic<int32_t> s_addCount;
126 static std::atomic<int32_t> s_primeCount;
127 static std::atomic<int32_t> s_fromFileCount;
128 static std::atomic<int32_t> s_updateCount;
129 static std::atomic<int32_t> s_deleteCount;
130 static std::atomic<int32_t> s_expireCount;
132 static int32_t s_expireQueueSize;
133 static std::atomic<int64_t> s_purgingTime;
135 static void remove(SharedValueProfile *svp, bool replace);
136 static void add(SharedValueProfile *svp);
138 struct charHashCompare {
139 bool equal(const char *s1, const char *s2) const {
140 assert(s1 && s2);
141 return strcmp(s1, s2) == 0;
143 size_t hash(const char *s) const {
144 assert(s);
145 return hash_string(s);
149 typedef tbb::concurrent_hash_map<const char*, SharedValueProfile*,
150 charHashCompare> StatsMap;
152 static StatsMap s_statsMap, s_detailMap;
155 ///////////////////////////////////////////////////////////////////////////////
158 #endif /* incl_HPHP_SHARED_STORESTATS_H_ */