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
e3c3f91c
Commit
e3c3f91c
authored
Dec 22, 2015
by
Gabi Melman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #153 from ksergey/clock_tweak
Added CLOCK_MONOTONIC trick
parents
01f3d6f5
9e8c8c11
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
1 deletion
+31
-1
include/spdlog/details/os.h
include/spdlog/details/os.h
+23
-1
include/spdlog/tweakme.h
include/spdlog/tweakme.h
+8
-0
No files found.
include/spdlog/details/os.h
View file @
e3c3f91c
...
...
@@ -35,6 +35,20 @@ namespace details
namespace
os
{
#if defined __linux__ && defined SPDLOG_CLOCK_MONOTONIC
inline
uint64_t
clock_offset
()
{
timespec
ts_realtime
;
::
clock_gettime
(
CLOCK_REALTIME
,
&
ts_realtime
);
timespec
ts_monotonic
;
::
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts_monotonic
);
const
uint64_t
realtime
=
ts_realtime
.
tv_sec
*
1000000000
+
ts_realtime
.
tv_nsec
;
const
uint64_t
monotonic
=
ts_monotonic
.
tv_sec
*
1000000000
+
ts_monotonic
.
tv_nsec
;
return
realtime
-
monotonic
;
}
#endif
inline
spdlog
::
log_clock
::
time_point
now
()
{
...
...
@@ -45,6 +59,14 @@ inline spdlog::log_clock::time_point now()
std
::
chrono
::
duration_cast
<
typename
log_clock
::
duration
>
(
std
::
chrono
::
seconds
(
ts
.
tv_sec
)
+
std
::
chrono
::
nanoseconds
(
ts
.
tv_nsec
)));
#elif defined __linux__ && defined SPDLOG_CLOCK_MONOTONIC
static
const
auto
offset
=
std
::
chrono
::
nanoseconds
(
clock_offset
());
timespec
ts
;
::
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
return
std
::
chrono
::
time_point
<
log_clock
,
typename
log_clock
::
duration
>
(
std
::
chrono
::
duration_cast
<
typename
log_clock
::
duration
>
(
offset
+
std
::
chrono
::
seconds
(
ts
.
tv_sec
)
+
std
::
chrono
::
nanoseconds
(
ts
.
tv_nsec
)));
#else
return
log_clock
::
now
();
#endif
...
...
@@ -151,7 +173,7 @@ inline bool file_exists(const std::string& filename)
#elif __linux__
struct
stat
buffer
;
return
(
stat
(
filename
.
c_str
(),
&
buffer
)
==
0
);
#else
#else
auto
*
file
=
fopen
(
filename
.
c_str
(),
"r"
);
if
(
file
!=
nullptr
)
{
...
...
include/spdlog/tweakme.h
View file @
e3c3f91c
...
...
@@ -17,6 +17,14 @@
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Under Linux, the much faster CLOCK_MONOTONIC clock can be used.
// This clock is more accurate than CLOCK_REALTIME_COARSE and faster than regular clock.
// Uncomment to use it instead of the regular clock.
// #define SPDLOG_CLOCK_MONOTONIC
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Uncomment if date/time logging is not needed.
// This will prevent spdlog from quering the clock on each log call.
...
...
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