-
Notifications
You must be signed in to change notification settings - Fork 7
/
stat.h
68 lines (57 loc) · 1.71 KB
/
stat.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
62
63
64
65
66
67
68
#pragma once
#include "common.h"
class Stat {
public:
Stat() { reset_all(); }
void reset() {
read_count_ = 0;
read_bytes_ = 0;
write_count_ = 0;
write_bytes_ = 0;
delete_count_ = 0;
delete_bytes_ = 0;
}
void reset_all() {
reset();
current_bytes_ = 0;
}
void read(uint64_t num_bytes) {
read_count_++;
read_bytes_ += static_cast<int64_t>(num_bytes);
}
void write(uint64_t num_bytes) {
write_count_++;
write_bytes_ += static_cast<int64_t>(num_bytes);
current_bytes_ += static_cast<int64_t>(num_bytes);
}
void overwrite(uint64_t num_bytes) {
write_count_++;
write_bytes_ += static_cast<int64_t>(num_bytes);
}
void del(uint64_t num_bytes) {
delete_count_++;
delete_bytes_ += static_cast<int64_t>(num_bytes);
current_bytes_ -= static_cast<int64_t>(num_bytes);
}
int64_t read_count() const { return read_count_; }
int64_t read_bytes() const { return read_bytes_; }
int64_t write_count() const { return write_count_; }
int64_t write_bytes() const { return write_bytes_; }
int64_t delete_count() const { return delete_count_; }
int64_t delete_bytes() const { return delete_bytes_; }
int64_t current_bytes() const { return current_bytes_; }
void print_status() const {
printf("Read: %ld times, %ld bytes\n", read_count_, read_bytes_);
printf("Write: %ld times, %ld bytes\n", write_count_, write_bytes_);
printf("Delete: %ld times, %ld bytes\n", delete_count_, delete_bytes_);
printf("Current size: %ld bytes\n", current_bytes_);
}
private:
int64_t read_count_;
int64_t read_bytes_;
int64_t write_count_;
int64_t write_bytes_;
int64_t delete_count_;
int64_t delete_bytes_;
int64_t current_bytes_;
};