|
|
@ -6,6 +6,7 @@ |
|
|
|
#include "rocksdb/utilities/sim_cache.h" |
|
|
|
#include "rocksdb/utilities/sim_cache.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <atomic> |
|
|
|
#include <atomic> |
|
|
|
|
|
|
|
#include <iomanip> |
|
|
|
|
|
|
|
|
|
|
|
#include "file/writable_file_writer.h" |
|
|
|
#include "file/writable_file_writer.h" |
|
|
|
#include "monitoring/statistics.h" |
|
|
|
#include "monitoring/statistics.h" |
|
|
@ -13,7 +14,6 @@ |
|
|
|
#include "rocksdb/env.h" |
|
|
|
#include "rocksdb/env.h" |
|
|
|
#include "rocksdb/file_system.h" |
|
|
|
#include "rocksdb/file_system.h" |
|
|
|
#include "util/mutexlock.h" |
|
|
|
#include "util/mutexlock.h" |
|
|
|
#include "util/string_util.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ROCKSDB_NAMESPACE { |
|
|
|
namespace ROCKSDB_NAMESPACE { |
|
|
|
|
|
|
|
|
|
|
@ -68,11 +68,12 @@ class CacheActivityLogger { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string log_line = "LOOKUP - " + key.ToString(true) + "\n"; |
|
|
|
std::ostringstream oss; |
|
|
|
|
|
|
|
|
|
|
|
// line format: "LOOKUP - <KEY>"
|
|
|
|
// line format: "LOOKUP - <KEY>"
|
|
|
|
|
|
|
|
oss << "LOOKUP - " << key.ToString(true) << std::endl; |
|
|
|
|
|
|
|
|
|
|
|
MutexLock l(&mutex_); |
|
|
|
MutexLock l(&mutex_); |
|
|
|
Status s = file_writer_->Append(log_line); |
|
|
|
Status s = file_writer_->Append(oss.str()); |
|
|
|
if (!s.ok() && bg_status_.ok()) { |
|
|
|
if (!s.ok() && bg_status_.ok()) { |
|
|
|
bg_status_ = s; |
|
|
|
bg_status_ = s; |
|
|
|
} |
|
|
|
} |
|
|
@ -88,15 +89,11 @@ class CacheActivityLogger { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string log_line = "ADD - "; |
|
|
|
std::ostringstream oss; |
|
|
|
log_line += key.ToString(true); |
|
|
|
|
|
|
|
log_line += " - "; |
|
|
|
|
|
|
|
AppendNumberTo(&log_line, size); |
|
|
|
|
|
|
|
log_line += "\n"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// line format: "ADD - <KEY> - <KEY-SIZE>"
|
|
|
|
// line format: "ADD - <KEY> - <KEY-SIZE>"
|
|
|
|
|
|
|
|
oss << "ADD - " << key.ToString(true) << " - " << size << std::endl; |
|
|
|
MutexLock l(&mutex_); |
|
|
|
MutexLock l(&mutex_); |
|
|
|
Status s = file_writer_->Append(log_line); |
|
|
|
Status s = file_writer_->Append(oss.str()); |
|
|
|
if (!s.ok() && bg_status_.ok()) { |
|
|
|
if (!s.ok() && bg_status_.ok()) { |
|
|
|
bg_status_ = s; |
|
|
|
bg_status_ = s; |
|
|
|
} |
|
|
|
} |
|
|
@ -298,25 +295,23 @@ class SimCacheImpl : public SimCache { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string ToString() const override { |
|
|
|
std::string ToString() const override { |
|
|
|
std::string res; |
|
|
|
std::ostringstream oss; |
|
|
|
res.append("SimCache MISSes: " + std::to_string(get_miss_counter()) + "\n"); |
|
|
|
oss << "SimCache MISSes: " << get_miss_counter() << std::endl; |
|
|
|
res.append("SimCache HITs: " + std::to_string(get_hit_counter()) + "\n"); |
|
|
|
oss << "SimCache HITs: " << get_hit_counter() << std::endl; |
|
|
|
char buff[350]; |
|
|
|
|
|
|
|
auto lookups = get_miss_counter() + get_hit_counter(); |
|
|
|
auto lookups = get_miss_counter() + get_hit_counter(); |
|
|
|
snprintf(buff, sizeof(buff), "SimCache HITRATE: %.2f%%\n", |
|
|
|
oss << "SimCache HITRATE: " << std::fixed << std::setprecision(2) |
|
|
|
(lookups == 0 ? 0 : get_hit_counter() * 100.0f / lookups)); |
|
|
|
<< (lookups == 0 ? 0 : get_hit_counter() * 100.0f / lookups) |
|
|
|
res.append(buff); |
|
|
|
<< std::endl; |
|
|
|
return res; |
|
|
|
return oss.str(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string GetPrintableOptions() const override { |
|
|
|
std::string GetPrintableOptions() const override { |
|
|
|
std::string ret; |
|
|
|
std::ostringstream oss; |
|
|
|
ret.reserve(20000); |
|
|
|
oss << " cache_options:" << std::endl; |
|
|
|
ret.append(" cache_options:\n"); |
|
|
|
oss << cache_->GetPrintableOptions(); |
|
|
|
ret.append(cache_->GetPrintableOptions()); |
|
|
|
oss << " sim_cache_options:" << std::endl; |
|
|
|
ret.append(" sim_cache_options:\n"); |
|
|
|
oss << key_only_cache_->GetPrintableOptions(); |
|
|
|
ret.append(key_only_cache_->GetPrintableOptions()); |
|
|
|
return oss.str(); |
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Status StartActivityLogging(const std::string& activity_log_file, Env* env, |
|
|
|
Status StartActivityLogging(const std::string& activity_log_file, Env* env, |
|
|
|