|
| 1 | +// ------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// perf_count.h: performance counters LevelDB |
| 4 | +// |
| 5 | +// Copyright (c) 2012-2013 Basho Technologies, Inc. All Rights Reserved. |
| 6 | +// |
| 7 | +// This file is provided to you under the Apache License, |
| 8 | +// Version 2.0 (the "License"); you may not use this file |
| 9 | +// except in compliance with the License. You may obtain |
| 10 | +// a copy of the License at |
| 11 | +// |
| 12 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +// |
| 14 | +// Unless required by applicable law or agreed to in writing, |
| 15 | +// software distributed under the License is distributed on an |
| 16 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | +// KIND, either express or implied. See the License for the |
| 18 | +// specific language governing permissions and limitations |
| 19 | +// under the License. |
| 20 | +// |
| 21 | +// ------------------------------------------------------------------- |
| 22 | + |
| 23 | +#ifndef STORAGE_LEVELDB_INCLUDE_PERF_COUNT_H_ |
| 24 | +#define STORAGE_LEVELDB_INCLUDE_PERF_COUNT_H_ |
| 25 | + |
| 26 | +#include "leveldb_terark_config.h" |
| 27 | + |
| 28 | +#include <stdint.h> |
| 29 | +#include <string> |
| 30 | +#include "status.h" |
| 31 | + |
| 32 | +namespace leveldb { |
| 33 | + |
| 34 | +enum SstCountEnum |
| 35 | +{ |
| 36 | + // |
| 37 | + // array index values/names |
| 38 | + // |
| 39 | + eSstCountKeys=0, //!< how many keys in this sst |
| 40 | + eSstCountBlocks=1, //!< how many blocks in this sst |
| 41 | + eSstCountCompressAborted=2,//!< how many blocks attempted compression and aborted use |
| 42 | + eSstCountKeySize=3, //!< byte count of all keys |
| 43 | + eSstCountValueSize=4, //!< byte count of all values |
| 44 | + eSstCountBlockSize=5, //!< byte count of all blocks (pre-compression) |
| 45 | + eSstCountBlockWriteSize=6, //!< post-compression size, or BlockSize if no compression |
| 46 | + eSstCountIndexKeys=7, //!< how many keys in the index block |
| 47 | + eSstCountKeyLargest=8, //!< largest key in sst |
| 48 | + eSstCountKeySmallest=9, //!< smallest key in sst |
| 49 | + eSstCountValueLargest=10, //!< largest value in sst |
| 50 | + eSstCountValueSmallest=11, //!< smallest value in sst |
| 51 | + eSstCountDeleteKey=12, //!< tombstone count |
| 52 | + eSstCountBlockSizeUsed=13, //!< Options::block_size used with this file |
| 53 | + eSstCountUserDataSize=14, //!< post-compression size of non-metadata (user keys/values/block overhead) |
| 54 | + |
| 55 | + // must follow last index name to represent size of array |
| 56 | + eSstCountEnumSize, //!< size of the array described by the enum values |
| 57 | + |
| 58 | + eSstCountVersion=1 |
| 59 | + |
| 60 | +}; // enum SstCountEnum |
| 61 | + |
| 62 | + |
| 63 | +class SstCounters |
| 64 | +{ |
| 65 | +protected: |
| 66 | + bool m_IsReadOnly; //!< set when data decoded from a file |
| 67 | + uint32_t m_Version; //!< object revision identification |
| 68 | + uint32_t m_CounterSize; //!< number of objects in m_Counter |
| 69 | + |
| 70 | + uint64_t m_Counter[eSstCountEnumSize]; |
| 71 | + |
| 72 | +public: |
| 73 | + // constructors / destructor |
| 74 | + SstCounters(); |
| 75 | + |
| 76 | + // Put data into disk form |
| 77 | + void EncodeTo(std::string & Dst) const; |
| 78 | + |
| 79 | + // Populate member data from prior EncodeTo block |
| 80 | + Status DecodeFrom(const Slice& src); |
| 81 | + |
| 82 | + // increment the counter |
| 83 | + uint64_t Inc(unsigned Index); |
| 84 | + |
| 85 | + // add value to the counter |
| 86 | + uint64_t Add(unsigned Index, uint64_t Amount); |
| 87 | + |
| 88 | + // return value of a counter |
| 89 | + uint64_t Value(unsigned Index) const; |
| 90 | + |
| 91 | + // set a value |
| 92 | + void Set(unsigned Index, uint64_t); |
| 93 | + |
| 94 | + // return number of counters |
| 95 | + uint32_t Size() const {return(m_CounterSize);}; |
| 96 | + |
| 97 | + // printf all values |
| 98 | + void Dump() const; |
| 99 | + |
| 100 | +}; // class SstCounters |
| 101 | + |
| 102 | + |
| 103 | +extern struct PerformanceCounters * gPerfCounters; |
| 104 | + |
| 105 | + |
| 106 | +enum PerformanceCountersEnum |
| 107 | +{ |
| 108 | + // |
| 109 | + // array index values/names |
| 110 | + // (enum explicitly numbered to allow future edits / moves / inserts) |
| 111 | + // |
| 112 | + ePerfROFileOpen=0, //!< PosixMmapReadableFile open |
| 113 | + ePerfROFileClose=1, //!< closed |
| 114 | + ePerfROFileUnmap=2, //!< unmap without close |
| 115 | + |
| 116 | + ePerfRWFileOpen=3, //!< PosixMmapFile open |
| 117 | + ePerfRWFileClose=4, //!< closed |
| 118 | + ePerfRWFileUnmap=5, //!< unmap without close |
| 119 | + |
| 120 | + ePerfApiOpen=6, //!< Count of DB::Open completions |
| 121 | + ePerfApiGet=7, //!< Count of DBImpl::Get completions |
| 122 | + ePerfApiWrite=8, //!< Count of DBImpl::Get completions |
| 123 | + |
| 124 | + ePerfWriteSleep=9, //!< DBImpl::MakeRoomForWrite called sleep |
| 125 | + ePerfWriteWaitImm=10, //!< DBImpl::MakeRoomForWrite called Wait on Imm compact |
| 126 | + ePerfWriteWaitLevel0=11,//!< DBImpl::MakeRoomForWrite called Wait on Level0 compact |
| 127 | + ePerfWriteNewMem=12, //!< DBImpl::MakeRoomForWrite created new memory log |
| 128 | + ePerfWriteError=13, //!< DBImpl::MakeRoomForWrite saw bg_error_ |
| 129 | + ePerfWriteNoWait=14, //!< DBImpl::MakeRoomForWrite took no action |
| 130 | + |
| 131 | + ePerfGetMem=15, //!< DBImpl::Get read from memory log |
| 132 | + ePerfGetImm=16, //!< DBImpl::Get read from previous memory log |
| 133 | + ePerfGetVersion=17, //!< DBImpl::Get read from Version object |
| 134 | + |
| 135 | + // code ASSUMES the levels are in numerical order, |
| 136 | + // i.e. based off of ePerfSearchLevel0 |
| 137 | + ePerfSearchLevel0=18, //!< Version::Get read searched one or more files here |
| 138 | + ePerfSearchLevel1=19, //!< Version::Get read searched one or more files here |
| 139 | + ePerfSearchLevel2=20, //!< Version::Get read searched one or more files here |
| 140 | + ePerfSearchLevel3=21, //!< Version::Get read searched one or more files here |
| 141 | + ePerfSearchLevel4=22, //!< Version::Get read searched one or more files here |
| 142 | + ePerfSearchLevel5=23, //!< Version::Get read searched one or more files here |
| 143 | + ePerfSearchLevel6=24, //!< Version::Get read searched one or more files here |
| 144 | + |
| 145 | + ePerfTableCached=25, //!< TableCache::FindTable found table in cache |
| 146 | + ePerfTableOpened=26, //!< TableCache::FindTable had to open table file |
| 147 | + ePerfTableGet=27, //!< TableCache::Get used to retrieve a key |
| 148 | + |
| 149 | + ePerfBGCloseUnmap=28, //!< PosixEnv::BGThreaed started Unmap/Close job |
| 150 | + ePerfBGCompactImm=29, //!< PosixEnv::BGThreaed started compaction of Imm |
| 151 | + ePerfBGNormal=30, //!< PosixEnv::BGThreaed started normal compaction job |
| 152 | + ePerfBGCompactLevel0=31,//!< PosixEnv::BGThreaed started compaction of Level0 |
| 153 | + |
| 154 | + ePerfBlockFiltered=32, //!< Table::BlockReader search stopped due to filter |
| 155 | + ePerfBlockFilterFalse=33,//!< Table::BlockReader gave a false positive for match |
| 156 | + ePerfBlockCached=34, //!< Table::BlockReader found block in cache |
| 157 | + ePerfBlockRead=35, //!< Table::BlockReader read block from disk |
| 158 | + ePerfBlockFilterRead=36,//!< Table::ReadMeta filter loaded from file |
| 159 | + ePerfBlockValidGet=37, //!< Table::InternalGet has valid iterator |
| 160 | + |
| 161 | + ePerfDebug0=38, //!< Developer debug counters, moveable |
| 162 | + ePerfDebug1=39, //!< Developer debug counters, moveable |
| 163 | + ePerfDebug2=40, //!< Developer debug counters, moveable |
| 164 | + ePerfDebug3=41, //!< Developer debug counters, moveable |
| 165 | + ePerfDebug4=42, //!< Developer debug counters, moveable |
| 166 | + |
| 167 | + ePerfReadBlockError=43, //!< crc or compression error in ReadBlock (format.cc) |
| 168 | + |
| 169 | + ePerfIterNew=44, //!< Count of DBImpl::NewDBIterator calls |
| 170 | + ePerfIterNext=45, //!< Count of DBIter::Next calls |
| 171 | + ePerfIterPrev=46, //!< Count of DBIter::Prev calls |
| 172 | + ePerfIterSeek=47, //!< Count of DBIter::Seek calls |
| 173 | + ePerfIterSeekFirst=48, //!< Count of DBIter::SeekFirst calls |
| 174 | + ePerfIterSeekLast=49, //!< Count of DBIter::SeekLast calls |
| 175 | + ePerfIterDelete=50, //!< Count of DBIter::~DBIter |
| 176 | + |
| 177 | + ePerfElevelDirect=51, //!< eleveldb's FindWaitingThread went direct to thread |
| 178 | + ePerfElevelQueued=52, //!< eleveldb's FindWaitingThread queued work item |
| 179 | + ePerfElevelDequeued=53, //!< eleveldb's worker took item from backlog queue |
| 180 | + |
| 181 | + ePerfElevelRefCreate=54,//!< eleveldb RefObject constructed |
| 182 | + ePerfElevelRefDelete=55,//!< eleveldb RefObject destructed |
| 183 | + |
| 184 | + ePerfThrottleGauge=56, //!< current throttle value |
| 185 | + ePerfThrottleCounter=57,//!< running throttle by seconds |
| 186 | + |
| 187 | + ePerfThrottleMicros0=58,//!< level 0 micros spent compacting |
| 188 | + ePerfThrottleKeys0=59, //!< level 0 keys processed |
| 189 | + ePerfThrottleBacklog0=60,//!< backlog at time of posting (level0) |
| 190 | + ePerfThrottleCompacts0=61,//!< number of level 0 compactions |
| 191 | + |
| 192 | + ePerfThrottleMicros1=62,//!< level 1+ micros spent compacting |
| 193 | + ePerfThrottleKeys1=63, //!< level 1+ keys processed |
| 194 | + ePerfThrottleBacklog1=64,//!< backlog at time of posting (level1+) |
| 195 | + ePerfThrottleCompacts1=65,//!< number of level 1+ compactions |
| 196 | + |
| 197 | + ePerfBGWriteError=66, //!< error in write/close, see syslog |
| 198 | + |
| 199 | + ePerfThrottleWait=67, //!< milliseconds of throttle wait |
| 200 | + ePerfThreadError=68, //!< system error on thread related call, no LOG access |
| 201 | + |
| 202 | + ePerfBGImmDirect=69, //!< count Imm compactions happened directly |
| 203 | + ePerfBGImmQueued=70, //!< count Imm compactions placed on queue |
| 204 | + ePerfBGImmDequeued=71, //!< count Imm compactions removed from queue |
| 205 | + ePerfBGImmWeighted=72, //!< total microseconds item spent on queue |
| 206 | + |
| 207 | + ePerfBGUnmapDirect=73, //!< count Unmap operations happened directly |
| 208 | + ePerfBGUnmapQueued=74, //!< count Unmap operations placed on queue |
| 209 | + ePerfBGUnmapDequeued=75,//!< count Unmap operations removed from queue |
| 210 | + ePerfBGUnmapWeighted=76,//!< total microseconds item spent on queue |
| 211 | + |
| 212 | + ePerfBGLevel0Direct=77, //!< count Level0 compactions happened directly |
| 213 | + ePerfBGLevel0Queued=78, //!< count Level0 compactions placed on queue |
| 214 | + ePerfBGLevel0Dequeued=79,//!< count Level0 compactions removed from queue |
| 215 | + ePerfBGLevel0Weighted=80,//!< total microseconds item spent on queue |
| 216 | + |
| 217 | + ePerfBGCompactDirect=81, //!< count generic compactions happened directly |
| 218 | + ePerfBGCompactQueued=82, //!< count generic compactions placed on queue |
| 219 | + ePerfBGCompactDequeued=83,//!< count generic compactions removed from queue |
| 220 | + ePerfBGCompactWeighted=84,//!< total microseconds item spent on queue |
| 221 | + |
| 222 | + ePerfFileCacheInsert=85, //!< total bytes inserted into file cache |
| 223 | + ePerfFileCacheRemove=86, //!< total bytes removed from file cache |
| 224 | + |
| 225 | + ePerfBlockCacheInsert=87, //!< total bytes inserted into block cache |
| 226 | + ePerfBlockCacheRemove=88, //!< total bytes removed from block cache |
| 227 | + |
| 228 | + ePerfApiDelete=89, //!< Count of DB::Delete |
| 229 | + |
| 230 | + // must follow last index name to represent size of array |
| 231 | + // (ASSUMES previous enum is highest value) |
| 232 | + ePerfCountEnumSize, //!< size of the array described by the enum values |
| 233 | + |
| 234 | + ePerfVersion=1, //!< structure versioning |
| 235 | + ePerfKey=41207 //!< random number as shared memory identifier |
| 236 | +}; |
| 237 | + |
| 238 | +// |
| 239 | +// Do NOT use virtual functions. This structure will be aligned at different |
| 240 | +// locations in multiple processes. Things can get messy with virtuals. |
| 241 | + |
| 242 | +struct PerformanceCounters |
| 243 | +{ |
| 244 | +public: |
| 245 | + static int m_LastError; |
| 246 | + |
| 247 | +protected: |
| 248 | + uint32_t m_Version; //!< object revision identification |
| 249 | + uint32_t m_CounterSize; //!< number of objects in m_Counter |
| 250 | + |
| 251 | + volatile uint64_t m_Counter[ePerfCountEnumSize]; |
| 252 | + |
| 253 | + static const char * m_PerfCounterNames[]; |
| 254 | + static int m_PerfSharedId; |
| 255 | + static volatile uint64_t m_BogusCounter; //!< for out of range GetPtr calls |
| 256 | + |
| 257 | +public: |
| 258 | + // only called for local object, not for shared memory |
| 259 | + PerformanceCounters(); |
| 260 | + |
| 261 | + //!< does executable's idea of version match shared object? |
| 262 | + bool VersionTest() |
| 263 | + {return(ePerfCountEnumSize<=m_CounterSize && ePerfVersion==m_Version);}; |
| 264 | + |
| 265 | + //!< mostly for perf_count_test.cc |
| 266 | + void SetVersion(uint32_t Version, uint32_t CounterSize) |
| 267 | + {m_Version=Version; m_CounterSize=CounterSize;}; |
| 268 | + |
| 269 | + static PerformanceCounters * Init(bool IsReadOnly); |
| 270 | + static int Close(PerformanceCounters * Counts); |
| 271 | + |
| 272 | + uint64_t Inc(unsigned Index); |
| 273 | + uint64_t Dec(unsigned Index); |
| 274 | + |
| 275 | + // add value to the counter |
| 276 | + uint64_t Add(unsigned Index, uint64_t Amount); |
| 277 | + |
| 278 | + // return value of a counter |
| 279 | + uint64_t Value(unsigned Index) const; |
| 280 | + |
| 281 | + // set a value |
| 282 | + void Set(unsigned Index, uint64_t); |
| 283 | + |
| 284 | + volatile const uint64_t * GetPtr(unsigned Index) const; |
| 285 | + |
| 286 | + static const char * GetNamePtr(unsigned Index); |
| 287 | + |
| 288 | + int LookupCounter(const char * Name); |
| 289 | + |
| 290 | + void Dump(); |
| 291 | + |
| 292 | +}; // struct PerformanceCounters |
| 293 | + |
| 294 | +extern PerformanceCounters * gPerfCounters; |
| 295 | + |
| 296 | +} // namespace leveldb |
| 297 | + |
| 298 | +#endif // STORAGE_LEVELDB_INCLUDE_PERF_COUNT_H_ |
0 commit comments