Optimize logging to NULL on Windows. Fixes #2112.
It is possible to do only about 100 writes to NULL per second, which is about 8-80 times less than even performance of writes to a console app.
This commit is contained in:
parent
10680fe353
commit
628b8901bc
@ -46,9 +46,11 @@ static FileFd &get_file_fd() {
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
|
||||
static auto handle = GetStdHandle(id);
|
||||
LOG_IF(FATAL, handle == INVALID_HANDLE_VALUE) << "Failed to GetStdHandle " << id;
|
||||
static FileFd result = FileFd::from_native_fd(NativeFd(handle, true));
|
||||
static FileFd result = handle == nullptr ? FileFd() : FileFd::from_native_fd(NativeFd(handle, true));
|
||||
static auto guard = ScopeExit() + [&] {
|
||||
result.move_as_native_fd().release();
|
||||
if (handle != nullptr) {
|
||||
result.move_as_native_fd().release();
|
||||
}
|
||||
};
|
||||
#else
|
||||
static FileFd result;
|
||||
|
@ -43,6 +43,9 @@ class LogBenchmark final : public td::Benchmark {
|
||||
threads_.resize(threads_n_);
|
||||
}
|
||||
void tear_down() final {
|
||||
if (log_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (const auto &path : log_->get_file_paths()) {
|
||||
td::unlink(path).ignore();
|
||||
}
|
||||
@ -50,7 +53,9 @@ class LogBenchmark final : public td::Benchmark {
|
||||
}
|
||||
void run(int n) final {
|
||||
auto old_log_interface = td::log_interface;
|
||||
td::log_interface = log_.get();
|
||||
if (log_ != nullptr) {
|
||||
td::log_interface = log_.get();
|
||||
}
|
||||
|
||||
for (auto &thread : threads_) {
|
||||
thread = td::thread([this, n] { this->run_thread(n); });
|
||||
@ -65,7 +70,7 @@ class LogBenchmark final : public td::Benchmark {
|
||||
void run_thread(int n) {
|
||||
auto str = PSTRING() << "#" << n << " : fsjklfdjsklfjdsklfjdksl\n";
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (i % 10000 == 0) {
|
||||
if (i % 10000 == 0 && log_ != nullptr) {
|
||||
log_->after_rotation();
|
||||
}
|
||||
if (test_full_logging_) {
|
||||
@ -97,6 +102,8 @@ static void bench_log(std::string name, F &&f) {
|
||||
TEST(Log, Bench) {
|
||||
bench_log("NullLog", [] { return td::make_unique<td::NullLog>(); });
|
||||
|
||||
// bench_log("Default", []() -> td::unique_ptr<td::NullLog> { return nullptr; });
|
||||
|
||||
bench_log("MemoryLog", [] { return td::make_unique<td::MemoryLog<1 << 20>>(); });
|
||||
|
||||
bench_log("CombinedLogEmpty", [] { return td::make_unique<td::CombinedLog>(); });
|
||||
|
Loading…
Reference in New Issue
Block a user