Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
16ee72da
Commit
16ee72da
authored
Jul 10, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang format
parent
d409e536
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
207 additions
and
211 deletions
+207
-211
bench/bench.cpp
bench/bench.cpp
+2
-3
bench/latency.cpp
bench/latency.cpp
+6
-10
include/spdlog/details/fmt_helper.h
include/spdlog/details/fmt_helper.h
+5
-5
include/spdlog/details/logger_impl.h
include/spdlog/details/logger_impl.h
+17
-17
include/spdlog/details/pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+4
-4
include/spdlog/details/thread_pool.h
include/spdlog/details/thread_pool.h
+161
-161
include/spdlog/logger.h
include/spdlog/logger.h
+3
-3
include/spdlog/sinks/rotating_file_sink.h
include/spdlog/sinks/rotating_file_sink.h
+9
-8
No files found.
bench/bench.cpp
View file @
16ee72da
...
@@ -32,7 +32,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
...
@@ -32,7 +32,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
howmany
=
1000000
;
int
howmany
=
1000000
;
int
queue_size
=
howmany
+
2
;
int
queue_size
=
howmany
+
2
;
int
threads
=
10
;
int
threads
=
10
;
...
...
bench/latency.cpp
View file @
16ee72da
...
@@ -29,7 +29,7 @@ using namespace utils;
...
@@ -29,7 +29,7 @@ using namespace utils;
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
);
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
);
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
);
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
);
int
main
(
int
,
char
*
[])
int
main
(
int
,
char
*
[])
{
{
std
::
srand
(
static_cast
<
unsigned
>
(
std
::
time
(
nullptr
)));
// use current time as seed for random generator
std
::
srand
(
static_cast
<
unsigned
>
(
std
::
time
(
nullptr
)));
// use current time as seed for random generator
int
howmany
=
1000000
;
int
howmany
=
1000000
;
...
@@ -91,7 +91,6 @@ int main(int , char *[])
...
@@ -91,7 +91,6 @@ int main(int , char *[])
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
)
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
)
{
{
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
...
@@ -106,10 +105,10 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
...
@@ -106,10 +105,10 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
auto
start
=
high_resolution_clock
::
now
();
auto
start
=
high_resolution_clock
::
now
();
log
->
info
(
"Hello logger: msg number {}"
,
i
);
log
->
info
(
"Hello logger: msg number {}"
,
i
);
auto
delta_nanos
=
chrono
::
duration_cast
<
nanoseconds
>
(
high_resolution_clock
::
now
()
-
start
);
auto
delta_nanos
=
chrono
::
duration_cast
<
nanoseconds
>
(
high_resolution_clock
::
now
()
-
start
);
total_nanos
+=
delta_nanos
;
total_nanos
+=
delta_nanos
;
}
}
auto
avg
=
total_nanos
.
count
()
/
howmany
;
auto
avg
=
total_nanos
.
count
()
/
howmany
;
cout
<<
format
(
avg
)
<<
" ns/call"
<<
endl
;
cout
<<
format
(
avg
)
<<
" ns/call"
<<
endl
;
}
}
...
@@ -131,7 +130,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
...
@@ -131,7 +130,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
auto
start
=
high_resolution_clock
::
now
();
auto
start
=
high_resolution_clock
::
now
();
log
->
info
(
"Hello logger: msg number {}"
,
j
);
log
->
info
(
"Hello logger: msg number {}"
,
j
);
auto
delta_nanos
=
chrono
::
duration_cast
<
nanoseconds
>
(
high_resolution_clock
::
now
()
-
start
);
auto
delta_nanos
=
chrono
::
duration_cast
<
nanoseconds
>
(
high_resolution_clock
::
now
()
-
start
);
total_nanos
+=
delta_nanos
.
count
();
total_nanos
+=
delta_nanos
.
count
();
}
}
}));
}));
}
}
...
@@ -141,9 +140,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
...
@@ -141,9 +140,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
t
.
join
();
t
.
join
();
};
};
auto
avg
=
total_nanos
/
howmany
;
auto
avg
=
total_nanos
/
howmany
;
cout
<<
format
(
avg
)
<<
" ns/call"
<<
endl
;
cout
<<
format
(
avg
)
<<
" ns/call"
<<
endl
;
}
}
include/spdlog/details/fmt_helper.h
View file @
16ee72da
...
@@ -9,14 +9,14 @@ namespace spdlog {
...
@@ -9,14 +9,14 @@ namespace spdlog {
namespace
details
{
namespace
details
{
namespace
fmt_helper
{
namespace
fmt_helper
{
template
<
size_t
Buffer_Size
>
template
<
size_t
Buffer_Size
>
inline
void
append_str
(
const
std
::
string
&
str
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
inline
void
append_str
(
const
std
::
string
&
str
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
{
auto
*
str_ptr
=
str
.
data
();
auto
*
str_ptr
=
str
.
data
();
dest
.
append
(
str_ptr
,
str_ptr
+
str
.
size
());
dest
.
append
(
str_ptr
,
str_ptr
+
str
.
size
());
}
}
template
<
size_t
Buffer_Size
>
template
<
size_t
Buffer_Size
>
inline
void
append_c_str
(
const
char
*
c_str
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
inline
void
append_c_str
(
const
char
*
c_str
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
{
char
ch
;
char
ch
;
...
@@ -41,7 +41,7 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
...
@@ -41,7 +41,7 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
dest
.
append
(
i
.
data
(),
i
.
data
()
+
i
.
size
());
dest
.
append
(
i
.
data
(),
i
.
data
()
+
i
.
size
());
}
}
template
<
size_t
Buffer_Size
>
template
<
size_t
Buffer_Size
>
inline
void
pad2
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
inline
void
pad2
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
{
if
(
n
>
99
)
if
(
n
>
99
)
...
@@ -65,7 +65,7 @@ inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
...
@@ -65,7 +65,7 @@ inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
fmt
::
format_to
(
dest
,
"{:02}"
,
n
);
fmt
::
format_to
(
dest
,
"{:02}"
,
n
);
}
}
template
<
size_t
Buffer_Size
>
template
<
size_t
Buffer_Size
>
inline
void
pad3
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
inline
void
pad3
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
{
if
(
n
>
99
)
if
(
n
>
99
)
...
@@ -91,7 +91,7 @@ inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
...
@@ -91,7 +91,7 @@ inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
fmt
::
format_to
(
dest
,
"{:03}"
,
n
);
fmt
::
format_to
(
dest
,
"{:03}"
,
n
);
}
}
template
<
size_t
Buffer_Size
>
template
<
size_t
Buffer_Size
>
inline
void
pad6
(
size_t
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
inline
void
pad6
(
size_t
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
{
// todo: maybe replace this implementation with
// todo: maybe replace this implementation with
...
...
include/spdlog/details/logger_impl.h
View file @
16ee72da
include/spdlog/details/pattern_formatter.h
View file @
16ee72da
...
@@ -120,7 +120,7 @@ class c_formatter SPDLOG_FINAL : public flag_formatter
...
@@ -120,7 +120,7 @@ class c_formatter SPDLOG_FINAL : public flag_formatter
{
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
{
//fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday);
//
fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday);
// date
// date
fmt_helper
::
append_str
(
days
[
tm_time
.
tm_wday
],
dest
);
fmt_helper
::
append_str
(
days
[
tm_time
.
tm_wday
],
dest
);
dest
.
push_back
(
' '
);
dest
.
push_back
(
' '
);
...
@@ -496,7 +496,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
...
@@ -496,7 +496,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
// cache the millis part for the next milli.
// cache the millis part for the next milli.
auto
millis
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
duration
).
count
()
%
1000
;
auto
millis
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
duration
).
count
()
%
1000
;
if
(
millis
!=
millis_cache_timestamp_
||
cached_millis_
.
size
()
==
0
)
if
(
millis
!=
millis_cache_timestamp_
||
cached_millis_
.
size
()
==
0
)
{
{
cached_millis_
.
resize
(
0
);
cached_millis_
.
resize
(
0
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
),
cached_millis_
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
),
cached_millis_
);
...
@@ -528,8 +528,8 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
...
@@ -528,8 +528,8 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
}
}
private:
private:
std
::
chrono
::
seconds
cache_timestamp_
{
0
};
std
::
chrono
::
seconds
cache_timestamp_
{
0
};
std
::
chrono
::
milliseconds
::
rep
millis_cache_timestamp_
{
0
};
std
::
chrono
::
milliseconds
::
rep
millis_cache_timestamp_
{
0
};
fmt
::
basic_memory_buffer
<
char
,
128
>
cached_datetime_
;
fmt
::
basic_memory_buffer
<
char
,
128
>
cached_datetime_
;
fmt
::
basic_memory_buffer
<
char
,
8
>
cached_millis_
;
fmt
::
basic_memory_buffer
<
char
,
8
>
cached_millis_
;
};
};
...
...
include/spdlog/details/thread_pool.h
View file @
16ee72da
...
@@ -10,21 +10,21 @@
...
@@ -10,21 +10,21 @@
#include <vector>
#include <vector>
namespace
spdlog
{
namespace
spdlog
{
namespace
details
{
namespace
details
{
using
async_logger_ptr
=
std
::
shared_ptr
<
spdlog
::
async_logger
>
;
using
async_logger_ptr
=
std
::
shared_ptr
<
spdlog
::
async_logger
>
;
enum
class
async_msg_type
enum
class
async_msg_type
{
{
log
,
log
,
flush
,
flush
,
terminate
terminate
};
};
// Async msg to move to/from the queue
// Async msg to move to/from the queue
// Movable only. should never be copied
// Movable only. should never be copied
struct
async_msg
struct
async_msg
{
{
async_msg_type
msg_type
;
async_msg_type
msg_type
;
level
::
level_enum
level
;
level
::
level_enum
level
;
log_clock
::
time_point
time
;
log_clock
::
time_point
time
;
...
@@ -39,7 +39,9 @@ namespace spdlog {
...
@@ -39,7 +39,9 @@ namespace spdlog {
// should only be moved in or out of the queue..
// should only be moved in or out of the queue..
async_msg
(
const
async_msg
&
)
=
delete
;
async_msg
(
const
async_msg
&
)
=
delete
;
#if defined(_MSC_VER) && _MSC_VER <= 1800 // support for vs2013 move
// support for vs2013 move
#if defined(_MSC_VER) && _MSC_VER <= 1800
async_msg
(
async_msg
&&
other
)
SPDLOG_NOEXCEPT
:
msg_type
(
other
.
msg_type
),
async_msg
(
async_msg
&&
other
)
SPDLOG_NOEXCEPT
:
msg_type
(
other
.
msg_type
),
level
(
other
.
level
),
level
(
other
.
level
),
time
(
other
.
time
),
time
(
other
.
time
),
...
@@ -61,7 +63,7 @@ namespace spdlog {
...
@@ -61,7 +63,7 @@ namespace spdlog {
worker_ptr
=
std
::
move
(
other
.
worker_ptr
);
worker_ptr
=
std
::
move
(
other
.
worker_ptr
);
return
*
this
;
return
*
this
;
}
}
#else
#else
// (_MSC_VER) && _MSC_VER <= 1800
async_msg
(
async_msg
&&
other
)
=
default
;
async_msg
(
async_msg
&&
other
)
=
default
;
async_msg
&
operator
=
(
async_msg
&&
other
)
=
default
;
async_msg
&
operator
=
(
async_msg
&&
other
)
=
default
;
#endif
#endif
...
@@ -100,11 +102,11 @@ namespace spdlog {
...
@@ -100,11 +102,11 @@ namespace spdlog {
msg
.
color_range_start
=
0
;
msg
.
color_range_start
=
0
;
msg
.
color_range_end
=
0
;
msg
.
color_range_end
=
0
;
}
}
};
};
class
thread_pool
class
thread_pool
{
{
public:
public:
using
item_type
=
async_msg
;
using
item_type
=
async_msg
;
using
q_type
=
details
::
mpmc_blocking_queue
<
item_type
>
;
using
q_type
=
details
::
mpmc_blocking_queue
<
item_type
>
;
using
clock_type
=
std
::
chrono
::
steady_clock
;
using
clock_type
=
std
::
chrono
::
steady_clock
;
...
@@ -154,7 +156,7 @@ namespace spdlog {
...
@@ -154,7 +156,7 @@ namespace spdlog {
post_async_msg_
(
async_msg
(
std
::
move
(
worker_ptr
),
async_msg_type
::
flush
),
overflow_policy
);
post_async_msg_
(
async_msg
(
std
::
move
(
worker_ptr
),
async_msg_type
::
flush
),
overflow_policy
);
}
}
private:
private:
q_type
q_
;
q_type
q_
;
std
::
vector
<
std
::
thread
>
threads_
;
std
::
vector
<
std
::
thread
>
threads_
;
...
@@ -173,9 +175,7 @@ namespace spdlog {
...
@@ -173,9 +175,7 @@ namespace spdlog {
void
worker_loop_
()
void
worker_loop_
()
{
{
while
(
process_next_msg_
())
while
(
process_next_msg_
())
{};
{
};
}
}
// process next message in the queue
// process next message in the queue
...
@@ -213,7 +213,7 @@ namespace spdlog {
...
@@ -213,7 +213,7 @@ namespace spdlog {
assert
(
false
);
assert
(
false
);
return
true
;
// should not be reached
return
true
;
// should not be reached
}
}
};
};
}
// namespace details
}
// namespace details
}
// namespace spdlog
}
// namespace spdlog
\ No newline at end of file
include/spdlog/logger.h
View file @
16ee72da
include/spdlog/sinks/rotating_file_sink.h
View file @
16ee72da
...
@@ -101,7 +101,8 @@ private:
...
@@ -101,7 +101,8 @@ private:
details
::
os
::
remove
(
target
);
details
::
os
::
remove
(
target
);
if
(
details
::
os
::
rename
(
src
,
target
)
!=
0
)
if
(
details
::
os
::
rename
(
src
,
target
)
!=
0
)
{
{
throw
spdlog_ex
(
"rotating_file_sink: failed renaming "
+
filename_to_str
(
src
)
+
" to "
+
filename_to_str
(
target
),
errno
);
throw
spdlog_ex
(
"rotating_file_sink: failed renaming "
+
filename_to_str
(
src
)
+
" to "
+
filename_to_str
(
target
),
errno
);
}
}
}
}
}
}
...
...
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