Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Olena
pylene
Commits
aa842f61
Commit
aa842f61
authored
Jan 05, 2015
by
Edwin Carlinet
Browse files
Use thread local stack for trace.
* mln/core/trace.hpp: thread local stack.
parent
8f84d165
Changes
1
Hide whitespace changes
Inline
Side-by-side
mln/core/trace.hpp
View file @
aa842f61
...
...
@@ -7,7 +7,11 @@
# include <iostream>
# include <stack>
# include <string>
# include <mutex>
//# include <mutex>
# include <thread>
# include <tbb/compat/thread>
# include <tbb/combinable.h>
# include <tbb/tick_count.h>
# define mln_entering(NAME) \
mln::trace::entering(NAME);
...
...
@@ -24,26 +28,29 @@ namespace mln
explicit
trace_t
(
const
std
::
string
&
fun
)
:
fname
(
fun
)
{
clock
=
std
::
clock
();
clock
=
tbb
::
tick_count
::
now
();
}
std
::
string
fname
;
std
::
clock_t
clock
;
std
::
string
fname
;
tbb
::
tick_count
clock
;
};
static
std
::
stack
<
trace_t
>
callstack
;
static
tbb
::
combinable
<
std
::
stack
<
trace_t
>
>
callstacks
;
//
static std::stack<trace_t> callstack;
static
bool
verbose
=
(
std
::
getenv
(
"TRACE"
)
!=
NULL
);
static
std
::
mutex
stack_mutex
;
//
static std::mutex stack_mutex;
static
inline
void
entering
(
const
std
::
string
&
fname
)
{
if
(
verbose
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
stack_mutex
);
//std::lock_guard<std::mutex> lock(stack_mutex);
std
::
stack
<
trace_t
>&
callstack
=
callstacks
.
local
();
callstack
.
emplace
(
fname
);
std
::
clog
<<
std
::
string
(
callstack
.
size
(),
' '
)
<<
fname
<<
std
::
endl
;
std
::
clog
<<
std
::
string
(
callstack
.
size
(),
' '
)
<<
"#"
<<
std
::
this_thread
::
get_id
()
<<
" - "
<<
fname
<<
std
::
endl
;
}
};
...
...
@@ -52,11 +59,13 @@ namespace mln
void
exiting
()
{
if
(
verbose
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
stack_mutex
);
//
std::lock_guard<std::mutex> lock(stack_mutex);
std
::
stack
<
trace_t
>&
callstack
=
callstacks
.
local
();
trace_t
tr
=
callstack
.
top
();
std
::
clog
<<
std
::
string
(
callstack
.
size
(),
' '
)
<<
tr
.
fname
<<
" in "
<<
((
float
)(
std
::
clock
()
-
tr
.
clock
)
/
CLOCKS_PER_SEC
)
<<
std
::
endl
;
std
::
clog
<<
std
::
string
(
callstack
.
size
(),
' '
)
<<
"#"
<<
std
::
this_thread
::
get_id
()
<<
" - "
<<
tr
.
fname
<<
" in "
<<
(
tbb
::
tick_count
::
now
()
-
tr
.
clock
).
seconds
()
<<
std
::
endl
;
callstack
.
pop
();
}
...
...
@@ -66,7 +75,9 @@ namespace mln
void
warn
(
const
std
::
string
&
msg
)
{
if
(
verbose
)
std
::
clog
<<
std
::
string
(
callstack
.
size
(),
' '
)
<<
msg
<<
std
::
endl
;
std
::
clog
<<
std
::
string
(
callstacks
.
local
().
size
(),
' '
)
<<
"#"
<<
std
::
this_thread
::
get_id
()
<<
" - "
<<
msg
<<
std
::
endl
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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