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
2d075bcf
Commit
2d075bcf
authored
Oct 31, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bench
parent
31971bf6
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
96 additions
and
116 deletions
+96
-116
bench.cpp
example/bench.cpp
+78
-26
example.cpp
example/example.cpp
+2
-3
.gitignore
example/logs/.gitignore
+4
-0
makefile
example/makefile
+1
-1
makefile.bench
example/makefile.bench
+0
-24
makefile.clang
example/makefile.clang
+1
-1
utils.h
example/utils.h
+0
-34
file_helper.h
include/spdlog/details/file_helper.h
+10
-9
logger.h
include/spdlog/logger.h
+0
-18
No files found.
example/bench.cpp
View file @
2d075bcf
// example.cpp : Simple logger example
//
// bench.cpp : spdlog benchmarks
//
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <atomic>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/file_sinks.h"
#include "spdlog/sinks/stdout_sinks.h"
...
...
@@ -10,47 +16,93 @@
using
namespace
std
;
using
namespace
std
::
chrono
;
using
namespace
spdlog
;
using
namespace
spdlog
::
sinks
;
using
namespace
utils
;
int
main_
(
int
argc
,
char
*
argv
[]
)
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
)
{
try
{
cout
<<
log
->
name
()
<<
", "
<<
format
(
howmany
)
<<
" iterations.."
<<
endl
;
auto
start
=
system_clock
::
now
();
for
(
auto
i
=
0
;
i
<
howmany
;
++
i
)
{
log
->
info
(
"Hello logger: msg number "
)
<<
i
;
}
using
namespace
spdlog
::
sinks
;
spdlog
::
create
<
daily_file_sink_st
>
(
"mylog"
,
"dailylog"
,
"txt"
);
const
unsigned
int
howmany
=
argc
<=
1
?
1500000
:
atoi
(
argv
[
1
]);
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout
<<
"Delta:"
<<
format
(
delta_d
)
<<
" seconds"
<<
endl
;
cout
<<
"Rate:"
<<
format
(
howmany
/
delta_d
)
<<
"/sec"
<<
endl
<<
endl
;
}
spdlog
::
set_pattern
(
"%Y-%m-%d %H:%M:%S.%e %l : %t"
);
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
)
{
auto
console
=
spdlog
::
create
<
sinks
::
stdout_sink_st
>
(
"reporter"
);
console
->
info
(
"Starting bench with"
,
howmany
,
"iterations.."
);
console
->
log
()
<<
"Streams are also supprted: "
<<
std
::
hex
<<
255
;
spdlog
::
stop
();
cout
<<
log
->
name
()
<<
", "
<<
format
(
howmany
)
<<
" iterations.."
<<
endl
;
std
::
atomic
<
int
>
msg_counter
{
0
};
vector
<
thread
>
threads
;
auto
start
=
system_clock
::
now
();
for
(
int
t
=
0
;
t
<
thread_count
;
++
t
)
{
threads
.
push_back
(
std
::
thread
([
&
]()
{
while
(
msg_counter
++
<
howmany
)
log
->
info
(
"Hello logger: msg number "
)
<<
msg_counter
;
}));
}
for
(
auto
&
t
:
threads
)
{
t
.
join
();
};
//return 0;
auto
bench
=
spdlog
::
create
<
sinks
::
rotating_file_sink_st
>
(
"bench"
,
"myrotating"
,
"txt"
,
1024
*
1024
*
1
,
10
,
0
);
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout
<<
"Delta:"
<<
format
(
delta_d
)
<<
" seconds"
<<
endl
;
cout
<<
"Rate:"
<<
format
(
howmany
/
delta_d
)
<<
"/sec"
<<
endl
<<
endl
;
}
//auto bench = spdlog::create<sinks::simple_file_sink_st>("bench", "simplelog.txt", 1);
//auto bench = spdlog::create<sinks::null_sink_st>("bench");
auto
start
=
system_clock
::
now
();
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
++
i
)
{
bench
->
info
(
"Hello logger: msg number"
)
<<
i
;
}
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
int
main
(
int
argc
,
char
*
argv
[])
{
cout
<<
"Total:"
<<
format
(
howmany
)
<<
endl
;
cout
<<
"Delta:"
<<
format
(
delta_d
)
<<
endl
;
cout
<<
"Rate:"
<<
format
(
howmany
/
delta_d
)
<<
"/sec
\n
"
;
try
{
int
howmany
=
argc
<=
1
?
100000
:
atoi
(
argv
[
1
]);
int
threads
=
argc
<=
2
?
4
:
atoi
(
argv
[
2
]);
int
flush_interval
=
100
;
cout
<<
"*******************************************************************************
\n
"
;
cout
<<
"Single threaded benchmarks. flush_interval = "
<<
flush_interval
<<
endl
;
cout
<<
"*******************************************************************************
\n
"
;
auto
rotating_st
=
spdlog
::
rotating_logger_st
(
"rotating_st"
,
"logs/rotating_st"
,
1024
*
1024
*
5
,
5
,
flush_interval
);
bench
(
howmany
,
rotating_st
);
auto
daily_st
=
spdlog
::
daily_logger_st
(
"daily_st"
,
"logs/daily_st"
,
flush_interval
);
bench
(
howmany
,
daily_st
);
bench
(
howmany
,
spdlog
::
create
<
null_sink_st
>
(
"null_st"
));
cout
<<
"*******************************************************************************
\n
"
;
cout
<<
"Multi threaded benchmarks ("
<<
threads
<<
" threads), flush_interval = "
<<
flush_interval
<<
endl
;
cout
<<
"*******************************************************************************
\n
"
;
auto
rotating_mt
=
spdlog
::
rotating_logger_mt
(
"rotating_mt"
,
"logs/rotating_mt"
,
1024
*
1024
*
5
,
5
,
flush_interval
);
bench_mt
(
howmany
,
rotating_mt
,
threads
);
auto
daily_mt
=
spdlog
::
daily_logger_mt
(
"daily_mt"
,
"logs/daily_mt"
,
flush_interval
);
bench_mt
(
howmany
,
daily_mt
,
threads
);
bench_mt
(
howmany
,
spdlog
::
create
<
null_sink_mt
>
(
"null_mt"
),
threads
);
}
catch
(
std
::
exception
&
ex
)
{
std
::
cerr
<<
"E
xception
: "
<<
ex
.
what
()
<<
std
::
endl
;
std
::
cerr
<<
"E
rror
: "
<<
ex
.
what
()
<<
std
::
endl
;
perror
(
"Last error"
);
}
return
0
;
...
...
example/example.cpp
View file @
2d075bcf
...
...
@@ -10,11 +10,12 @@ int main(int, char* [])
{
namespace
spd
=
spdlog
;
try
{
std
::
string
filename
=
"spdlog_example"
;
auto
console
=
spd
::
stderr_logger_mt
(
"console"
);
console
->
info
(
"Welcome to spdlog!"
);
console
->
info
(
"Welcome to spdlog!"
)
;
console
->
info
()
<<
"Creating file "
<<
filename
<<
".."
;
auto
file_logger
=
spd
::
rotating_logger_mt
(
"file_logger"
,
filename
,
1024
*
1024
*
5
,
3
);
...
...
@@ -26,7 +27,6 @@ int main(int, char* [])
file_logger
->
info
()
<<
i
<<
'*'
<<
i
<<
'='
<<
square
<<
" ("
<<
"0x"
<<
std
::
hex
<<
square
<<
")"
;
}
// Change log level to all loggers to warning and above
spd
::
set_level
(
spd
::
level
::
WARN
);
console
->
info
(
"This should not be displayed"
);
...
...
@@ -40,6 +40,5 @@ int main(int, char* [])
{
std
::
cout
<<
"Log failed: "
<<
ex
.
what
()
<<
std
::
endl
;
}
}
example/logs/.gitignore
0 → 100644
View file @
2d075bcf
# Ignore everything in this directory
*
# Except this file
!.gitignore
example/makefile
View file @
2d075bcf
...
...
@@ -23,7 +23,7 @@ bench-debug: bench.cpp
clean
:
rm
-f
*
.o
*
.txt example example-debug bench bench-debug
rm
-f
*
.o
logs/
*
.txt example example-debug bench bench-debug
rebuild
:
clean all
...
...
example/makefile.bench
deleted
100644 → 0
View file @
31971bf6
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
=
bench
all
:
bench.cpp
$(CXX)
bench.cpp
-o
$(OUTBIN)
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
debug
:
bench.cpp
$(CXX)
bench.cpp
-o
$(OUTBIN)
-debug
$(CXXFLAGS)
$(CXX_DEBUG_FLAGS)
clean
:
rm
-f
*
.txt
$(OUTBIN)
$(OUTBIN)
-debug
rebuild
:
clean all
rebuild-debug
:
clean debug
example/makefile.clang
View file @
2d075bcf
...
...
@@ -23,7 +23,7 @@ bench-debug: bench.cpp
clean
:
rm
-f
*
.o
*
.txt example-clang example-clang-debug bench-clang bench-clang-debug
rm
-f
*
.o
logs/
*
.txt example-clang example-clang-debug bench-clang bench-clang-debug
rebuild
:
clean all
...
...
example/utils.h
View file @
2d075bcf
...
...
@@ -30,38 +30,4 @@ inline std::string format(const double & value)
return
ss
.
str
();
}
inline
void
bench
(
const
std
::
string
&
fn_name
,
const
std
::
chrono
::
milliseconds
&
duration
,
const
std
::
function
<
void
()
>&
fn
)
{
using
namespace
std
::
chrono
;
typedef
steady_clock
the_clock
;
size_t
counter
=
0
;
seconds
print_interval
(
1
);
auto
start_time
=
the_clock
::
now
();
auto
lastPrintTime
=
start_time
;
while
(
true
)
{
fn
();
++
counter
;
auto
now
=
the_clock
::
now
();
if
(
now
-
start_time
>=
duration
)
break
;
if
(
now
-
lastPrintTime
>=
print_interval
)
{
std
::
cout
<<
fn_name
<<
": "
<<
format
(
counter
)
<<
" per sec"
<<
std
::
endl
;
counter
=
0
;
lastPrintTime
=
the_clock
::
now
();
}
}
}
inline
void
bench
(
const
std
::
string
&
fn_name
,
const
std
::
function
<
void
()
>&
fn
)
{
using
namespace
std
::
chrono
;
auto
start
=
steady_clock
::
now
();
fn
();
auto
delta
=
steady_clock
::
now
()
-
start
;
std
::
cout
<<
fn_name
<<
": "
<<
duration_cast
<
milliseconds
>
(
delta
).
count
()
<<
" ms"
<<
std
::
endl
;
}
}
include/spdlog/details/file_helper.h
View file @
2d075bcf
...
...
@@ -12,7 +12,8 @@
#include <string>
#include <thread>
#include <chrono>
#include "../common.h"
#include "os.h"
...
...
@@ -24,8 +25,8 @@ namespace details
class
file_helper
{
public
:
static
const
int
open_max
_tries
=
5
;
static
const
int
sleep_ms_bewteen_tries
=
10
;
const
int
open
_tries
=
5
;
const
int
open_interval
=
10
;
explicit
file_helper
(
const
std
::
size_t
flush_inverval
)
:
_fd
(
nullptr
),
...
...
@@ -40,21 +41,21 @@ public:
}
void
open
(
const
std
::
string
&
f
ile
name
)
void
open
(
const
std
::
string
&
fname
)
{
close
();
_filename
=
f
ile
name
;
for
(
int
tries
=
0
;
tries
<
open_
max_
tries
;
++
tries
)
_filename
=
fname
;
for
(
int
tries
=
0
;
tries
<
open_tries
;
++
tries
)
{
if
(
!
os
::
fopen_s
(
&
_fd
,
f
ile
name
,
"wb"
))
if
(
!
os
::
fopen_s
(
&
_fd
,
fname
,
"wb"
))
return
;
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
sleep_ms_bewteen_tries
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
open_interval
));
}
throw
spdlog_ex
(
"Failed opening file "
+
f
ile
name
+
" for writing"
);
throw
spdlog_ex
(
"Failed opening file "
+
fname
+
" for writing"
);
}
void
close
()
...
...
include/spdlog/logger.h
View file @
2d075bcf
...
...
@@ -9,9 +9,6 @@
#include<vector>
#include<memory>
#include<atomic>
#include <sstream>
#include <exception>
#include "sinks/base_sink.h"
#include "common.h"
...
...
@@ -75,19 +72,4 @@ private:
}
//
// Trace & debug macros
//
#ifdef FFLOG_ENABLE_TRACE
#define FFLOG_TRACE(logger, ...) logger->log(spdlog::level::TRACE, __FILE__, " #", __LINE__,": " __VA_ARGS__)
#else
#define FFLOG_TRACE(logger, ...) {}
#endif
#ifdef FFLOG_ENABLE_DEBUG
#define FFLOG_DEBUG(logger, ...) logger->log(spdlog::level::DEBUG, __VA_ARGS__)
#else
#define FFLOG_DEBUG(logger, ...) {}
#endif
#include "./details/logger_impl.h"
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