Coverage Report

Created: 2026-05-31 07:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/utilities/env_timed.cc
Line
Count
Source
1
// Copyright (c) 2017-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under both the GPLv2 (found in the
3
//  COPYING file in the root directory) and Apache 2.0 License
4
//  (found in the LICENSE.Apache file in the root directory).
5
#include "utilities/env_timed.h"
6
7
#include "env/composite_env_wrapper.h"
8
#include "monitoring/perf_context_imp.h"
9
#include "rocksdb/env.h"
10
#include "rocksdb/file_system.h"
11
#include "rocksdb/status.h"
12
13
namespace ROCKSDB_NAMESPACE {
14
15
TimedFileSystem::TimedFileSystem(const std::shared_ptr<FileSystem>& base)
16
0
    : FileSystemWrapper(base) {}
17
IOStatus TimedFileSystem::NewSequentialFile(
18
    const std::string& fname, const FileOptions& options,
19
0
    std::unique_ptr<FSSequentialFile>* result, IODebugContext* dbg) {
20
0
  PERF_TIMER_GUARD(env_new_sequential_file_nanos);
21
0
  return FileSystemWrapper::NewSequentialFile(fname, options, result, dbg);
22
0
}
23
24
IOStatus TimedFileSystem::NewRandomAccessFile(
25
    const std::string& fname, const FileOptions& options,
26
0
    std::unique_ptr<FSRandomAccessFile>* result, IODebugContext* dbg) {
27
0
  PERF_TIMER_GUARD(env_new_random_access_file_nanos);
28
0
  return FileSystemWrapper::NewRandomAccessFile(fname, options, result, dbg);
29
0
}
30
31
IOStatus TimedFileSystem::NewWritableFile(
32
    const std::string& fname, const FileOptions& options,
33
0
    std::unique_ptr<FSWritableFile>* result, IODebugContext* dbg) {
34
0
  PERF_TIMER_GUARD(env_new_writable_file_nanos);
35
0
  return FileSystemWrapper::NewWritableFile(fname, options, result, dbg);
36
0
}
37
38
IOStatus TimedFileSystem::ReuseWritableFile(
39
    const std::string& fname, const std::string& old_fname,
40
    const FileOptions& options, std::unique_ptr<FSWritableFile>* result,
41
0
    IODebugContext* dbg) {
42
0
  PERF_TIMER_GUARD(env_reuse_writable_file_nanos);
43
0
  return FileSystemWrapper::ReuseWritableFile(fname, old_fname, options, result,
44
0
                                              dbg);
45
0
}
46
47
IOStatus TimedFileSystem::NewRandomRWFile(
48
    const std::string& fname, const FileOptions& options,
49
0
    std::unique_ptr<FSRandomRWFile>* result, IODebugContext* dbg) {
50
0
  PERF_TIMER_GUARD(env_new_random_rw_file_nanos);
51
0
  return FileSystemWrapper::NewRandomRWFile(fname, options, result, dbg);
52
0
}
53
54
IOStatus TimedFileSystem::NewDirectory(const std::string& name,
55
                                       const IOOptions& options,
56
                                       std::unique_ptr<FSDirectory>* result,
57
0
                                       IODebugContext* dbg) {
58
0
  PERF_TIMER_GUARD(env_new_directory_nanos);
59
0
  return FileSystemWrapper::NewDirectory(name, options, result, dbg);
60
0
}
61
62
IOStatus TimedFileSystem::FileExists(const std::string& fname,
63
                                     const IOOptions& options,
64
0
                                     IODebugContext* dbg) {
65
0
  PERF_TIMER_GUARD(env_file_exists_nanos);
66
0
  return FileSystemWrapper::FileExists(fname, options, dbg);
67
0
}
68
69
IOStatus TimedFileSystem::GetChildren(const std::string& dir,
70
                                      const IOOptions& options,
71
                                      std::vector<std::string>* result,
72
0
                                      IODebugContext* dbg) {
73
0
  PERF_TIMER_GUARD(env_get_children_nanos);
74
0
  return FileSystemWrapper::GetChildren(dir, options, result, dbg);
75
0
}
76
77
IOStatus TimedFileSystem::GetChildrenFileAttributes(
78
    const std::string& dir, const IOOptions& options,
79
0
    std::vector<FileAttributes>* result, IODebugContext* dbg) {
80
0
  PERF_TIMER_GUARD(env_get_children_file_attributes_nanos);
81
0
  return FileSystemWrapper::GetChildrenFileAttributes(dir, options, result,
82
0
                                                      dbg);
83
0
}
84
85
IOStatus TimedFileSystem::DeleteFile(const std::string& fname,
86
                                     const IOOptions& options,
87
0
                                     IODebugContext* dbg) {
88
0
  PERF_TIMER_GUARD(env_delete_file_nanos);
89
0
  return FileSystemWrapper::DeleteFile(fname, options, dbg);
90
0
}
91
92
IOStatus TimedFileSystem::CreateDir(const std::string& dirname,
93
                                    const IOOptions& options,
94
0
                                    IODebugContext* dbg) {
95
0
  PERF_TIMER_GUARD(env_create_dir_nanos);
96
0
  return FileSystemWrapper::CreateDir(dirname, options, dbg);
97
0
}
98
99
IOStatus TimedFileSystem::CreateDirIfMissing(const std::string& dirname,
100
                                             const IOOptions& options,
101
0
                                             IODebugContext* dbg) {
102
0
  PERF_TIMER_GUARD(env_create_dir_if_missing_nanos);
103
0
  return FileSystemWrapper::CreateDirIfMissing(dirname, options, dbg);
104
0
}
105
106
IOStatus TimedFileSystem::DeleteDir(const std::string& dirname,
107
                                    const IOOptions& options,
108
0
                                    IODebugContext* dbg) {
109
0
  PERF_TIMER_GUARD(env_delete_dir_nanos);
110
0
  return FileSystemWrapper::DeleteDir(dirname, options, dbg);
111
0
}
112
113
IOStatus TimedFileSystem::GetFileSize(const std::string& fname,
114
                                      const IOOptions& options,
115
                                      uint64_t* file_size,
116
0
                                      IODebugContext* dbg) {
117
0
  PERF_TIMER_GUARD(env_get_file_size_nanos);
118
0
  return FileSystemWrapper::GetFileSize(fname, options, file_size, dbg);
119
0
}
120
121
IOStatus TimedFileSystem::GetFileModificationTime(const std::string& fname,
122
                                                  const IOOptions& options,
123
                                                  uint64_t* file_mtime,
124
0
                                                  IODebugContext* dbg) {
125
0
  PERF_TIMER_GUARD(env_get_file_modification_time_nanos);
126
0
  return FileSystemWrapper::GetFileModificationTime(fname, options, file_mtime,
127
0
                                                    dbg);
128
0
}
129
130
IOStatus TimedFileSystem::RenameFile(const std::string& src,
131
                                     const std::string& dst,
132
                                     const IOOptions& options,
133
0
                                     IODebugContext* dbg) {
134
0
  PERF_TIMER_GUARD(env_rename_file_nanos);
135
0
  return FileSystemWrapper::RenameFile(src, dst, options, dbg);
136
0
}
137
138
IOStatus TimedFileSystem::LinkFile(const std::string& src,
139
                                   const std::string& dst,
140
                                   const IOOptions& options,
141
0
                                   IODebugContext* dbg) {
142
0
  PERF_TIMER_GUARD(env_link_file_nanos);
143
0
  return FileSystemWrapper::LinkFile(src, dst, options, dbg);
144
0
}
145
146
IOStatus TimedFileSystem::LockFile(const std::string& fname,
147
                                   const IOOptions& options, FileLock** lock,
148
0
                                   IODebugContext* dbg) {
149
0
  PERF_TIMER_GUARD(env_lock_file_nanos);
150
0
  return FileSystemWrapper::LockFile(fname, options, lock, dbg);
151
0
}
152
153
IOStatus TimedFileSystem::UnlockFile(FileLock* lock, const IOOptions& options,
154
0
                                     IODebugContext* dbg) {
155
0
  PERF_TIMER_GUARD(env_unlock_file_nanos);
156
0
  return FileSystemWrapper::UnlockFile(lock, options, dbg);
157
0
}
158
159
IOStatus TimedFileSystem::NewLogger(const std::string& fname,
160
                                    const IOOptions& options,
161
                                    std::shared_ptr<Logger>* result,
162
0
                                    IODebugContext* dbg) {
163
0
  PERF_TIMER_GUARD(env_new_logger_nanos);
164
0
  return FileSystemWrapper::NewLogger(fname, options, result, dbg);
165
0
}
166
167
std::shared_ptr<FileSystem> NewTimedFileSystem(
168
0
    const std::shared_ptr<FileSystem>& base) {
169
0
  return std::make_shared<TimedFileSystem>(base);
170
0
}
171
172
// An environment that measures function call times for filesystem
173
// operations, reporting results to variables in PerfContext.
174
0
Env* NewTimedEnv(Env* base_env) {
175
0
  std::shared_ptr<FileSystem> timed_fs =
176
0
      NewTimedFileSystem(base_env->GetFileSystem());
177
0
  return new CompositeEnvWrapper(base_env, timed_fs);
178
0
}
179
180
}  // namespace ROCKSDB_NAMESPACE