Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
50403ea0
Commit
50403ea0
authored
Sep 21, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Give CAF threads recognizable names for debugging
parent
0f333bb3
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
116 additions
and
15 deletions
+116
-15
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+1
-0
libcaf_core/caf/detail/set_thread_name.hpp
libcaf_core/caf/detail/set_thread_name.hpp
+29
-0
libcaf_core/caf/scheduler/coordinator.hpp
libcaf_core/caf/scheduler/coordinator.hpp
+7
-3
libcaf_core/caf/scheduler/worker.hpp
libcaf_core/caf/scheduler/worker.hpp
+5
-3
libcaf_core/src/blocking_actor.cpp
libcaf_core/src/blocking_actor.cpp
+8
-7
libcaf_core/src/logger.cpp
libcaf_core/src/logger.cpp
+2
-0
libcaf_core/src/private_thread.cpp
libcaf_core/src/private_thread.cpp
+2
-0
libcaf_core/src/set_thread_name.cpp
libcaf_core/src/set_thread_name.cpp
+57
-0
libcaf_core/test/thread_hook.cpp
libcaf_core/test/thread_hook.cpp
+3
-2
libcaf_io/src/middleman.cpp
libcaf_io/src/middleman.cpp
+2
-0
No files found.
libcaf_core/CMakeLists.txt
View file @
50403ea0
...
@@ -98,6 +98,7 @@ set(LIBCAF_CORE_SRCS
...
@@ -98,6 +98,7 @@ set(LIBCAF_CORE_SRCS
src/sec.cpp
src/sec.cpp
src/sequencer.cpp
src/sequencer.cpp
src/serializer.cpp
src/serializer.cpp
src/set_thread_name.cpp
src/shared_spinlock.cpp
src/shared_spinlock.cpp
src/simple_actor_clock.cpp
src/simple_actor_clock.cpp
src/skip.cpp
src/skip.cpp
...
...
libcaf_core/caf/detail/set_thread_name.hpp
0 → 100644
View file @
50403ea0
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
namespace
caf
{
namespace
detail
{
/// Sets the name thread shown by the OS. Not supported on all plattforms
/// (no-op on Windows).
void
set_thread_name
(
const
char
*
name
);
}
// namespace detail
}
// namespace caf
libcaf_core/caf/scheduler/coordinator.hpp
View file @
50403ea0
...
@@ -25,10 +25,10 @@
...
@@ -25,10 +25,10 @@
#include <memory>
#include <memory>
#include <condition_variable>
#include <condition_variable>
#include "caf/scheduler/worker.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/detail/thread_safe_actor_clock.hpp"
#include "caf/detail/thread_safe_actor_clock.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/scheduler/worker.hpp"
namespace
caf
{
namespace
caf
{
namespace
scheduler
{
namespace
scheduler
{
...
@@ -75,7 +75,11 @@ protected:
...
@@ -75,7 +75,11 @@ protected:
// Launch an additional background thread for dispatching timeouts and
// Launch an additional background thread for dispatching timeouts and
// delayed messages.
// delayed messages.
timer_
=
std
::
thread
{[
&
]
{
timer_
=
std
::
thread
{[
&
]
{
CAF_SET_LOGGER_SYS
(
&
system
());
detail
::
set_thread_name
(
"caf.clock"
);
system
().
thread_started
();
clock_
.
run_dispatch_loop
();
clock_
.
run_dispatch_loop
();
system
().
thread_terminates
();
}};
}};
// Run remaining startup code.
// Run remaining startup code.
super
::
start
();
super
::
start
();
...
...
libcaf_core/caf/scheduler/worker.hpp
View file @
50403ea0
...
@@ -20,11 +20,11 @@
...
@@ -20,11 +20,11 @@
#include <cstddef>
#include <cstddef>
#include "caf/detail/double_ended_queue.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/execution_unit.hpp"
#include "caf/logger.hpp"
#include "caf/logger.hpp"
#include "caf/resumable.hpp"
#include "caf/resumable.hpp"
#include "caf/execution_unit.hpp"
#include "caf/detail/double_ended_queue.hpp"
namespace
caf
{
namespace
caf
{
namespace
scheduler
{
namespace
scheduler
{
...
@@ -54,6 +54,8 @@ public:
...
@@ -54,6 +54,8 @@ public:
CAF_ASSERT
(
this_thread_
.
get_id
()
==
std
::
thread
::
id
{});
CAF_ASSERT
(
this_thread_
.
get_id
()
==
std
::
thread
::
id
{});
auto
this_worker
=
this
;
auto
this_worker
=
this
;
this_thread_
=
std
::
thread
{[
this_worker
]
{
this_thread_
=
std
::
thread
{[
this_worker
]
{
CAF_SET_LOGGER_SYS
(
&
this_worker
->
system
());
detail
::
set_thread_name
(
"caf.multiplexer"
);
this_worker
->
system
().
thread_started
();
this_worker
->
system
().
thread_started
();
this_worker
->
run
();
this_worker
->
run
();
this_worker
->
system
().
thread_terminates
();
this_worker
->
system
().
thread_terminates
();
...
...
libcaf_core/src/blocking_actor.cpp
View file @
50403ea0
...
@@ -16,17 +16,17 @@
...
@@ -16,17 +16,17 @@
* http://www.boost.org/LICENSE_1_0.txt. *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
******************************************************************************/
#include <utility>
#include "caf/blocking_actor.hpp"
#include "caf/blocking_actor.hpp"
#include "caf/logger.hpp"
#include <utility>
#include "caf/actor_system.hpp"
#include "caf/actor_registry.hpp"
#include "caf/
detail/sync_request_bouncer
.hpp"
#include "caf/
actor_registry
.hpp"
#include "caf/
detail/invoke_result_visitor
.hpp"
#include "caf/
actor_system
.hpp"
#include "caf/detail/default_invoke_result_visitor.hpp"
#include "caf/detail/default_invoke_result_visitor.hpp"
#include "caf/detail/invoke_result_visitor.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/detail/sync_request_bouncer.hpp"
#include "caf/logger.hpp"
namespace
caf
{
namespace
caf
{
...
@@ -92,6 +92,7 @@ void blocking_actor::launch(execution_unit*, bool, bool hide) {
...
@@ -92,6 +92,7 @@ void blocking_actor::launch(execution_unit*, bool, bool hide) {
home_system
().
inc_detached_threads
();
home_system
().
inc_detached_threads
();
std
::
thread
([](
strong_actor_ptr
ptr
)
{
std
::
thread
([](
strong_actor_ptr
ptr
)
{
// actor lives in its own thread
// actor lives in its own thread
detail
::
set_thread_name
(
"caf.actor"
);
ptr
->
home_system
->
thread_started
();
ptr
->
home_system
->
thread_started
();
auto
this_ptr
=
ptr
->
get
();
auto
this_ptr
=
ptr
->
get
();
CAF_ASSERT
(
dynamic_cast
<
blocking_actor
*>
(
this_ptr
)
!=
nullptr
);
CAF_ASSERT
(
dynamic_cast
<
blocking_actor
*>
(
this_ptr
)
!=
nullptr
);
...
...
libcaf_core/src/logger.cpp
View file @
50403ea0
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include "caf/defaults.hpp"
#include "caf/defaults.hpp"
#include "caf/detail/get_process_id.hpp"
#include "caf/detail/get_process_id.hpp"
#include "caf/detail/pretty_type_name.hpp"
#include "caf/detail/pretty_type_name.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/intrusive/task_result.hpp"
#include "caf/intrusive/task_result.hpp"
#include "caf/local_actor.hpp"
#include "caf/local_actor.hpp"
#include "caf/locks.hpp"
#include "caf/locks.hpp"
...
@@ -555,6 +556,7 @@ void logger::start() {
...
@@ -555,6 +556,7 @@ void logger::start() {
log_first_line
();
log_first_line
();
else
else
thread_
=
std
::
thread
{[
this
]
{
thread_
=
std
::
thread
{[
this
]
{
detail
::
set_thread_name
(
"caf.logger"
);
this
->
system_
.
thread_started
();
this
->
system_
.
thread_started
();
this
->
run
();
this
->
run
();
this
->
system_
.
thread_terminates
();
this
->
system_
.
thread_terminates
();
...
...
libcaf_core/src/private_thread.cpp
View file @
50403ea0
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include "caf/detail/private_thread.hpp"
#include "caf/detail/private_thread.hpp"
#include "caf/config.hpp"
#include "caf/config.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/logger.hpp"
#include "caf/logger.hpp"
#include "caf/scheduled_actor.hpp"
#include "caf/scheduled_actor.hpp"
...
@@ -87,6 +88,7 @@ void private_thread::shutdown() {
...
@@ -87,6 +88,7 @@ void private_thread::shutdown() {
}
}
void
private_thread
::
exec
(
private_thread
*
this_ptr
)
{
void
private_thread
::
exec
(
private_thread
*
this_ptr
)
{
detail
::
set_thread_name
(
"caf.actor"
);
this_ptr
->
system_
.
thread_started
();
this_ptr
->
system_
.
thread_started
();
this_ptr
->
run
();
this_ptr
->
run
();
// make sure to not destroy the private thread object before the
// make sure to not destroy the private thread object before the
...
...
libcaf_core/src/set_thread_name.cpp
0 → 100644
View file @
50403ea0
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/set_thread_name.hpp"
#include "caf/config.hpp"
#ifndef CAF_WINDOWS
#include <pthread.h>
#endif // CAF_WINDOWS
#if defined(CAF_LINUX)
#include <sys/prctl.h>
#elif defined(CAF_BSD)
#include <pthread_np.h>
#endif // defined(...)
#include <thread>
#include <type_traits>
namespace
caf
{
namespace
detail
{
void
set_thread_name
(
const
char
*
name
)
{
CAF_IGNORE_UNUSED
(
name
);
#ifdef CAF_WINDOWS
// nop
#else // CAF_WINDOWS
static_assert
(
std
::
is_same
<
std
::
thread
::
native_handle_type
,
pthread_t
>::
value
,
"std::thread not based on pthread_t"
);
#if defined(CAF_MACOS)
pthread_setname_np
(
name
);
#elif defined(CAF_LINUX)
prctl
(
PR_SET_NAME
,
name
,
0
,
0
,
0
);
#elif defined(CAF_BSD)
pthread_set_name_np
(
pthread_self
(),
name
);
#endif // defined(...)
#endif // CAF_WINDOWS
}
}
// namespace detail
}
// namespace caf
libcaf_core/test/thread_hook.cpp
View file @
50403ea0
...
@@ -118,7 +118,8 @@ CAF_TEST_FIXTURE_SCOPE(counting_hook, fixture<counting_thread_hook>)
...
@@ -118,7 +118,8 @@ CAF_TEST_FIXTURE_SCOPE(counting_hook, fixture<counting_thread_hook>)
CAF_TEST
(
counting_system_without_actor
)
{
CAF_TEST
(
counting_system_without_actor
)
{
assumed_init_calls
=
1
;
assumed_init_calls
=
1
;
assumed_thread_count
=
get_or
(
cfg
,
"scheduler.max-threads"
,
assumed_thread_count
=
get_or
(
cfg
,
"scheduler.max-threads"
,
defaults
::
scheduler
::
max_threads
);
defaults
::
scheduler
::
max_threads
)
+
1
;
// caf.clock thread
auto
&
sched
=
sys
.
scheduler
();
auto
&
sched
=
sys
.
scheduler
();
if
(
sched
.
detaches_utility_actors
())
if
(
sched
.
detaches_utility_actors
())
assumed_thread_count
+=
sched
.
num_utility_actors
();
assumed_thread_count
+=
sched
.
num_utility_actors
();
...
@@ -128,7 +129,7 @@ CAF_TEST(counting_system_with_actor) {
...
@@ -128,7 +129,7 @@ CAF_TEST(counting_system_with_actor) {
assumed_init_calls
=
1
;
assumed_init_calls
=
1
;
assumed_thread_count
=
get_or
(
cfg
,
"scheduler.max-threads"
,
assumed_thread_count
=
get_or
(
cfg
,
"scheduler.max-threads"
,
defaults
::
scheduler
::
max_threads
)
defaults
::
scheduler
::
max_threads
)
+
1
;
+
2
;
// caf.clock thread plus detached actor
auto
&
sched
=
sys
.
scheduler
();
auto
&
sched
=
sys
.
scheduler
();
if
(
sched
.
detaches_utility_actors
())
if
(
sched
.
detaches_utility_actors
())
assumed_thread_count
+=
sched
.
num_utility_actors
();
assumed_thread_count
+=
sched
.
num_utility_actors
();
...
...
libcaf_io/src/middleman.cpp
View file @
50403ea0
...
@@ -55,6 +55,7 @@
...
@@ -55,6 +55,7 @@
#include "caf/detail/ripemd_160.hpp"
#include "caf/detail/ripemd_160.hpp"
#include "caf/detail/safe_equal.hpp"
#include "caf/detail/safe_equal.hpp"
#include "caf/detail/get_root_uuid.hpp"
#include "caf/detail/get_root_uuid.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/detail/get_mac_addresses.hpp"
#include "caf/detail/get_mac_addresses.hpp"
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
...
@@ -323,6 +324,7 @@ void middleman::start() {
...
@@ -323,6 +324,7 @@ void middleman::start() {
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
thread_
=
std
::
thread
{[
&
,
this
]
{
thread_
=
std
::
thread
{[
&
,
this
]
{
CAF_SET_LOGGER_SYS
(
&
system
());
CAF_SET_LOGGER_SYS
(
&
system
());
detail
::
set_thread_name
(
"caf.multiplexer"
);
system
().
thread_started
();
system
().
thread_started
();
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
{
{
...
...
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