Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gabime/spdlog.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgabime <gmelman1@gmail.com>2018-05-19 14:41:53 +0300
committergabime <gmelman1@gmail.com>2018-05-20 18:10:29 +0300
commit5c38e15dd21541b21fd719f5bfd2858623a6b5e3 (patch)
tree9379b3415d732a93d6b567213aacf7b866401b90
parent0e86c4eed0ef1d2605771c7cf9d9ac6e5afb07b2 (diff)
replaced the lockfree queue with bounded, locked queue
-rw-r--r--example/bench.cpp33
-rw-r--r--include/spdlog/sinks/test_sink.h39
2 files changed, 23 insertions, 49 deletions
diff --git a/example/bench.cpp b/example/bench.cpp
index 49385e0f..d92e20bc 100644
--- a/example/bench.cpp
+++ b/example/bench.cpp
@@ -7,8 +7,7 @@
// bench.cpp : spdlog benchmarks
//
#include "spdlog/async_logger.h"
-#include "spdlog/sinks/file_sinks.h"
-#include "spdlog/sinks/null_sink.h"
+#include "spdlog/sinks/test_sink.h"
#include "spdlog/spdlog.h"
#include "utils.h"
#include <atomic>
@@ -30,12 +29,10 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
int main(int argc, char *argv[])
{
- int queue_size = 1048576;
+ int queue_size = 1024*1024;
int howmany = 1000000;
int threads = 10;
- int file_size = 30 * 1024 * 1024;
- int rotating_files = 5;
-
+
try
{
@@ -45,7 +42,7 @@ int main(int argc, char *argv[])
threads = atoi(argv[2]);
if (argc > 3)
queue_size = atoi(argv[3]);
-
+ /*
cout << "*******************************************************************************\n";
cout << "Single thread, " << format(howmany) << " iterations" << endl;
cout << "*******************************************************************************\n";
@@ -67,17 +64,32 @@ int main(int argc, char *argv[])
bench_mt(howmany, daily_mt, threads);
bench(howmany, spdlog::create<null_sink_st>("null_mt"));
+ */
+
cout << "\n*******************************************************************************\n";
cout << "async logging.. " << threads << " threads sharing same logger, " << format(howmany) << " iterations " << endl;
cout << "*******************************************************************************\n";
spdlog::set_async_mode(queue_size);
- for (int i = 0; i < 3; ++i)
+
+ for (int i = 0; i < 300; ++i)
{
- auto as = spdlog::daily_logger_st("as", "logs/daily_async.log");
- bench_mt(howmany, as, threads);
+ //auto as = spdlog::daily_logger_mt("as", "logs/daily_async.log");
+ auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
+ //auto as = spdlog::basic_logger_mt("as", "logs/async.log", true);
+ auto as = std::make_shared<spdlog::async_logger>("as", test_sink, queue_size, async_overflow_policy::block_retry, nullptr, std::chrono::milliseconds(2000));
+ bench_mt(howmany, as, threads);
+ as.reset();
spdlog::drop("as");
+
+ auto msg_counter = test_sink->msg_counter();
+ cout << "Count:" << msg_counter << endl;
+ if (msg_counter != howmany)
+ {
+ cout << "ERROR! Expected " << howmany;
+ exit(0);
+ }
}
}
catch (std::exception &ex)
@@ -119,6 +131,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
if (counter > howmany)
break;
log->info("Hello logger: msg number {}", counter);
+ //std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}));
}
diff --git a/include/spdlog/sinks/test_sink.h b/include/spdlog/sinks/test_sink.h
deleted file mode 100644
index f25654cd..00000000
--- a/include/spdlog/sinks/test_sink.h
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-// Copyright(c) 2015 Gabi Melman.
-// Distributed under the MIT License (http://opensource.org/licenses/MIT)
-//
-
-#pragma once
-
-#include "../details/null_mutex.h"
-#include "base_sink.h"
-
-#include <mutex>
-
-namespace spdlog {
-namespace sinks {
-
-template<class Mutex>
-class test_sink : public base_sink<Mutex>
-{
-public:
- size_t msg_counter()
- {
- return msg_counter_;
- }
-
-protected:
- void _sink_it(const details::log_msg &) override
- {
- msg_counter_++;
- }
-
- void _flush() override {}
- size_t msg_counter_{0};
-};
-
-using test_sink_mt = test_sink<std::mutex>;
-using test_sink_st = test_sink<details::null_mutex>;
-
-} // namespace sinks
-} // namespace spdlog