Add IOActivityToString helper method (#13440)

Summary:
I have a place I want to use this helper method inside the Sally codebase. I have this functionality in my Sally diff right now, but I think it is generic enough to warrant putting alongside `Env::PriorityToString`.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/13440

Test Plan: Just the compiler and CI checks are sufficient IMO.

Reviewed By: hx235

Differential Revision: D70664597

Pulled By: archang19

fbshipit-source-id: 341de6c6e311a3f421ad093c2c216e5caa5034dd
This commit is contained in:
Andrew Chang 2025-03-05 19:07:01 -08:00 committed by Facebook GitHub Bot
parent 14c949df8b
commit 8e6d431153
2 changed files with 33 additions and 0 deletions

31
env/env.cc vendored
View File

@ -732,6 +732,37 @@ std::string Env::PriorityToString(Env::Priority priority) {
return "Invalid";
}
std::string Env::IOActivityToString(IOActivity activity) {
switch (activity) {
case Env::IOActivity::kFlush:
return "Flush";
case Env::IOActivity::kCompaction:
return "Compaction";
case Env::IOActivity::kDBOpen:
return "DBOpen";
case Env::IOActivity::kGet:
return "Get";
case Env::IOActivity::kMultiGet:
return "MultiGet";
case Env::IOActivity::kDBIterator:
return "DBIterator";
case Env::IOActivity::kVerifyDBChecksum:
return "VerifyDBChecksum";
case Env::IOActivity::kVerifyFileChecksums:
return "VerifyFileChecksums";
case Env::IOActivity::kGetEntity:
return "GetEntity";
case Env::IOActivity::kMultiGetEntity:
return "MultiGetEntity";
case Env::IOActivity::kReadManifest:
return "ReadManifest";
case Env::IOActivity::kUnknown:
return "Unknown";
};
assert(false);
return "Invalid";
}
uint64_t Env::GetThreadID() const {
std::hash<std::thread::id> hasher;
return hasher(std::this_thread::get_id());

View File

@ -459,6 +459,8 @@ class Env : public Customizable {
kUnknown, // Keep last for easy array of non-unknowns
};
static std::string IOActivityToString(IOActivity activity);
// Arrange to run "(*function)(arg)" once in a background thread, in
// the thread pool specified by pri. By default, jobs go to the 'LOW'
// priority thread pool.