2 +----------------------------------------------------------------------+
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"
26 ///////////////////////////////////////////////////////////////////////////////
28 class SharedValueProfile
{
50 SharedVariantStats var
;
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)
68 time_t lastDeleteTime
;
71 SharedValueProfile() {
72 // For temporary use only
76 SharedValueProfile(const char *key
) {
78 this->key
= strdup(key
);
82 ~SharedValueProfile() {
86 void calcInd(const StringData
*key
, const SharedVariant
*var
);
87 void addToGroup(SharedValueProfile
*ind
);
88 void removeFromGroup(SharedValueProfile
*ind
);
91 class SharedStoreStats
{
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
);
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 {
141 return strcmp(s1
, s2
) == 0;
143 size_t hash(const char *s
) const {
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_ */