2014-01-25 21:52:10 +08:00
|
|
|
// test.cpp : Defines the entry point for the console application.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
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-25 23:28:56 +08:00
|
|
|
|
2014-01-25 21:52:10 +08:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2014-01-28 01:35:18 +08:00
|
|
|
using namespace std::chrono;
|
2014-01-27 03:23:26 +08:00
|
|
|
int nthreads = argc > 1 ? atoi(argv[1]) : 1;
|
2014-01-28 01:35:18 +08:00
|
|
|
int nlines = argc > 2 ? atoi(argv[2]) : 1000000;
|
|
|
|
|
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-28 01:35:18 +08:00
|
|
|
auto async = std::make_shared<c11log::sinks::async_sink>(100);
|
2014-01-27 19:07:57 +08:00
|
|
|
//auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2);
|
2014-01-27 19:20:00 +08:00
|
|
|
auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
|
2014-01-25 23:28:56 +08:00
|
|
|
|
2014-01-27 19:07:57 +08:00
|
|
|
async->add_sink(fsink);
|
2014-01-28 01:35:18 +08:00
|
|
|
//async->add_sink(null_sink);
|
2014-01-25 23:28:56 +08:00
|
|
|
|
2014-01-26 07:53:23 +08:00
|
|
|
c11log::logger logger("test");
|
|
|
|
logger.add_sink(async);
|
2014-01-28 01:35:18 +08:00
|
|
|
|
2014-01-27 19:57:52 +08:00
|
|
|
std::vector<std::thread*> threads;
|
2014-01-28 01:35:18 +08:00
|
|
|
std::cout << "Starting " << nthreads << " threads x " << utils::format(nlines) << " lines each.." << std::endl;
|
2014-01-27 03:23:26 +08:00
|
|
|
for (int i = 0; i < nthreads; i++)
|
2014-01-26 07:53:23 +08:00
|
|
|
{
|
2014-01-28 01:35:18 +08:00
|
|
|
auto t = new std::thread([&logger, nlines]() {
|
|
|
|
|
|
|
|
for(int i = 0 ; i < nlines; ++i)
|
2014-01-26 07:53:23 +08:00
|
|
|
{
|
2014-01-28 01:35:18 +08:00
|
|
|
logger.info() << "Hello from thread " << std::this_thread::get_id() << "\tcounter: " << i ;
|
2014-01-27 19:57:52 +08:00
|
|
|
}
|
2014-01-26 07:53:23 +08:00
|
|
|
|
|
|
|
});
|
2014-01-27 19:57:52 +08:00
|
|
|
threads.push_back(t);
|
2014-01-26 07:53:23 +08:00
|
|
|
}
|
2014-01-27 19:57:52 +08:00
|
|
|
|
2014-01-28 01:35:18 +08:00
|
|
|
|
|
|
|
auto stime = steady_clock::now();
|
2014-01-27 19:57:52 +08:00
|
|
|
for(auto t:threads)
|
|
|
|
t->join();
|
2014-01-28 01:35:18 +08:00
|
|
|
auto delta = steady_clock::now() - stime;
|
|
|
|
auto delta_seconds = duration_cast<milliseconds>(delta).count()/1000.0;
|
|
|
|
|
|
|
|
auto total = nthreads*nlines;
|
|
|
|
std::cout << "Total: " << utils::format(total) << " = " << utils::format(total/delta_seconds) << "/sec" << std::endl;
|
|
|
|
|
|
|
|
async->shutdown(seconds(1));
|
2014-01-27 19:57:52 +08:00
|
|
|
|
2014-01-25 21:52:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|