spdlog/src/test.cpp

98 lines
2.2 KiB
C++
Raw Normal View History

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