80 lines
2.6 KiB
C++
80 lines
2.6 KiB
C++
#include "catch/catch.hpp"
|
|
#include "lib/config/config.h"
|
|
#include "lib/config/protos/logging.pb.h"
|
|
#include "lib/utils/bts_chrono.h"
|
|
#include "lib/logging/logging.h"
|
|
|
|
#include <fmt/chrono.h>
|
|
|
|
namespace bts {
|
|
int logging_tests;
|
|
|
|
TEST_CASE("Logging Tests", "[logging] [benchmark]") {
|
|
|
|
auto sz = 1000000;
|
|
log::Filter f;
|
|
for (auto &l : f)
|
|
l = Diag;
|
|
log::LoggingConfig cfg;
|
|
cfg.logger_initial_queue_size = sz * 10;
|
|
cfg.sinks["null_sink"] = std::make_pair([](log::LogMsg const &) {}, f);
|
|
log::configure_logging(cfg);
|
|
LOG(Gen, Info, "Kicking things off");
|
|
|
|
SECTION("timestamp_interpolation") {
|
|
auto start = bts::Timer::now();
|
|
for (int i = 0; i < sz; i++)
|
|
LOG(Gen, Info, "Hello World. It is now: {0}", Timer::now());
|
|
auto stop = Timer::now();
|
|
LOG(Testing, Info, "Logging: ns/msg for log with timestamps: {} tt: {} ",
|
|
bts::ns_diff(stop, start) / sz, bts::ns_diff(stop, start));
|
|
}
|
|
|
|
SECTION("int_interpolation") {
|
|
auto start = bts::Timer::now();
|
|
for (int i = 0; i < sz; i++)
|
|
LOG(Gen, Info, "Hello World. This is interpolating a number {0}", 12);
|
|
auto stop = bts::Timer::now();
|
|
LOG(Testing, Info,
|
|
"Logging: ns/msg for log with simple number interpolation: {} tt: "
|
|
"{} ",
|
|
bts::ns_diff(stop, start) / sz, bts::ns_diff(stop, start));
|
|
}
|
|
|
|
SECTION("large_string_interpolation") {
|
|
std::array<std::string, 8> strs;
|
|
int i = 0;
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
|
|
auto start = bts::Timer::now();
|
|
for (int i = 0; i < sz; i++)
|
|
LOG(Gen, Info, "Hello World. This is interpolating a string ",
|
|
strs[i & 0x00000007]);
|
|
auto stop = bts::Timer::now();
|
|
LOG(Testing, Info,
|
|
"Logging: ns/msg for log with large string interpolation: {} tt: {} ",
|
|
bts::ns_diff(stop, start) / sz, bts::ns_diff(stop, start));
|
|
}
|
|
|
|
SECTION("log_skipping") {
|
|
auto start = bts::Timer::now();
|
|
for (int i = 0; i < sz; i++)
|
|
LOG(Gen, Diag, "Hello World. I am {} years old!", i);
|
|
auto stop = bts::Timer::now();
|
|
LOG(Testing, Info, "Logging: ns/msg for log skipping: {} tt: {} ",
|
|
bts::ns_diff(stop, start) / sz, bts::ns_diff(stop, start));
|
|
}
|
|
auto cfg2 = config::get<config::Logging>();
|
|
cfg2.mutable_console()->set_default_level("Fatal");
|
|
log::configure_logging(cfg2);
|
|
}
|
|
|
|
} // namespace bts
|