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
3448e586
Commit
3448e586
authored
Jun 06, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added oberrun policy bench to async-bench and removed async from bench
parent
d3927390
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
31 deletions
+34
-31
async_bench.cpp
bench/async_bench.cpp
+33
-13
bench.cpp
bench/bench.cpp
+0
-17
logger-inl.h
include/spdlog/logger-inl.h
+1
-1
No files found.
bench/async_bench.cpp
View file @
3448e586
...
...
@@ -26,6 +26,7 @@ using namespace utils;
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996) //disable fopen warning under msvc
...
...
@@ -45,11 +46,22 @@ int count_lines(const char *filename)
return
counter
;
}
void
verify_file
(
const
char
*
filename
,
int
expected_count
)
{
auto
count
=
count_lines
(
filename
);
if
(
count
!=
expected_count
)
{
spdlog
::
error
(
"Test failed. {} has {:n} lines instead of {:n}"
,
filename
,
count
,
expected_count
);
exit
(
1
);
}
spdlog
::
info
(
"Line count OK ({:n})
\n
"
,
count
);
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -60,9 +72,9 @@ int main(int argc, char *argv[])
try
{
spdlog
::
set_pattern
(
"[%^%l%$] %v"
);
if
(
argc
==
1
)
{
spdlog
::
set_pattern
(
"%v"
);
spdlog
::
info
(
"Usage: {} <message_count> <threads> <q_size> <iterations>"
,
argv
[
0
]);
return
0
;
}
...
...
@@ -94,24 +106,32 @@ int main(int argc, char *argv[])
spdlog
::
info
(
"-------------------------------------------------"
);
const
char
*
filename
=
"logs/basic_async.log"
;
spdlog
::
info
(
""
);
spdlog
::
info
(
"*********************************"
);
spdlog
::
info
(
"Queue Overflow Policy: block"
);
spdlog
::
info
(
"*********************************"
);
for
(
int
i
=
0
;
i
<
iters
;
i
++
)
{
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic_file_sink_mt
>
(
filename
,
true
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"async_logger"
,
std
::
move
(
file_sink
),
std
::
move
(
tp
),
async_overflow_policy
::
block
);
bench_mt
(
howmany
,
std
::
move
(
logger
),
threads
);
auto
count
=
count_lines
(
filename
);
#ifdef SPDLOG_ASYNC_BENCH_VERIFY
verify_file
(
filename
,
howmany
);
#endif // SPDLOG_ASYNC_BENCH_VERIFY
}
if
(
count
!=
howmany
)
{
spdlog
::
error
(
"Test failed. {} has {:n} lines instead of {:n}"
,
filename
,
count
,
howmany
);
exit
(
1
);
}
else
{
spdlog
::
info
(
"Line count OK ({:n})
\n
"
,
count
);
}
spdlog
::
info
(
""
);
spdlog
::
info
(
"*********************************"
);
spdlog
::
info
(
"Queue Overflow Policy: overrun"
);
spdlog
::
info
(
"*********************************"
);
// do same test but discard oldest if queue is full instead of blocking
for
(
int
i
=
0
;
i
<
iters
;
i
++
)
{
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic_file_sink_mt
>
(
filename
,
true
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"async_logger"
,
std
::
move
(
file_sink
),
std
::
move
(
tp
),
async_overflow_policy
::
overrun_oldest
);
bench_mt
(
howmany
,
std
::
move
(
logger
),
threads
);
}
spdlog
::
shutdown
();
}
...
...
bench/bench.cpp
View file @
3448e586
...
...
@@ -7,7 +7,6 @@
// bench.cpp : spdlog benchmarks
//
#include "spdlog/spdlog.h"
#include "spdlog/async.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/null_sink.h"
...
...
@@ -95,22 +94,6 @@ int main(int argc, char *argv[])
auto
daily_mt
=
spdlog
::
daily_logger_mt
(
"daily_mt"
,
"logs/daily_mt.log"
);
bench_mt
(
howmany
,
std
::
move
(
daily_mt
),
threads
);
bench_mt
(
howmany
,
spdlog
::
create
<
null_sink_mt
>
(
"null_mt"
),
threads
);
int
iters
=
3
;
spdlog
::
info
(
"**************************************************************"
);
spdlog
::
info
(
"Asyncronous bench {:n} threads sharing same logger"
,
threads
);
spdlog
::
info
(
"Messages: {:n}"
,
howmany
);
spdlog
::
info
(
"Queue size: {:n} slots"
,
queue_size
);
auto
slot_size
=
sizeof
(
spdlog
::
details
::
async_msg
);
spdlog
::
info
(
"Total queue memory: {}x{} bytes per slot = {:n} Kb "
,
queue_size
,
slot_size
,
(
queue_size
*
slot_size
)
/
1024
);
spdlog
::
info
(
"**************************************************************"
);
for
(
int
i
=
0
;
i
<
iters
;
++
i
)
{
spdlog
::
init_thread_pool
(
static_cast
<
size_t
>
(
queue_size
),
1
);
auto
as
=
spdlog
::
basic_logger_mt
<
spdlog
::
async_factory
>
(
"async"
,
"logs/basic_async.log"
,
true
);
bench_mt
(
howmany
,
std
::
move
(
as
),
threads
);
}
}
catch
(
std
::
exception
&
ex
)
{
...
...
include/spdlog/logger-inl.h
View file @
3448e586
...
...
@@ -64,7 +64,7 @@ SPDLOG_INLINE const std::string &logger::name() const
return
name_
;
}
// set formatting for the sinks in this logger.
redundant
// set formatting for the sinks in this logger.
// each sink will get a seperate instance of the formatter object.
SPDLOG_INLINE
void
logger
::
set_formatter
(
std
::
unique_ptr
<
formatter
>
f
)
{
...
...
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