Add MemoryLog to LogInterface benchmarks.
GitOrigin-RevId: 5169c7b0d3e376323fd229212b95d17f65487e8f
This commit is contained in:
parent
6bc45e1c2e
commit
dc96827a93
|
@ -8,6 +8,7 @@
|
||||||
#include "td/utils/FileLog.h"
|
#include "td/utils/FileLog.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
#include "td/utils/MemoryLog.h"
|
||||||
#include "td/utils/port/path.h"
|
#include "td/utils/port/path.h"
|
||||||
#include "td/utils/port/thread.h"
|
#include "td/utils/port/thread.h"
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
|
@ -54,13 +55,13 @@ class LogBenchmark : public td::Benchmark {
|
||||||
if (i % 10000 == 0) {
|
if (i % 10000 == 0) {
|
||||||
log_->rotate();
|
log_->rotate();
|
||||||
}
|
}
|
||||||
log_->append(str);
|
log_->append(str, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
td::unique_ptr<Log> log_;
|
td::unique_ptr<td::LogInterface> log_;
|
||||||
int threads_n_{0};
|
int threads_n_{0};
|
||||||
std::function<td::unique_ptr<Log>()> creator_;
|
std::function<td::unique_ptr<Log>()> creator_;
|
||||||
std::vector<td::thread> threads_;
|
std::vector<td::thread> threads_;
|
||||||
|
@ -71,10 +72,13 @@ static void bench_log(std::string name, int threads_n, F &&f) {
|
||||||
bench(LogBenchmark<typename decltype(f())::element_type>(std::move(name), threads_n, std::move(f)));
|
bench(LogBenchmark<typename decltype(f())::element_type>(std::move(name), threads_n, std::move(f)));
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(Log, TsLogger) {
|
TEST(Log, Bench) {
|
||||||
bench_log("NewTsFileLog", 4,
|
bench_log("MemoryLog", 4, [] { return td::make_unique<td::MemoryLog<1 << 20>>(); });
|
||||||
|
|
||||||
|
bench_log("TsFileLog", 4,
|
||||||
[] { return td::TsFileLog::create("tmplog", std::numeric_limits<td::int64>::max(), false).move_as_ok(); });
|
[] { return td::TsFileLog::create("tmplog", std::numeric_limits<td::int64>::max(), false).move_as_ok(); });
|
||||||
bench_log("TsFileLog", 8, [] {
|
|
||||||
|
bench_log("FileLog + TsLog", 8, [] {
|
||||||
class FileLog : public td::LogInterface {
|
class FileLog : public td::LogInterface {
|
||||||
public:
|
public:
|
||||||
FileLog() {
|
FileLog() {
|
||||||
|
@ -83,8 +87,8 @@ TEST(Log, TsLogger) {
|
||||||
}
|
}
|
||||||
~FileLog() {
|
~FileLog() {
|
||||||
}
|
}
|
||||||
void append(td::CSlice slice) override {
|
void append(td::CSlice slice, int log_level) override {
|
||||||
ts_log_.append(slice, -1);
|
ts_log_.append(slice, log_level);
|
||||||
}
|
}
|
||||||
std::vector<std::string> get_file_paths() override {
|
std::vector<std::string> get_file_paths() override {
|
||||||
return file_log_.get_file_paths();
|
return file_log_.get_file_paths();
|
||||||
|
@ -100,7 +104,7 @@ TEST(Log, TsLogger) {
|
||||||
bench_log("noop", 4, [] {
|
bench_log("noop", 4, [] {
|
||||||
class NoopLog : public td::LogInterface {
|
class NoopLog : public td::LogInterface {
|
||||||
public:
|
public:
|
||||||
void append(td::CSlice slice) override {
|
void append(td::CSlice slice, int log_level) override {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return td::make_unique<NoopLog>();
|
return td::make_unique<NoopLog>();
|
||||||
|
@ -114,8 +118,8 @@ TEST(Log, TsLogger) {
|
||||||
}
|
}
|
||||||
~FileLog() {
|
~FileLog() {
|
||||||
}
|
}
|
||||||
void append(td::CSlice slice) override {
|
void append(td::CSlice slice, int log_level) override {
|
||||||
file_log_.append(slice, -1);
|
file_log_.append(slice, log_level);
|
||||||
}
|
}
|
||||||
std::vector<std::string> get_file_paths() override {
|
std::vector<std::string> get_file_paths() override {
|
||||||
return file_log_.get_file_paths();
|
return file_log_.get_file_paths();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user