update and change how we build with spdlog

This commit is contained in:
Benjamin Sergeant
2019-09-29 11:13:24 -07:00
parent 0ee675e554
commit 681390f22f
156 changed files with 28175 additions and 19817 deletions

View File

@ -26,6 +26,11 @@ using namespace utils;
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996) // disable fopen warning under msvc
#endif // _MSC_VER
int count_lines(const char *filename)
{
int counter = 0;
@ -40,19 +45,36 @@ int count_lines(const char *filename)
return counter;
}
void verify_file(const char *filename, int expected_count)
{
spdlog::info("Verifying {} to contain {:n} line..", filename, expected_count);
auto count = count_lines(filename);
if (count != expected_count)
{
spdlog::error("Test failed. {} has {:n} lines instead of {:n}", filename, count, expected_count);
exit(1);
}
spdlog::info("Line count OK ({:n})\n", count);
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
int main(int argc, char *argv[])
{
int howmany = 1000000;
int queue_size = howmany + 2;
int queue_size = std::min(howmany + 2, 8192);
int threads = 10;
int iters = 3;
try
{
spdlog::set_pattern("[%^%l%$] %v");
if (argc == 1)
{
spdlog::set_pattern("%v");
spdlog::info("Usage: {} <message_count> <threads> <q_size> <iterations>", argv[0]);
return 0;
}
@ -62,37 +84,54 @@ int main(int argc, char *argv[])
if (argc > 2)
threads = atoi(argv[2]);
if (argc > 3)
{
queue_size = atoi(argv[3]);
if (queue_size > 500000)
{
spdlog::error("Max queue size allowed: 500,000");
exit(1);
}
}
if (argc > 4)
iters = atoi(argv[4]);
auto slot_size = sizeof(spdlog::details::async_msg);
spdlog::info("-------------------------------------------------");
spdlog::info("Messages: {:14n}", howmany);
spdlog::info("Threads : {:14n}", threads);
spdlog::info("Queue : {:14n}", queue_size);
spdlog::info("Iters : {:>14n}", iters);
spdlog::info("Messages : {:n}", howmany);
spdlog::info("Threads : {:n}", threads);
spdlog::info("Queue : {:n} slots", queue_size);
spdlog::info("Queue memory : {:n} x {} = {:n} KB ", queue_size, slot_size, (queue_size * slot_size) / 1024);
spdlog::info("Total iters : {:n}", iters);
spdlog::info("-------------------------------------------------");
const char *filename = "logs/basic_async.log";
spdlog::info("");
spdlog::info("*********************************");
spdlog::info("Queue Overflow Policy: block");
spdlog::info("*********************************");
for (int i = 0; i < iters; i++)
{
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
auto logger = std::make_shared<async_logger>("async_logger", std::move(file_sink), std::move(tp), async_overflow_policy::block);
bench_mt(howmany, std::move(logger), threads);
auto count = count_lines(filename);
// verify_file(filename, howmany);
}
if (count != howmany)
{
spdlog::error("Test failed. {} has {:n} lines instead of {:n}", filename, count, howmany);
exit(1);
}
else
{
spdlog::info("Line count OK ({:n})\n", count);
}
spdlog::info("");
spdlog::info("*********************************");
spdlog::info("Queue Overflow Policy: overrun");
spdlog::info("*********************************");
// do same test but discard oldest if queue is full instead of blocking
filename = "logs/basic_async-overrun.log";
for (int i = 0; i < iters; i++)
{
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
auto logger =
std::make_shared<async_logger>("async_logger", std::move(file_sink), std::move(tp), async_overflow_policy::overrun_oldest);
bench_mt(howmany, std::move(logger), threads);
}
spdlog::shutdown();
}
@ -102,7 +141,6 @@ int main(int argc, char *argv[])
perror("Last error");
return 1;
}
return 0;
}