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
470c23ad
Commit
470c23ad
authored
Jan 27, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes and imprvts
parent
0bf2391d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
28 deletions
+33
-28
makefile
build/gcc/makefile
+3
-1
formatters.cpp
src/formatters.cpp
+10
-6
test.cpp
src/test.cpp
+20
-21
No files found.
build/gcc/makefile
View file @
470c23ad
...
...
@@ -17,7 +17,7 @@ OUTLIB_DEBUG = libc11log-debug.a
TEST_RELEASE
=
testme
TEST_DEBUG
=
testme-debug
.PHONY
:
all mkdirs release debug build clean
.PHONY
:
all mkdirs release debug build clean
rebuild
all
:
release
...
...
@@ -49,4 +49,6 @@ debug/%.o: $(SRC_DIR)/%.cpp
clean
:
rm
-rf
release debug daily.
*
$(TEST_RELEASE)
$(TEST_DEBUG)
$(OUTLIB_RELEASE)
$(OUTLIB_DEBUG)
rebuild
:
clean all
src/formatters.cpp
View file @
470c23ad
...
...
@@ -4,16 +4,20 @@
void
c11log
::
formatters
::
format_time
(
const
c11log
::
formatters
::
timepoint
&
tp
,
std
::
ostream
&
dest
)
{
std
::
tm
tm
=
details
::
os
::
localtime
(
std
::
chrono
::
system_clock
::
to_time_t
(
tp
));
//get ms
auto
duration
=
tp
.
time_since_epoch
();
int
millis
=
static_cast
<
int
>
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
duration
).
count
()
%
1000
);
//std::put_time(&tm, "[ %Y-%m-%d %H:%M:%S ]") - seems too slow
//auto duration = tp.time_since_epoch();
//int millis = static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000);
char
buf
[
64
];
auto
size
=
sprintf
(
buf
,
"[%d-%02d-%02d %02d:%02d:%02d
.%03d
]"
,
auto
size
=
sprintf
(
buf
,
"[%d-%02d-%02d %02d:%02d:%02d]"
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
,
millis
);
dest
.
write
(
buf
,
size
);
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
dest
.
write
(
buf
,
size
);
}
void
c11log
::
formatters
::
format_time
(
std
::
ostream
&
dest
)
...
...
src/test.cpp
View file @
470c23ad
...
...
@@ -13,49 +13,48 @@
int
main
(
int
argc
,
char
*
argv
[])
{
using
namespace
std
::
chrono
;
int
nthreads
=
argc
>
1
?
atoi
(
argv
[
1
])
:
1
;
int
nlines
=
argc
>
2
?
atoi
(
argv
[
2
])
:
1000000
;
auto
null_sink
=
std
::
make_shared
<
c11log
::
sinks
::
null_sink
>
();
auto
stdout_sink
=
std
::
make_shared
<
c11log
::
sinks
::
stdout_sink
>
();
auto
async
=
std
::
make_shared
<
c11log
::
sinks
::
async_sink
>
(
100
0
);
auto
async
=
std
::
make_shared
<
c11log
::
sinks
::
async_sink
>
(
100
);
//auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2);
auto
fsink
=
std
::
make_shared
<
c11log
::
sinks
::
daily_file_sink
>
(
"daily"
,
"txt"
);
async
->
add_sink
(
fsink
);
//async->add_sink(null_sink);
c11log
::
logger
logger
(
"test"
);
logger
.
add_sink
(
async
);
std
::
atomic
<
uint32_t
>
counter
{
0
};
auto
counter_ptr
=
&
counter
;
std
::
atomic
<
bool
>
active
{
true
};
auto
active_ptr
=
&
active
;
std
::
vector
<
std
::
thread
*>
threads
;
std
::
cout
<<
"Starting "
<<
nthreads
<<
" threads
for 3 seconds
.."
<<
std
::
endl
;
std
::
cout
<<
"Starting "
<<
nthreads
<<
" threads
x "
<<
utils
::
format
(
nlines
)
<<
" lines each
.."
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
nthreads
;
i
++
)
{
auto
t
=
new
std
::
thread
([
&
logger
,
counter_ptr
,
active_ptr
]()
{
while
(
*
active_ptr
)
auto
t
=
new
std
::
thread
([
&
logger
,
nlines
]()
{
for
(
int
i
=
0
;
i
<
nlines
;
++
i
)
{
logger
.
info
()
<<
"Hello from thread "
<<
std
::
this_thread
::
get_id
()
<<
"
\t
counter: "
<<
counter_ptr
->
load
();
(
*
counter_ptr
)
++
;
logger
.
info
()
<<
"Hello from thread "
<<
std
::
this_thread
::
get_id
()
<<
"
\t
counter: "
<<
i
;
}
});
threads
.
push_back
(
t
);
}
int
seconds
=
0
;
while
(
seconds
++
<
3
)
{
counter
=
0
;
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
1
));
std
::
cout
<<
"Counter = "
<<
utils
::
format
(
counter
.
load
())
<<
std
::
endl
;
}
active
=
false
;
auto
stime
=
steady_clock
::
now
();
for
(
auto
t
:
threads
)
t
->
join
();
async
->
shutdown
(
std
::
chrono
::
seconds
(
1
));
auto
delta
=
steady_clock
::
now
()
-
stime
;
auto
delta_seconds
=
duration_cast
<
milliseconds
>
(
delta
).
count
()
/
1000.0
;
auto
total
=
nthreads
*
nlines
;
std
::
cout
<<
"Total: "
<<
utils
::
format
(
total
)
<<
" = "
<<
utils
::
format
(
total
/
delta_seconds
)
<<
"/sec"
<<
std
::
endl
;
async
->
shutdown
(
seconds
(
1
));
return
0
;
}
...
...
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