summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/log/test/performance
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/log/test/performance
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/log/test/performance')
-rw-r--r--src/boost/libs/log/test/performance/Jamfile.v215
-rw-r--r--src/boost/libs/log/test/performance/dump.cpp76
-rw-r--r--src/boost/libs/log/test/performance/record_emission.cpp132
3 files changed, 223 insertions, 0 deletions
diff --git a/src/boost/libs/log/test/performance/Jamfile.v2 b/src/boost/libs/log/test/performance/Jamfile.v2
new file mode 100644
index 00000000..036ed6e0
--- /dev/null
+++ b/src/boost/libs/log/test/performance/Jamfile.v2
@@ -0,0 +1,15 @@
+#
+# Copyright Andrey Semashev 2007 - 2015.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+#
+
+exe record_emission
+ : record_emission.cpp ../../build//boost_log
+ ;
+
+exe dump
+ : dump.cpp ../../build//boost_log
+ ;
+
diff --git a/src/boost/libs/log/test/performance/dump.cpp b/src/boost/libs/log/test/performance/dump.cpp
new file mode 100644
index 00000000..b19b161a
--- /dev/null
+++ b/src/boost/libs/log/test/performance/dump.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright Andrey Semashev 2007 - 2015.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ */
+/*!
+ * \file dump.cpp
+ * \author Andrey Semashev
+ * \date 05.05.2013
+ *
+ * \brief This code measures performance dumping binary data
+ */
+
+#include <cstdlib>
+#include <iomanip>
+#include <string>
+#include <vector>
+#include <iostream>
+#include <algorithm>
+
+#include <boost/cstdint.hpp>
+#include <boost/date_time/microsec_time_clock.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+
+#include <boost/log/utility/formatting_ostream.hpp>
+#include <boost/log/utility/manipulators/dump.hpp>
+
+namespace logging = boost::log;
+
+const unsigned int base_loop_count = 10000;
+
+void test(std::size_t block_size)
+{
+ std::cout << "Block size: " << block_size << " bytes.";
+
+ std::vector< boost::uint8_t > data;
+ data.resize(block_size);
+ std::generate_n(data.begin(), block_size, &std::rand);
+
+ std::string str;
+ logging::formatting_ostream strm(str);
+
+ const boost::uint8_t* const p = &data[0];
+
+ boost::uint64_t data_processed = 0, duration = 0;
+ boost::posix_time::ptime start, end;
+ start = boost::date_time::microsec_clock< boost::posix_time::ptime >::universal_time();
+ do
+ {
+ for (unsigned int i = 0; i < base_loop_count; ++i)
+ {
+ strm << logging::dump(p, block_size);
+ str.clear();
+ }
+ end = boost::date_time::microsec_clock< boost::posix_time::ptime >::universal_time();
+ data_processed += base_loop_count * block_size;
+ duration = (end - start).total_microseconds();
+ }
+ while (duration < 2000000);
+
+ std::cout << " Test duration: " << duration << " us ("
+ << std::fixed << std::setprecision(3) << static_cast< double >(data_processed) / (static_cast< double >(duration) * (1048576.0 / 1000000.0))
+ << " MiB per second)" << std::endl;
+}
+
+int main(int argc, char* argv[])
+{
+ test(32);
+ test(128);
+ test(1024);
+ test(16384);
+ test(1048576);
+
+ return 0;
+}
diff --git a/src/boost/libs/log/test/performance/record_emission.cpp b/src/boost/libs/log/test/performance/record_emission.cpp
new file mode 100644
index 00000000..8657091c
--- /dev/null
+++ b/src/boost/libs/log/test/performance/record_emission.cpp
@@ -0,0 +1,132 @@
+/*
+ * Copyright Andrey Semashev 2007 - 2015.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ */
+/*!
+ * \file record_emission.cpp
+ * \author Andrey Semashev
+ * \date 22.03.2009
+ *
+ * \brief This code measures performance of log record emission
+ */
+
+// #define BOOST_LOG_USE_CHAR
+// #define BOOST_ALL_DYN_LINK 1
+// #define BOOST_LOG_DYN_LINK 1
+#define BOOST_NO_DYN_LINK 1
+
+#include <iomanip>
+#include <iostream>
+#include <boost/ref.hpp>
+#include <boost/bind.hpp>
+#include <boost/smart_ptr/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared_object.hpp>
+#include <boost/date_time/microsec_time_clock.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/barrier.hpp>
+
+#include <boost/log/core.hpp>
+#include <boost/log/common.hpp>
+#include <boost/log/attributes.hpp>
+#include <boost/log/sinks.hpp>
+#include <boost/log/sinks/basic_sink_backend.hpp>
+#include <boost/log/sources/logger.hpp>
+
+#include <boost/log/expressions.hpp>
+
+#include <boost/log/attributes/scoped_attribute.hpp>
+
+enum config
+{
+ RECORD_COUNT = 20000000,
+ THREAD_COUNT = 8,
+ SINK_COUNT = 3
+};
+
+namespace logging = boost::log;
+namespace expr = boost::log::expressions;
+namespace sinks = boost::log::sinks;
+namespace attrs = boost::log::attributes;
+namespace src = boost::log::sources;
+namespace keywords = boost::log::keywords;
+
+enum severity_level
+{
+ normal,
+ warning,
+ error
+};
+
+BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", severity_level)
+
+namespace {
+
+ //! A fake sink backend that receives log records
+ class fake_backend :
+ public sinks::basic_sink_backend< sinks::concurrent_feeding >
+ {
+ public:
+ void consume(logging::record_view const& rec)
+ {
+ }
+ };
+
+} // namespace
+
+void test(unsigned int record_count, boost::barrier& bar)
+{
+ BOOST_LOG_SCOPED_THREAD_TAG("ThreadID", boost::this_thread::get_id());
+ src::severity_logger< severity_level > slg;
+// src::logger lg;
+ bar.wait();
+
+ for (unsigned int i = 0; i < record_count; ++i)
+ {
+ BOOST_LOG_SEV(slg, warning) << "Test record";
+// BOOST_LOG(lg) << "Test record";
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ std::cout << "Test config: " << THREAD_COUNT << " threads, " << SINK_COUNT << " sinks, " << RECORD_COUNT << " records" << std::endl;
+//__debugbreak();
+// typedef sinks::unlocked_sink< fake_backend > fake_sink;
+// typedef sinks::synchronous_sink< fake_backend > fake_sink;
+ typedef sinks::asynchronous_sink< fake_backend > fake_sink;
+ for (unsigned int i = 0; i < SINK_COUNT; ++i)
+ logging::core::get()->add_sink(boost::make_shared< fake_sink >());
+
+ logging::core::get()->add_global_attribute("LineID", attrs::counter< unsigned int >(1));
+ logging::core::get()->add_global_attribute("TimeStamp", attrs::local_clock());
+ logging::core::get()->add_global_attribute("Scope", attrs::named_scope());
+
+// logging::core::get()->set_filter(severity > normal); // all records pass the filter
+// logging::core::get()->set_filter(severity > error); // all records don't pass the filter
+
+// logging::core::get()->set_filter(severity > error); // all records don't pass the filter
+
+ const unsigned int record_count = RECORD_COUNT / THREAD_COUNT;
+ boost::barrier bar(THREAD_COUNT);
+ boost::thread_group threads;
+
+ for (unsigned int i = 1; i < THREAD_COUNT; ++i)
+ threads.create_thread(boost::bind(&test, record_count, boost::ref(bar)));
+
+ boost::posix_time::ptime start = boost::date_time::microsec_clock< boost::posix_time::ptime >::universal_time(), end;
+ test(record_count, bar);
+ if (THREAD_COUNT > 1)
+ threads.join_all();
+ end = boost::date_time::microsec_clock< boost::posix_time::ptime >::universal_time();
+
+ unsigned long long duration = (end - start).total_microseconds();
+
+ std::cout << "Test duration: " << duration << " us ("
+ << std::fixed << std::setprecision(3) << static_cast< double >(RECORD_COUNT) / (static_cast< double >(duration) / 1000000.0)
+ << " records per second)" << std::endl;
+
+ return 0;
+}