spdlog/src/test.cpp

101 lines
2.2 KiB
C++
Raw Normal View History

2014-01-25 08:52:10 -05:00
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
2014-01-28 21:00:05 -05:00
#include <functional>
2014-01-26 14:23:26 -05:00
#include "c11log/logger.h"
#include "c11log/sinks/async_sink.h"
#include "c11log/sinks/file_sinks.h"
#include "c11log/sinks/stdout_sinks.h"
#include "utils.h"
2014-01-25 08:52:10 -05:00
2014-01-28 21:00:05 -05:00
std::atomic<uint64_t> push_count, pop_count;
std::atomic<bool> active;
2014-01-31 18:47:37 -05:00
using std::string;
2014-01-28 21:00:05 -05:00
using std::chrono::seconds;
2014-01-31 18:47:37 -05:00
using Q = c11log::details::blocking_queue<string>;
2014-01-28 21:00:05 -05:00
void pusher(Q* q)
{
2014-02-03 13:28:19 -05:00
auto &logger = c11log::get_logger("async");
while(active)
{
logger.info()<<"Hello logger!";
2014-02-05 18:21:40 -05:00
++push_count;
2014-02-03 13:28:19 -05:00
}
2014-02-05 18:21:40 -05:00
2014-01-28 21:00:05 -05:00
}
2014-02-05 18:21:40 -05:00
2014-01-28 21:00:05 -05:00
void testq(int size, int pushers, int poppers)
{
active = true;
Q q{static_cast<Q::size_type>(size)};
2014-01-31 18:47:37 -05:00
2014-02-03 13:28:19 -05:00
/*
2014-01-28 21:00:05 -05:00
for(int i = 0; i < poppers; i++)
2014-02-03 13:28:19 -05:00
testq(qsize, pushers, poppers);
*/
2014-01-28 21:00:05 -05:00
for(int i = 0; i < pushers; i++)
new std::thread(std::bind(pusher, &q));
2014-02-01 16:49:55 -05:00
2014-01-28 21:00:05 -05:00
while(active)
{
using std::endl;
using std::cout;
using utils::format;
push_count = 0;
pop_count = 0;
std::this_thread::sleep_for(seconds(1));
cout << "Pushes/sec =\t" << format(push_count.load()) << endl;
2014-02-03 13:28:19 -05:00
//cout << "Pops/sec =\t" << format(pop_count.load()) << endl << endl;
//cout << "Total/sec =\t" << format(push_count+pop_count) << endl;
2014-01-28 21:00:05 -05:00
cout << "Queue size =\t" << format(q.size()) << endl;
cout << "---------------------------------------------------------------------" << endl;
2014-02-03 13:28:19 -05:00
}
2014-01-28 21:00:05 -05:00
}
2014-01-31 18:47:37 -05:00
2014-01-25 08:52:10 -05:00
int main(int argc, char* argv[])
{
2014-01-31 18:47:37 -05:00
2014-01-28 21:00:05 -05:00
if(argc !=4)
{
std::cerr << "Usage: " << argv[0] << " qsize, pushers, poppers" << std::endl;
return 0;
}
int qsize = atoi(argv[1]);
int pushers = atoi(argv[2]);
int poppers = atoi(argv[3]);
2014-02-03 13:28:19 -05:00
//testq(qsize, pushers, poppers);
2014-01-28 21:00:05 -05:00
2014-02-03 13:28:19 -05:00
using namespace std::chrono;
2014-01-27 12:35:18 -05:00
2014-02-03 13:28:19 -05:00
2014-01-25 18:53:23 -05:00
auto null_sink = std::make_shared<c11log::sinks::null_sink>();
2014-01-26 14:23:26 -05:00
auto stdout_sink = std::make_shared<c11log::sinks::stdout_sink>();
2014-01-28 21:00:05 -05:00
auto async = std::make_shared<c11log::sinks::async_sink>(1000);
2014-02-03 13:28:19 -05:00
auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2);
2014-01-28 21:00:05 -05:00
//auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
2014-02-05 18:21:40 -05:00
async->add_sink(fsink);
2014-02-03 13:28:19 -05:00
auto &logger = c11log::get_logger("async");
logger.add_sink(async);
2014-01-28 21:00:05 -05:00
2014-02-03 13:28:19 -05:00
testq(qsize, pushers, poppers);
2014-01-27 06:57:52 -05:00
2014-01-27 12:35:18 -05:00
2014-01-25 08:52:10 -05:00
}