2017-04-04 18:12:47 +00:00
|
|
|
// Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// 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).
|
2017-04-04 18:12:47 +00:00
|
|
|
|
2017-04-06 02:02:00 +00:00
|
|
|
#include "monitoring/perf_context_imp.h"
|
2017-04-04 18:12:47 +00:00
|
|
|
#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) {}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status NewSequentialFile(const std::string& fname,
|
|
|
|
std::unique_ptr<SequentialFile>* result,
|
|
|
|
const EnvOptions& options) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_new_sequential_file_nanos);
|
|
|
|
return EnvWrapper::NewSequentialFile(fname, result, options);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status NewRandomAccessFile(const std::string& fname,
|
|
|
|
std::unique_ptr<RandomAccessFile>* result,
|
|
|
|
const EnvOptions& options) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_new_random_access_file_nanos);
|
|
|
|
return EnvWrapper::NewRandomAccessFile(fname, result, options);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status NewWritableFile(const std::string& fname,
|
|
|
|
std::unique_ptr<WritableFile>* result,
|
|
|
|
const EnvOptions& options) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_new_writable_file_nanos);
|
|
|
|
return EnvWrapper::NewWritableFile(fname, result, options);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status ReuseWritableFile(const std::string& fname,
|
|
|
|
const std::string& old_fname,
|
|
|
|
std::unique_ptr<WritableFile>* result,
|
|
|
|
const EnvOptions& options) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_reuse_writable_file_nanos);
|
|
|
|
return EnvWrapper::ReuseWritableFile(fname, old_fname, result, options);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status NewRandomRWFile(const std::string& fname,
|
|
|
|
std::unique_ptr<RandomRWFile>* result,
|
|
|
|
const EnvOptions& options) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_new_random_rw_file_nanos);
|
|
|
|
return EnvWrapper::NewRandomRWFile(fname, result, options);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status NewDirectory(const std::string& name,
|
|
|
|
std::unique_ptr<Directory>* result) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_new_directory_nanos);
|
|
|
|
return EnvWrapper::NewDirectory(name, result);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status FileExists(const std::string& fname) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_file_exists_nanos);
|
|
|
|
return EnvWrapper::FileExists(fname);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status GetChildren(const std::string& dir,
|
|
|
|
std::vector<std::string>* result) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_get_children_nanos);
|
|
|
|
return EnvWrapper::GetChildren(dir, result);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status GetChildrenFileAttributes(
|
2017-04-04 18:12:47 +00:00
|
|
|
const std::string& dir, std::vector<FileAttributes>* result) override {
|
|
|
|
PERF_TIMER_GUARD(env_get_children_file_attributes_nanos);
|
|
|
|
return EnvWrapper::GetChildrenFileAttributes(dir, result);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status DeleteFile(const std::string& fname) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_delete_file_nanos);
|
|
|
|
return EnvWrapper::DeleteFile(fname);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status CreateDir(const std::string& dirname) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_create_dir_nanos);
|
|
|
|
return EnvWrapper::CreateDir(dirname);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status CreateDirIfMissing(const std::string& dirname) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_create_dir_if_missing_nanos);
|
|
|
|
return EnvWrapper::CreateDirIfMissing(dirname);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status DeleteDir(const std::string& dirname) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_delete_dir_nanos);
|
|
|
|
return EnvWrapper::DeleteDir(dirname);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status GetFileSize(const std::string& fname, uint64_t* file_size) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_get_file_size_nanos);
|
|
|
|
return EnvWrapper::GetFileSize(fname, file_size);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status GetFileModificationTime(const std::string& fname,
|
|
|
|
uint64_t* file_mtime) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_get_file_modification_time_nanos);
|
|
|
|
return EnvWrapper::GetFileModificationTime(fname, file_mtime);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status RenameFile(const std::string& src, const std::string& dst) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_rename_file_nanos);
|
|
|
|
return EnvWrapper::RenameFile(src, dst);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status LinkFile(const std::string& src, const std::string& dst) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_link_file_nanos);
|
|
|
|
return EnvWrapper::LinkFile(src, dst);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status LockFile(const std::string& fname, FileLock** lock) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_lock_file_nanos);
|
|
|
|
return EnvWrapper::LockFile(fname, lock);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status UnlockFile(FileLock* lock) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
PERF_TIMER_GUARD(env_unlock_file_nanos);
|
|
|
|
return EnvWrapper::UnlockFile(lock);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status NewLogger(const std::string& fname,
|
|
|
|
std::shared_ptr<Logger>* result) override {
|
2017-04-04 18:12:47 +00:00
|
|
|
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
|
|
|
|
|
2018-04-13 00:55:14 +00:00
|
|
|
Env* NewTimedEnv(Env* /*base_env*/) { return nullptr; }
|
2017-04-04 18:12:47 +00:00
|
|
|
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
|
|
|
} // namespace rocksdb
|