header only\!

This commit is contained in:
gabime
2014-02-20 21:39:58 +02:00
parent 8176f82de2
commit 3feba27f8b
12 changed files with 90 additions and 152 deletions

23
example/makefile Normal file
View File

@@ -0,0 +1,23 @@
CXX = g++
CXXFLAGS = -march=native -Wall -Wextra -Wshadow -pedantic -std=c++11 -pthread -I../include
CXX_RELEASE_FLAGS = -O3 -flto
CXX_DEBUG_FLAGS= -g
OUTBIN = testme
all: test.cpp
$(CXX) test.cpp -o $(OUTBIN) $(CXXFLAGS) $(CXX_RELEASE_FLAGS)
debug: test.cpp
$(CXX) test.cpp -o $(OUTBIN)-debug $(CXXFLAGS) $(CXX_DEBUG_FLAFS)
clean:
rm -f *.text $(OUTBIN) $(OUTBIN)-debug
rebuild: clean all
rebuild-debug: clean debug

56
example/makefile.clang Normal file
View File

@@ -0,0 +1,56 @@
SRC_DIR=../../src
_SOURCES = factory.cpp formatters.cpp os.cpp
SOURCES = $(patsubst %,$(SRC_DIR)/%,$(_SOURCES))
OBJS_RELEASE = $(patsubst %.cpp,release/%.o,$(_SOURCES))
OBJS_DEBUG = $(patsubst %.cpp,debug/%.o,$(_SOURCES))
CXX = clang++
CXXFLAGS = -march=native -Wall -Wextra -Wshadow -pedantic -std=c++11 -pthread -I../../include
CXX_RELEASE_FLAGS = -O3 -flto
CXX_DEBUG_FLAGS= -g
OUTLIB_RELEASE = libc11log.a
OUTLIB_DEBUG = libc11log-debug.a
TEST_RELEASE = testme-clang
TEST_DEBUG = testme-debug-clang
.PHONY: all mkdirs release debug build clean rebuild
all: release
release: CXXFLAGS += $(CXX_RELEASE_FLAGS)
release: mkdirs build-release
debug: CXXFLAGS += $(CXX_DEBUG_FLAGS)
debug: mkdirs build-debug
mkdirs:
@mkdir -p release debug
build-release: $(OBJS_RELEASE)
ar rs $(OUTLIB_RELEASE) $^
$(CXX) $(SRC_DIR)/test.cpp $(OBJS_RELEASE) -o $(TEST_RELEASE) $(CXXFLAGS) -B/usr/lib/gold-ld/
build-debug: $(OBJS_DEBUG)
ar --plugin /usr/local/lib/LLVMgold.so rs $(OUTLIB_DEBUG) $^
$(CXX) $(SRC_DIR)/test.cpp $(OBJS_RELEASE) -o $(TEST_DEBUG) $(CXXFLAGS) -B/usr/lib/gold-ld/
release/%.o: $(SRC_DIR)/%.cpp
$(CXX) -c $< -o $@ $(CXXFLAGS)
debug/%.o: $(SRC_DIR)/%.cpp
$(CXX) -c $< -o $@ $(CXXFLAGS)
clean:
rm -rf release debug daily.* $(TEST_RELEASE) $(TEST_DEBUG) $(OUTLIB_RELEASE) $(OUTLIB_DEBUG)
rebuild: clean all

97
example/test.cpp Normal file
View File

@@ -0,0 +1,97 @@
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <functional>
#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"
std::atomic<uint64_t> push_count, pop_count;
std::atomic<bool> active;
using std::string;
using std::chrono::seconds;
using Q = c11log::details::blocking_queue<string>;
void pusher(Q* )
{
auto &logger = c11log::get_logger("async");
while(active)
{
logger.info()<<"Hello logger!";
++push_count;
}
}
void testq(int size, int pushers /*int poppers*/)
{
active = true;
Q q{static_cast<Q::size_type>(size)};
/*
for(int i = 0; i < poppers; i++)
testq(qsize, pushers, poppers);
*/
for(int i = 0; i < pushers; i++)
new std::thread(std::bind(pusher, &q));
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;
//cout << "Pops/sec =\t" << format(pop_count.load()) << endl << endl;
//cout << "Total/sec =\t" << format(push_count+pop_count) << endl;
cout << "Queue size =\t" << format(q.size()) << endl;
cout << "---------------------------------------------------------------------" << endl;
}
}
int main(int argc, char* argv[])
{
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]);
//testq(qsize, pushers, poppers);
using namespace std::chrono;
auto null_sink = std::make_shared<c11log::sinks::null_sink>();
auto stdout_sink = std::make_shared<c11log::sinks::stdout_sink>();
auto async = std::make_shared<c11log::sinks::async_sink>(1000);
auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*50 , 5);
//auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
async->add_sink(null_sink);
auto &logger = c11log::get_logger("async");
logger.add_sink(async);
testq(qsize, pushers);
}