forked from facebook/rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_timed.cc
148 lines (119 loc) · 5.42 KB
/
env_timed.cc
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#include "monitoring/perf_context_imp.h"
#include "rocksdb/env.h"
#include "rocksdb/status.h"
namespace rocksdb {
#ifndef ROCKSDB_LITE
// An environment that measures function call times for filesystem
// operations, reporting results to variables in PerfContext.
class TimedEnv : public EnvWrapper {
public:
explicit TimedEnv(Env* base_env) : EnvWrapper(base_env) {}
virtual Status NewSequentialFile(const std::string& fname,
std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override {
PERF_TIMER_GUARD(env_new_sequential_file_nanos);
return EnvWrapper::NewSequentialFile(fname, result, options);
}
virtual Status NewRandomAccessFile(const std::string& fname,
std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override {
PERF_TIMER_GUARD(env_new_random_access_file_nanos);
return EnvWrapper::NewRandomAccessFile(fname, result, options);
}
virtual Status NewWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
PERF_TIMER_GUARD(env_new_writable_file_nanos);
return EnvWrapper::NewWritableFile(fname, result, options);
}
virtual Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
PERF_TIMER_GUARD(env_reuse_writable_file_nanos);
return EnvWrapper::ReuseWritableFile(fname, old_fname, result, options);
}
virtual Status NewRandomRWFile(const std::string& fname,
std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override {
PERF_TIMER_GUARD(env_new_random_rw_file_nanos);
return EnvWrapper::NewRandomRWFile(fname, result, options);
}
virtual Status NewDirectory(const std::string& name,
std::unique_ptr<Directory>* result) override {
PERF_TIMER_GUARD(env_new_directory_nanos);
return EnvWrapper::NewDirectory(name, result);
}
virtual Status FileExists(const std::string& fname) override {
PERF_TIMER_GUARD(env_file_exists_nanos);
return EnvWrapper::FileExists(fname);
}
virtual Status GetChildren(const std::string& dir,
std::vector<std::string>* result) override {
PERF_TIMER_GUARD(env_get_children_nanos);
return EnvWrapper::GetChildren(dir, result);
}
virtual Status GetChildrenFileAttributes(
const std::string& dir, std::vector<FileAttributes>* result) override {
PERF_TIMER_GUARD(env_get_children_file_attributes_nanos);
return EnvWrapper::GetChildrenFileAttributes(dir, result);
}
virtual Status DeleteFile(const std::string& fname) override {
PERF_TIMER_GUARD(env_delete_file_nanos);
return EnvWrapper::DeleteFile(fname);
}
virtual Status CreateDir(const std::string& dirname) override {
PERF_TIMER_GUARD(env_create_dir_nanos);
return EnvWrapper::CreateDir(dirname);
}
virtual Status CreateDirIfMissing(const std::string& dirname) override {
PERF_TIMER_GUARD(env_create_dir_if_missing_nanos);
return EnvWrapper::CreateDirIfMissing(dirname);
}
virtual Status DeleteDir(const std::string& dirname) override {
PERF_TIMER_GUARD(env_delete_dir_nanos);
return EnvWrapper::DeleteDir(dirname);
}
virtual Status GetFileSize(const std::string& fname,
uint64_t* file_size) override {
PERF_TIMER_GUARD(env_get_file_size_nanos);
return EnvWrapper::GetFileSize(fname, file_size);
}
virtual Status GetFileModificationTime(const std::string& fname,
uint64_t* file_mtime) override {
PERF_TIMER_GUARD(env_get_file_modification_time_nanos);
return EnvWrapper::GetFileModificationTime(fname, file_mtime);
}
virtual Status RenameFile(const std::string& src,
const std::string& dst) override {
PERF_TIMER_GUARD(env_rename_file_nanos);
return EnvWrapper::RenameFile(src, dst);
}
virtual Status LinkFile(const std::string& src,
const std::string& dst) override {
PERF_TIMER_GUARD(env_link_file_nanos);
return EnvWrapper::LinkFile(src, dst);
}
virtual Status LockFile(const std::string& fname, FileLock** lock) override {
PERF_TIMER_GUARD(env_lock_file_nanos);
return EnvWrapper::LockFile(fname, lock);
}
virtual Status UnlockFile(FileLock* lock) override {
PERF_TIMER_GUARD(env_unlock_file_nanos);
return EnvWrapper::UnlockFile(lock);
}
virtual Status NewLogger(const std::string& fname,
std::shared_ptr<Logger>* result) override {
PERF_TIMER_GUARD(env_new_logger_nanos);
return EnvWrapper::NewLogger(fname, result);
}
};
Env* NewTimedEnv(Env* base_env) { return new TimedEnv(base_env); }
#else // ROCKSDB_LITE
Env* NewTimedEnv(Env* /*base_env*/) { return nullptr; }
#endif // !ROCKSDB_LITE
} // namespace rocksdb