forked from dingodb/dingo-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracker.h
More file actions
125 lines (94 loc) · 5.29 KB
/
Copy pathtracker.h
File metadata and controls
125 lines (94 loc) · 5.29 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (c) 2023 dingodb.com, Inc. All Rights Reserved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DINGODB_SDK_TRACKER_H_
#define DINGODB_SDK_TRACKER_H_
#include <cstdint>
#include <memory>
#include <string>
#include "sdk/common/helper.h"
namespace dingodb {
namespace sdk {
class Tracker {
public:
Tracker() : start_time_(TimestampUs()) {}
~Tracker() = default;
static std::shared_ptr<Tracker> New() { return std::make_shared<Tracker>(); }
struct Metrics {
std::atomic<uint64_t> total_transaction_time_us{0};
std::atomic<uint64_t> prewrite_sdk_time_us{0};
std::atomic<uint64_t> prewrite_rpc_time_us{0};
std::atomic<uint64_t> prewrite_retry_count{0};
std::atomic<uint64_t> prewrite_rpc_retry_count{0};
std::atomic<uint64_t> commit_sdk_time_us{0};
std::atomic<uint64_t> commit_rpc_time_us{0};
std::atomic<uint64_t> commit_retry_count{0};
std::atomic<uint64_t> commit_rpc_retry_count{0};
std::atomic<uint64_t> read_sdk_time_us{0};
std::atomic<uint64_t> read_rpc_time_us{0};
std::atomic<uint64_t> read_retry_count{0};
std::atomic<uint64_t> read_rpc_retry_count{0};
std::atomic<uint64_t> resolve_lock_time_us{0};
std::atomic<uint64_t> sleep_time_us{0};
std::atomic<uint64_t> sleep_count{0};
std::atomic<uint64_t> tso_time_us{0};
std::atomic<uint64_t> tso_count{0};
};
void SetTotalTransactionTime() { metrics_.total_transaction_time_us.store(TimestampUs() - start_time_); }
uint64_t TotalTransactionTime() const { return metrics_.total_transaction_time_us.load(); }
void IncrementPrewriteSdkTime(uint64_t elapsed_time) { metrics_.prewrite_sdk_time_us.fetch_add(elapsed_time); }
uint64_t PrewriteSdkTime() const { return metrics_.prewrite_sdk_time_us.load(); }
void IncrementPrewriteRpcTime(uint64_t elapsed_time) { metrics_.prewrite_rpc_time_us.fetch_add(elapsed_time); }
uint64_t PrewriteRpcTime() const { return metrics_.prewrite_rpc_time_us.load(); }
void IncrementPrewriteRetryCount(uint64_t retry_count) { metrics_.prewrite_retry_count.fetch_add(retry_count); }
uint64_t PrewriteRetryCount() const { return metrics_.prewrite_retry_count.load(); }
void IncrementPrewriteRpcRetryCount(uint64_t retry_count) {
metrics_.prewrite_rpc_retry_count.fetch_add(retry_count);
}
uint64_t PrewriteRpcRetryCount() const { return metrics_.prewrite_rpc_retry_count.load(); }
void IncrementCommitSdkTime(uint64_t elapsed_time) { metrics_.commit_sdk_time_us.fetch_add(elapsed_time); }
uint64_t CommitSdkTime() const { return metrics_.commit_sdk_time_us.load(); }
void IncrementCommitRpcTime(uint64_t elapsed_time) { metrics_.commit_rpc_time_us.fetch_add(elapsed_time); }
uint64_t CommitRpcTime() const { return metrics_.commit_rpc_time_us.load(); }
void IncrementCommitRetryCount(uint64_t retry_count) { metrics_.commit_retry_count.fetch_add(retry_count); }
uint64_t CommitRetryCount() const { return metrics_.commit_retry_count.load(); }
void IncrementCommitRpcRetryCount(uint64_t retry_count) { metrics_.commit_rpc_retry_count.fetch_add(retry_count); }
uint64_t CommitRpcRetryCount() const { return metrics_.commit_rpc_retry_count.load(); }
void IncrementReadSdkTime(uint64_t elapsed_time) { metrics_.read_sdk_time_us.fetch_add(elapsed_time); }
uint64_t ReadSdkTime() const { return metrics_.read_sdk_time_us.load(); }
void IncrementReadRpcTime(uint64_t elapsed_time) { metrics_.read_rpc_time_us.fetch_add(elapsed_time); }
uint64_t ReadRpcTime() const { return metrics_.read_rpc_time_us.load(); }
void IncrementReadRetryCount(uint64_t retry_count) { metrics_.read_retry_count.fetch_add(retry_count); }
uint64_t ReadRetryCount() const { return metrics_.read_retry_count.load(); }
void IncrementReadRpcRetryCount(uint64_t retry_count) { metrics_.read_rpc_retry_count.fetch_add(retry_count); }
uint64_t ReadRpcRetryCount() const { return metrics_.read_rpc_retry_count.load(); }
void IncrementResolveLockTime(uint64_t elapsed_time) { metrics_.resolve_lock_time_us.fetch_add(elapsed_time); }
uint64_t ResolveLockSdkTime() const { return metrics_.resolve_lock_time_us.load(); }
void IncrementSleepTime(uint64_t sleep_time_us) { metrics_.sleep_time_us.fetch_add(sleep_time_us); }
uint64_t SleepTime() const { return metrics_.sleep_time_us.load(); }
void IncrementSleepCount(uint64_t count) { metrics_.sleep_count.fetch_add(count); }
uint64_t SleepTimeCount() const { return metrics_.sleep_count.load(); }
void IncrementTsoTime(uint64_t elapsed_time) {
metrics_.tso_time_us.fetch_add(elapsed_time);
metrics_.tso_count.fetch_add(1);
}
uint64_t TsoTime() const { return metrics_.tso_time_us.load(); }
uint64_t TsoCount() const { return metrics_.tso_count.load(); }
private:
uint64_t start_time_;
Metrics metrics_;
};
using TrackerPtr = std::shared_ptr<Tracker>;
} // namespace sdk
} // namespace dingodb
#endif