forked from OpenAtomFoundation/pikiwidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpika_statistic.h
62 lines (44 loc) · 1.62 KB
/
pika_statistic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2015-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_STATISTIC_H_
#define PIKA_STATISTIC_H_
#include <atomic>
#include <unordered_map>
class QpsStatistic {
public:
QpsStatistic();
QpsStatistic(const QpsStatistic& other);
~QpsStatistic();
void IncreaseQueryNum(bool is_write);
void ResetLastSecQuerynum();
std::atomic<uint64_t> querynum;
std::atomic<uint64_t> write_querynum;
std::atomic<uint64_t> last_querynum;
std::atomic<uint64_t> last_write_querynum;
std::atomic<uint64_t> last_sec_querynum;
std::atomic<uint64_t> last_sec_write_querynum;
std::atomic<uint64_t> last_time_us;
};
struct ServerStatistic {
ServerStatistic();
~ServerStatistic();
std::atomic<uint64_t> accumulative_connections;
std::unordered_map<std::string, std::atomic<uint64_t>> exec_count_table;
QpsStatistic qps;
};
struct Statistic {
Statistic();
QpsStatistic TableStat(const std::string& table_name);
std::unordered_map<std::string, QpsStatistic> AllTableStat();
void UpdateTableQps(
const std::string& table_name, const std::string& command, bool is_write);
void ResetTableLastSecQuerynum();
// statistic shows accumulated data of all tables
ServerStatistic server_stat;
// statistic shows accumulated data of every single table
pthread_rwlock_t table_stat_rw;
std::unordered_map<std::string, QpsStatistic> table_stat;
};
#endif // PIKA_STATISTIC_H_