Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
52dc317c
Commit
52dc317c
authored
Feb 03, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes
parent
5e8eea7e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
114 deletions
+49
-114
makefile
build/gcc/makefile
+1
-1
fast_oss.h
include/c11log/details/fast_oss.h
+16
-20
formatters.cpp
src/formatters.cpp
+3
-2
test.cpp
src/test.cpp
+29
-91
No files found.
build/gcc/makefile
View file @
52dc317c
...
@@ -9,7 +9,7 @@ OBJS_DEBUG = $(patsubst %.cpp,debug/%.o,$(_SOURCES))
...
@@ -9,7 +9,7 @@ OBJS_DEBUG = $(patsubst %.cpp,debug/%.o,$(_SOURCES))
CXX
=
g++
CXX
=
g++
CXXFLAGS
=
-march
=
native
-Wall
-std
=
c++11
-pthread
-I
../../include
CXXFLAGS
=
-march
=
native
-Wall
-std
=
c++11
-pthread
-I
../../include
CXX_RELEASE_FLAGS
=
-O2
-flto
CXX_RELEASE_FLAGS
=
-O2
-flto
-g
CXX_DEBUG_FLAGS
=
-g
CXX_DEBUG_FLAGS
=
-g
OUTLIB_RELEASE
=
libc11log.a
OUTLIB_RELEASE
=
libc11log.a
...
...
include/c11log/details/fast_oss.h
View file @
52dc317c
...
@@ -7,12 +7,12 @@ namespace details {
...
@@ -7,12 +7,12 @@ namespace details {
class
str_devicebuf
:
public
std
::
streambuf
{
class
str_devicebuf
:
public
std
::
streambuf
{
public
:
public
:
str_devicebuf
()
str_devicebuf
()
=
default
;
{
~
str_devicebuf
()
=
default
;
_str
.
reserve
(
128
);
str_devicebuf
(
const
str_devicebuf
&
)
=
delete
;
}
str_devicebuf
&
operator
=
(
const
str_devicebuf
&
)
=
delete
;
const
std
::
string
&
str_ref
()
const
std
::
string
&
str_ref
()
const
{
{
return
_str
;
return
_str
;
}
}
...
@@ -46,31 +46,28 @@ private:
...
@@ -46,31 +46,28 @@ private:
class
fast_oss
:
public
std
::
ostream
{
class
fast_oss
:
public
std
::
ostream
{
public
:
public
:
fast_oss
()
:
std
::
ostream
(
&
_dev
)
fast_oss
()
:
std
::
ostream
(
&
_dev
){}
{}
~
fast_oss
()
=
default
;
~
fast_oss
()
fast_oss
(
const
fast_oss
&
)
=
delete
;
{}
fast_oss
operator
=
(
const
fast_oss
&
)
=
delete
;
const
std
::
string
&
str_ref
()
const
const
std
::
string
&
str_ref
()
const
{
{
auto
mydevice
=
static_cast
<
str_devicebuf
*>
(
rdbuf
());
return
_dev
.
str_ref
();
return
mydevice
->
str_ref
();
}
}
const
std
::
string
str
()
const
const
std
::
string
str
()
const
{
{
auto
mydevice
=
static_cast
<
str_devicebuf
*>
(
rdbuf
());
return
_dev
.
str_ref
();
return
mydevice
->
str_ref
();
}
}
void
clear
()
void
clear
()
{
{
auto
mydevice
=
static_cast
<
str_devicebuf
*>
(
rdbuf
());
_dev
.
clear
();
mydevice
->
clear
();
}
}
private
:
private
:
str_devicebuf
_dev
;
str_devicebuf
_dev
;
};
};
}
}
}
}
\ No newline at end of file
src/formatters.cpp
View file @
52dc317c
...
@@ -9,12 +9,13 @@ void c11log::formatters::format_time(const c11log::formatters::timepoint& tp, st
...
@@ -9,12 +9,13 @@ void c11log::formatters::format_time(const c11log::formatters::timepoint& tp, st
//get ms
//get ms
//auto duration = tp.time_since_epoch();
//auto duration = tp.time_since_epoch();
//int millis = static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000);
//int millis = static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000);
char
buf
[
64
];
char
buf
[
64
];
auto
size
=
sprintf
(
buf
,
"[%d-%02d-%02d %02d:%02d:%02d]"
,
auto
size
=
sprintf
(
buf
,
"[%d-%02d-%02d %02d:%02d:%02d]"
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
dest
.
write
(
buf
,
size
);
dest
.
write
(
buf
,
size
);
}
}
...
...
src/test.cpp
View file @
52dc317c
...
@@ -17,52 +17,29 @@ std::atomic<bool> active;
...
@@ -17,52 +17,29 @@ std::atomic<bool> active;
class
A
{
public
:
A
()
{
std
::
cout
<<
"Regular ctor
\n
"
;
}
A
(
const
A
&
)
{
std
::
cout
<<
"Copy ctor
\n
"
;
}
A
&
operator
=
(
const
A
&
)
{
std
::
cout
<<
"operator=
\n
"
;
return
*
this
;
}
A
&
operator
=
(
A
&&
)
{
std
::
cout
<<
"operator=&&
\n
"
;
return
*
this
;
}
A
(
A
&&
a
)
{
std
::
cout
<<
"Move ctor
\n
"
;
}
~
A
()
{
//std::cout << "Dtor\n";
}
};
using
std
::
string
;
using
std
::
string
;
using
std
::
chrono
::
seconds
;
using
std
::
chrono
::
seconds
;
using
Q
=
c11log
::
details
::
blocking_queue
<
string
>
;
using
Q
=
c11log
::
details
::
blocking_queue
<
string
>
;
void
pusher
(
Q
*
q
)
void
pusher
(
Q
*
q
)
{
{
auto
&
logger
=
c11log
::
get_logger
(
"async"
);
while
(
active
)
{
logger
.
info
()
<<
"Hello logger!"
;
++
push_count
;
}
/*
string a = "Hello";
string a = "Hello";
while(active)
while(active)
{
{
q->push(a);
q->push(a);
++push_count;
++push_count;
}
}
*/
}
}
void
popper
(
Q
*
q
)
void
popper
(
Q
*
q
)
...
@@ -73,6 +50,7 @@ void popper(Q* q)
...
@@ -73,6 +50,7 @@ void popper(Q* q)
q
->
pop
(
output
);
q
->
pop
(
output
);
++
pop_count
;
++
pop_count
;
}
}
}
}
void
testq
(
int
size
,
int
pushers
,
int
poppers
)
void
testq
(
int
size
,
int
pushers
,
int
poppers
)
...
@@ -81,9 +59,10 @@ void testq(int size, int pushers, int poppers)
...
@@ -81,9 +59,10 @@ void testq(int size, int pushers, int poppers)
active
=
true
;
active
=
true
;
Q
q
{
static_cast
<
Q
::
size_type
>
(
size
)};
Q
q
{
static_cast
<
Q
::
size_type
>
(
size
)};
/*
for(int i = 0; i < poppers; i++)
for(int i = 0; i < poppers; i++)
new
std
::
thread
(
std
::
bind
(
popper
,
&
q
)
);
testq(qsize, pushers, poppers
);
*/
for
(
int
i
=
0
;
i
<
pushers
;
i
++
)
for
(
int
i
=
0
;
i
<
pushers
;
i
++
)
new
std
::
thread
(
std
::
bind
(
pusher
,
&
q
));
new
std
::
thread
(
std
::
bind
(
pusher
,
&
q
));
...
@@ -97,12 +76,11 @@ void testq(int size, int pushers, int poppers)
...
@@ -97,12 +76,11 @@ void testq(int size, int pushers, int poppers)
pop_count
=
0
;
pop_count
=
0
;
std
::
this_thread
::
sleep_for
(
seconds
(
1
));
std
::
this_thread
::
sleep_for
(
seconds
(
1
));
cout
<<
"Pushes/sec =
\t
"
<<
format
(
push_count
.
load
())
<<
endl
;
cout
<<
"Pushes/sec =
\t
"
<<
format
(
push_count
.
load
())
<<
endl
;
cout
<<
"Pops/sec =
\t
"
<<
format
(
pop_count
.
load
())
<<
endl
;
//cout << "Pops/sec =\t" << format(pop_count.load()) << endl
<< endl;
cout
<<
"Total/sec =
\t
"
<<
format
(
push_count
+
pop_count
)
<<
endl
<<
endl
;
//cout << "Total/sec =\t" << format(push_count+pop_count)
<< endl;
cout
<<
"Queue size =
\t
"
<<
format
(
q
.
size
())
<<
endl
;
cout
<<
"Queue size =
\t
"
<<
format
(
q
.
size
())
<<
endl
;
cout
<<
"---------------------------------------------------------------------"
<<
endl
;
cout
<<
"---------------------------------------------------------------------"
<<
endl
;
}
}
}
}
...
@@ -118,68 +96,28 @@ int main(int argc, char* argv[])
...
@@ -118,68 +96,28 @@ int main(int argc, char* argv[])
int
pushers
=
atoi
(
argv
[
2
]);
int
pushers
=
atoi
(
argv
[
2
]);
int
poppers
=
atoi
(
argv
[
3
]);
int
poppers
=
atoi
(
argv
[
3
]);
testq
(
qsize
,
pushers
,
poppers
);
//testq(qsize, pushers, poppers);
/*
using namespace std::chrono;
int nthreads = argc > 1 ? atoi(argv[1]) : 1;
using
namespace
std
::
chrono
;
int nlines = argc > 2 ? atoi(argv[2]) : 100000;
auto
null_sink
=
std
::
make_shared
<
c11log
::
sinks
::
null_sink
>
();
auto
null_sink
=
std
::
make_shared
<
c11log
::
sinks
::
null_sink
>
();
auto
stdout_sink
=
std
::
make_shared
<
c11log
::
sinks
::
stdout_sink
>
();
auto
stdout_sink
=
std
::
make_shared
<
c11log
::
sinks
::
stdout_sink
>
();
auto
async
=
std
::
make_shared
<
c11log
::
sinks
::
async_sink
>
(
1000
);
auto
async
=
std
::
make_shared
<
c11log
::
sinks
::
async_sink
>
(
1000
);
//
auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2);
auto
fsink
=
std
::
make_shared
<
c11log
::
sinks
::
rotating_file_sink
>
(
"newlog"
,
"txt"
,
1024
*
1024
*
10
,
2
);
//auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
//auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
//async->add_sink(fsink);
async->add_sink(null_sink);
//Async logger
//console logger
async
->
add_sink
(
null_sink
);
auto &console = c11log::get_logger("console");
auto
&
logger
=
c11log
::
get_logger
(
"async"
);
console.add_sink(stdout_sink);
logger
.
add_sink
(
async
);
//c11log::details::blocking_queue<std::string> q(1000);
//auto q_ptr = &q;
std::vector<std::thread*> threads;
std::cout << "Starting " << nthreads << " threads x " << utils::format(nlines) << " lines each.." << std::endl;
for (int i = 0; i < nthreads; i++)
{
auto logger = std::make_shared<c11log::logger>("test");
logger->add_sink(async);
auto t = new std::thread([logger, nlines, i]() {
testq
(
qsize
,
pushers
,
poppers
);
auto &console = c11log::get_logger("console");
for(int j = 0 ; j < nlines; ++j)
{
logger->info() << "Hello from thread #" << i << "\tcounter: " << j ;
if(j % 2000 == 0)
console.info() << "Hello from thread " << i << "\tcounter: " << j;
}
});
threads.push_back(t);
//std::this_thread::sleep_for(milliseconds(2));
}
auto stime = steady_clock::now();
int thread_joined = 0;
for(auto t:threads)
{
t->join();
std::cout << "Joined " << ++thread_joined << " threads" << std::endl;
}
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));
*/
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment