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
9d9a955e
Commit
9d9a955e
authored
Mar 15, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
default format_time performance improvement
parent
38670cef
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
28 deletions
+41
-28
example.cpp
example/example.cpp
+1
-1
fast_oss.h
include/c11log/details/fast_oss.h
+5
-1
line_logger.h
include/c11log/details/line_logger.h
+1
-3
formatter.h
include/c11log/formatter.h
+34
-23
No files found.
example/example.cpp
View file @
9d9a955e
...
@@ -33,7 +33,7 @@ int main(int argc, char* argv[])
...
@@ -33,7 +33,7 @@ int main(int argc, char* argv[])
auto
start
=
system_clock
::
now
();
auto
start
=
system_clock
::
now
();
const
unsigned
int
howmany
=
5000000
;
const
unsigned
int
howmany
=
1
5000000
;
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
i
++
)
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
i
++
)
my_logger
.
info
()
<<
"Hello logger "
<<
i
;
my_logger
.
info
()
<<
"Hello logger "
<<
i
;
...
...
include/c11log/details/fast_oss.h
View file @
9d9a955e
...
@@ -27,7 +27,7 @@ public:
...
@@ -27,7 +27,7 @@ public:
return
_str
;
return
_str
;
}
}
void
clea
r
()
void
reset_st
r
()
{
{
_str
.
clear
();
_str
.
clear
();
}
}
...
@@ -68,6 +68,10 @@ public:
...
@@ -68,6 +68,10 @@ public:
{
{
return
_dev
.
str_ref
();
return
_dev
.
str_ref
();
}
}
void
reset_str
()
{
_dev
.
reset_str
();
}
private
:
private
:
str_devicebuf
_dev
;
str_devicebuf
_dev
;
...
...
include/c11log/details/line_logger.h
View file @
9d9a955e
...
@@ -42,9 +42,7 @@ public:
...
@@ -42,9 +42,7 @@ public:
// The move ctor should only be called on start of logging line,
// The move ctor should only be called on start of logging line,
// where no logging happened yet for this line so no need to copy the string from the other
// where no logging happened yet for this line so no need to copy the string from the other
_oss
(),
_oss
(),
_level
(
other
.
_level
)
_level
(
other
.
_level
)
{};
{
};
~
line_logger
()
~
line_logger
()
...
...
include/c11log/formatter.h
View file @
9d9a955e
...
@@ -6,9 +6,11 @@
...
@@ -6,9 +6,11 @@
#include <sstream>
#include <sstream>
#include <iomanip>
#include <iomanip>
#include <thread>
#include <thread>
#include <cstdlib>
#include "common_types.h"
#include "common_types.h"
#include "details/os.h"
#include "details/os.h"
#include "details/fast_oss.h"
namespace
c11log
namespace
c11log
{
{
...
@@ -35,7 +37,7 @@ public:
...
@@ -35,7 +37,7 @@ public:
{
{
_format_time
(
tp
,
dest
);
_format_time
(
tp
,
dest
);
if
(
!
logger_name
.
empty
())
if
(
!
logger_name
.
empty
())
dest
<<
" ["
<<
logger_name
<<
":"
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
dest
<<
" ["
<<
logger_name
<<
':'
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
else
else
dest
<<
" ["
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
dest
<<
" ["
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
...
@@ -48,35 +50,44 @@ private:
...
@@ -48,35 +50,44 @@ private:
}
//namespace c11log
}
//namespace c11log
// Format datetime like this: [2014-03-14 17:15:22]
inline
void
c11log
::
formatters
::
default_formatter
::
_format_time
(
const
log_clock
::
time_point
&
tp
,
std
::
ostream
&
dest
)
inline
void
c11log
::
formatters
::
default_formatter
::
_format_time
(
const
log_clock
::
time_point
&
tp
,
std
::
ostream
&
dest
)
{
{
using
namespace
c11log
::
details
::
os
;
using
namespace
std
::
chrono
;
#ifdef _MSC_VER
#ifdef _MSC_VER
__declspec
(
thread
)
static
std
::
tm
last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
__declspec
(
thread
)
static
std
::
tm
s_
last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
__declspec
(
thread
)
static
char
last_time_str
[
64
]
;
__declspec
(
thread
)
static
details
::
fast_oss
s_time_oss
;
#else
#else
thread_local
static
std
::
tm
last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
thread_local
static
char
last_time_str
[
64
];
thread_local
static
details
::
fast_oss
s_time_oss
;
thread_local
static
std
::
time_t
s_cache_time_t
=
0
;
#endif
#endif
auto
tm_now
=
details
::
os
::
localtime
(
log_clock
::
to_time_t
(
tp
));
using
namespace
c11log
::
details
::
os
;
std
::
time_t
tp_time_t
=
log_clock
::
to_time_t
(
tp
);
if
(
last_tm
!=
tm_now
)
//Cache every second
if
(
tp_time_t
!=
s_cache_time_t
)
{
{
#ifdef _MSC_VER
auto
tm_now
=
details
::
os
::
localtime
(
tp_time_t
);
::
sprintf_s
s_time_oss
.
reset_str
();
#else
s_time_oss
.
fill
(
'0'
);
::
snprintf
s_time_oss
<<
'['
<<
tm_now
.
tm_year
+
1900
<<
'-'
;
#endif
s_time_oss
.
width
(
2
);
(
last_time_str
,
sizeof
(
last_time_str
),
"[%d-%02d-%02d %02d:%02d:%02d]"
,
s_time_oss
<<
tm_now
.
tm_mon
+
1
<<
'-'
;
tm_now
.
tm_year
+
1900
,
s_time_oss
.
width
(
2
);
tm_now
.
tm_mon
+
1
,
s_time_oss
<<
tm_now
.
tm_mday
<<
' '
;
tm_now
.
tm_mday
,
s_time_oss
.
width
(
2
);
tm_now
.
tm_hour
,
s_time_oss
<<
tm_now
.
tm_hour
<<
':'
;
tm_now
.
tm_min
,
s_time_oss
.
width
(
2
);
tm_now
.
tm_sec
);
s_time_oss
<<
tm_now
.
tm_min
<<
':'
;
last_tm
=
tm_now
;
s_time_oss
.
width
(
2
);
s_time_oss
<<
tm_now
.
tm_sec
<<
']'
;
s_cache_time_t
=
tp_time_t
;
}
}
dest
<<
last_time_str
;
const
std
::
string
&
s
=
s_time_oss
.
str_ref
();
dest
.
write
(
s
.
c_str
(),
s
.
size
());
}
}
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