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
76436d07
Commit
76436d07
authored
Dec 07, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bench and examples updates
parent
58975841
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
346 deletions
+13
-346
bench/spdlog-bench-async.cpp
bench/spdlog-bench-async.cpp
+5
-1
bench/spdlog-bench-mt-async.cpp
bench/spdlog-bench-mt-async.cpp
+5
-3
example/bench.cpp
example/bench.cpp
+3
-8
include/spdlog/details/fast_istostr.h
include/spdlog/details/fast_istostr.h
+0
-130
include/spdlog/details/mpcs_q.h
include/spdlog/details/mpcs_q.h
+0
-204
No files found.
bench/spdlog-bench-async.cpp
View file @
76436d07
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
int
main
(
int
,
char
*
[])
int
main
(
int
,
char
*
[])
{
{
int
howmany
=
10
00000
;
int
howmany
=
10
48576
;
namespace
spd
=
spdlog
;
namespace
spd
=
spdlog
;
spd
::
set_async_mode
(
howmany
);
spd
::
set_async_mode
(
howmany
);
///Create a file rotating logger with 5mb size max and 3 rotated files
///Create a file rotating logger with 5mb size max and 3 rotated files
...
@@ -14,5 +14,9 @@ int main(int, char* [])
...
@@ -14,5 +14,9 @@ int main(int, char* [])
for
(
int
i
=
0
;
i
<
howmany
;
++
i
)
for
(
int
i
=
0
;
i
<
howmany
;
++
i
)
logger
->
info
()
<<
"spdlog message #"
<<
i
<<
": This is some text for your pleasure"
;
logger
->
info
()
<<
"spdlog message #"
<<
i
<<
": This is some text for your pleasure"
;
//because spdlog async logger waits for the back thread logger to finish all messages upon destrcuting,
//and we want to measure only the time it took to push those messages to the backthread..
abort
();
return
0
;
return
0
;
}
}
bench/spdlog-bench-mt-async.cpp
View file @
76436d07
...
@@ -14,10 +14,10 @@ int main(int argc, char* argv[])
...
@@ -14,10 +14,10 @@ int main(int argc, char* argv[])
if
(
argc
>
1
)
if
(
argc
>
1
)
thread_count
=
atoi
(
argv
[
1
]);
thread_count
=
atoi
(
argv
[
1
]);
int
howmany
=
10
00000
;
int
howmany
=
10
48576
;
namespace
spd
=
spdlog
;
namespace
spd
=
spdlog
;
spd
::
set_async_mode
(
howmany
,
std
::
chrono
::
seconds
(
0
)
);
spd
::
set_async_mode
(
howmany
);
///Create a file rotating logger with 5mb size max and 3 rotated files
///Create a file rotating logger with 5mb size max and 3 rotated files
auto
logger
=
spd
::
rotating_logger_mt
(
"file_logger"
,
"logs/spd-sample"
,
10
*
1024
*
1024
,
5
);
auto
logger
=
spd
::
rotating_logger_mt
(
"file_logger"
,
"logs/spd-sample"
,
10
*
1024
*
1024
,
5
);
...
@@ -45,5 +45,7 @@ int main(int argc, char* argv[])
...
@@ -45,5 +45,7 @@ int main(int argc, char* argv[])
t
.
join
();
t
.
join
();
};
};
return
0
;
//because spdlog async logger waits for the back thread logger to finish all messages upon destrcuting,
//and we want to measure only the time it took to push those messages to the backthread..
abort
();
}
}
example/bench.cpp
View file @
76436d07
...
@@ -50,7 +50,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
...
@@ -50,7 +50,7 @@ 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
=
10
00000
;
int
howmany
=
10
48576
;
int
threads
=
10
;
int
threads
=
10
;
bool
auto_flush
=
false
;
bool
auto_flush
=
false
;
int
file_size
=
30
*
1024
*
1024
;
int
file_size
=
30
*
1024
*
1024
;
...
@@ -94,17 +94,12 @@ int main(int argc, char* argv[])
...
@@ -94,17 +94,12 @@ int main(int argc, char* argv[])
spdlog
::
set_async_mode
(
howmany
);
spdlog
::
set_async_mode
(
howmany
);
for
(
int
i
=
0
;
i
<
3
;
++
i
)
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
{
auto
as
=
spdlog
::
daily_logger_st
(
"as"
,
"logs/daily_async"
,
auto_flush
);
auto
as
=
spdlog
::
daily_logger_st
(
"as"
,
"logs/daily_async"
,
auto_flush
);
//bench_mt(howmany, spdlog::create<null_sink_st>("as"), threads);
bench_mt
(
howmany
,
as
,
threads
);
bench_mt
(
howmany
,
as
,
threads
);
as
->
stop
();
spdlog
::
drop
(
"as"
);
spdlog
::
drop
(
"as"
);
}
}
spdlog
::
stop
();
}
}
catch
(
std
::
exception
&
ex
)
catch
(
std
::
exception
&
ex
)
{
{
...
...
include/spdlog/details/fast_istostr.h
deleted
100644 → 0
View file @
58975841
/*************************************************************************/
/* spdlog - an extremely fast and easy to use c++11 logging library. */
/* Copyright (c) 2014 Gabi Melman. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#pragma once
#include <string>
//Fast to int to string
//Base on :http://stackoverflow.com/a/4351484/192001
//Modified version to pad zeros according to padding arg
namespace
spdlog
{
namespace
details
{
const
char
digit_pairs
[
201
]
=
{
"00010203040506070809"
"10111213141516171819"
"20212223242526272829"
"30313233343536373839"
"40414243444546474849"
"50515253545556575859"
"60616263646566676869"
"70717273747576777879"
"80818283848586878889"
"90919293949596979899"
};
inline
std
::
string
&
fast_itostr
(
int
n
,
std
::
string
&
s
,
size_t
padding
)
{
if
(
n
==
0
)
{
s
=
std
::
string
(
padding
,
'0'
);
return
s
;
}
int
sign
=
-
(
n
<
0
);
unsigned
int
val
=
static_cast
<
unsigned
int
>
((
n
^
sign
)
-
sign
);
size_t
size
;
if
(
val
>=
10000
)
{
if
(
val
>=
10000000
)
{
if
(
val
>=
1000000000
)
size
=
10
;
else
if
(
val
>=
100000000
)
size
=
9
;
else
size
=
8
;
}
else
{
if
(
val
>=
1000000
)
size
=
7
;
else
if
(
val
>=
100000
)
size
=
6
;
else
size
=
5
;
}
}
else
{
if
(
val
>=
100
)
{
if
(
val
>=
1000
)
size
=
4
;
else
size
=
3
;
}
else
{
if
(
val
>=
10
)
size
=
2
;
else
size
=
1
;
}
}
size
-=
sign
;
if
(
size
<
padding
)
size
=
padding
;
s
.
resize
(
size
);
char
*
c
=
&
s
[
0
];
if
(
sign
)
*
c
=
'-'
;
c
+=
size
-
1
;
while
(
val
>=
100
)
{
size_t
pos
=
val
%
100
;
val
/=
100
;
*
(
short
*
)(
c
-
1
)
=
*
(
short
*
)(
digit_pairs
+
2
*
pos
);
c
-=
2
;
}
while
(
val
>
0
)
{
*
c
--
=
static_cast
<
char
>
(
'0'
+
(
val
%
10
));
val
/=
10
;
}
while
(
c
>=
s
.
data
())
*
c
--
=
'0'
;
return
s
;
}
}
}
include/spdlog/details/mpcs_q.h
deleted
100644 → 0
View file @
58975841
/*
A modified version of Intrusive MPSC node-based queue
Original code from
http://www.1024cores.net/home/lock-free-algorithms/queues/intrusive-mpsc-node-based-queue
licensed by Dmitry Vyukov under the terms below:
Simplified BSD license
Copyright (c) 2010-2011 Dmitry Vyukov. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY DMITRY VYUKOV "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL DMITRY VYUKOV OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the authors and
should not be interpreted as representing official policies, either expressed or implied, of Dmitry Vyukov.
*/
/*************************************************************************/
/********* The code in its current form adds the license below: **********/
/*************************************************************************/
/* spdlog - an extremely fast and easy to use c++11 logging library. */
/* Copyright (c) 2014 Gabi Melman. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#pragma once
#include <atomic>
namespace
spdlog
{
namespace
details
{
template
<
typename
T
>
class
mpsc_q
{
public:
using
item_type
=
T
;
explicit
mpsc_q
(
size_t
max_size
)
:
_max_size
(
max_size
),
_size
(
0
),
_stub
(),
_head
(
&
_stub
),
_tail
(
&
_stub
)
{
}
mpsc_q
(
const
mpsc_q
&
)
=
delete
;
mpsc_q
&
operator
=
(
const
mpsc_q
&
)
=
delete
;
~
mpsc_q
()
{
clear
();
}
template
<
typename
TT
>
bool
push
(
TT
&&
val
)
{
if
(
_size
>=
_max_size
)
return
false
;
mpscq_node_t
*
new_node
=
new
mpscq_node_t
(
std
::
forward
<
TT
>
(
val
));
push_node
(
new_node
);
++
_size
;
return
true
;
}
// Try to pop or return false immediatly is queue is empty
bool
pop
(
T
&
value
)
{
mpscq_node_t
*
node
=
pop_node
();
if
(
node
!=
nullptr
)
{
--
_size
;
value
=
std
::
move
(
node
->
value
);
delete
(
node
);
return
true
;
}
else
{
return
false
;
}
}
// Empty the queue by popping all its elements
void
clear
()
{
while
(
mpscq_node_t
*
node
=
pop_node
())
{
--
_size
;
delete
(
node
);
}
}
// Return approx size
size_t
approx_size
()
const
{
return
_size
.
load
();
}
private:
struct
mpscq_node_t
{
std
::
atomic
<
mpscq_node_t
*>
next
;
T
value
;
mpscq_node_t
()
:
next
(
nullptr
)
{}
mpscq_node_t
(
const
mpscq_node_t
&
)
=
delete
;
mpscq_node_t
&
operator
=
(
const
mpscq_node_t
&
)
=
delete
;
explicit
mpscq_node_t
(
const
T
&
val
)
:
next
(
nullptr
),
value
(
val
)
{}
explicit
mpscq_node_t
(
T
&&
val
)
:
next
(
nullptr
),
value
(
std
::
move
(
val
))
{}
};
size_t
_max_size
;
std
::
atomic
<
size_t
>
_size
;
mpscq_node_t
_stub
;
std
::
atomic
<
mpscq_node_t
*>
_head
;
mpscq_node_t
*
_tail
;
// Lockfree push
void
push_node
(
mpscq_node_t
*
n
)
{
n
->
next
=
nullptr
;
mpscq_node_t
*
prev
=
_head
.
exchange
(
n
);
prev
->
next
=
n
;
}
// Clever lockfree pop algorithm by Dmitry Vyukov using single xchng instruction..
// Return pointer to the poppdc node or nullptr if no items left in the queue
mpscq_node_t
*
pop_node
()
{
mpscq_node_t
*
tail
=
_tail
;
mpscq_node_t
*
next
=
tail
->
next
;
if
(
tail
==
&
_stub
)
{
if
(
nullptr
==
next
)
return
nullptr
;
_tail
=
next
;
tail
=
next
;
next
=
next
->
next
;
}
if
(
next
)
{
_tail
=
next
;
return
tail
;
}
mpscq_node_t
*
head
=
_head
;
if
(
tail
!=
head
)
return
nullptr
;
push_node
(
&
_stub
);
next
=
tail
->
next
;
if
(
next
)
{
_tail
=
next
;
return
tail
;
}
return
nullptr
;
}
};
}
}
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