SObjectizer  5.8
Loading...
Searching...
No Matches
messages.hpp
Go to the documentation of this file.
1/*
2 * SObjectizer-5
3 */
4
5/*!
6 * \file
7 *
8 * \brief Messages with monitoring information.
9 *
10 * \since v.5.5.4
11 */
12
13#pragma once
14
15#include <so_5/current_thread_id.hpp>
16
17#include <so_5/message.hpp>
18
19#include <so_5/detect_os.hpp>
20
21#include <so_5/stats/prefix.hpp>
22#include <so_5/stats/work_thread_activity.hpp>
23
24#if defined( SO_5_MSVC )
25 #pragma warning(push)
26 #pragma warning(disable: 4251)
27#endif
28
29namespace so_5
30{
31
32namespace stats
33{
34
35namespace messages
36{
37
38/*
39 * Implementation note: this type has to be marked as SO_5_TYPE for
40 * clang on FreeBSD/macOS. But SO_5_TYPE shouldn't be used on Windows.
41 */
42#if defined(SO_5_OS_WINDOWS)
43 #define SO_5_EXPORT_IMPORT_FOR_QUANTITY_MSG /* empty */
44#else
45 #define SO_5_EXPORT_IMPORT_FOR_QUANTITY_MSG SO_5_TYPE
46#endif
47
48/*!
49 * \brief A message with value of some quantity.
50 *
51 * This message can be used for monitoring things like queue sizes,
52 * count of delayed messages, count of cooperations and so on.
53 *
54 * \tparam T type for representing quantity.
55 *
56 * \since v.5.5.4
57 */
58template< typename T >
60 {
61 //! Prefix of data_source name.
63 //! Suffix of data_source name.
65
66 //! Actual quantity value.
68
69 //! Initializing constructor.
71 const prefix_t & prefix,
72 const suffix_t & suffix,
73 T value )
74 : m_prefix( prefix )
75 , m_suffix( suffix )
76 , m_value( std::move( value ) )
77 {}
78 };
79
80#undef SO_5_EXPORT_IMPORT_FOR_QUANTITY_MSG
81
82/*!
83 * \brief Notification about start of new stats distribution.
84 *
85 * \note This message is empty now but it is not declared as a signal.
86 * It is for a possibility of expansion of the message in the future.
87 *
88 * \since v.5.5.18
89 */
91
92/*!
93 * \brief Notification about finish of stats distribution.
94 *
95 * \note This message is empty now but it is not declared as a signal.
96 * It is for a possibility of expansion of the message in the future.
97 *
98 * \since v.5.5.18
99 */
101
102/*!
103 * \brief Information about one work thread activity.
104 *
105 * \since v.5.5.18
106 */
108 {
109 //! Prefix of data_source name.
111 //! Suffix of data_source name.
113
114 //! ID of the thread.
116
117 //! Actual value.
119
121 const prefix_t & prefix,
122 const suffix_t & suffix,
123 const so_5::current_thread_id_t & thread_id,
125 : m_prefix( prefix )
126 , m_suffix( suffix )
128 , m_stats( stats )
129 {}
130 };
131
132} /* namespace messages */
133
134} /* namespace stats */
135
136} /* namespace so_5 */
137
138#if defined( SO_5_MSVC )
139 #pragma warning(pop)
140#endif
A base class for agents.
Definition agent.hpp:673
Alias for namespace with traits of event queue.
const queue_traits::queue_params_t & queue_params() const
Getter for queue parameters.
disp_params_t & tune_queue_params(L tunner)
Tuner for queue parameters.
queue_traits::queue_params_t m_queue_params
Queue parameters.
friend void swap(disp_params_t &a, disp_params_t &b) noexcept
disp_params_t & set_queue_params(queue_traits::queue_params_t p)
Setter for queue parameters.
disp_params_t()=default
Default constructor.
A handle for active_group dispatcher.
dispatcher_handle_t(impl::basic_dispatcher_iface_shptr_t dispatcher) noexcept
impl::basic_dispatcher_iface_shptr_t m_dispatcher
A reference to actual implementation of a dispatcher.
bool empty() const noexcept
Is this handle empty?
void reset() noexcept
Drop the content of handle.
bool operator!() const noexcept
Does this handle contain a reference to dispatcher?
operator bool() const noexcept
Is this handle empty?
disp_binder_shptr_t binder(nonempty_name_t group_name) const
Get a binder for that dispatcher.
const std::string m_group_name
Name of group for new agents.
void preallocate_resources(agent_t &) override
Allocate resources in dispatcher for new agent.
void unbind(agent_t &) noexcept override
Unbind agent from dispatcher.
void bind(agent_t &agent) noexcept override
Bind agent to dispatcher.
actual_dispatcher_iface_shptr_t m_disp
Dispatcher to be used.
void undo_preallocation(agent_t &) noexcept override
Undo resources allocation.
actual_binder_t(actual_dispatcher_iface_shptr_t disp, nonempty_name_t group_name) noexcept
An actual interface of active group dispatcher.
virtual so_5::event_queue_t * query_thread_for_group(const std::string &group_name) noexcept=0
Get the event_queue for the specified active group.
virtual void release_thread_for_group(const std::string &group_name) noexcept=0
Release the thread for the specified active group.
virtual void allocate_thread_for_group(const std::string &group_name)=0
Create a new thread for a group if it necessary.
The very basic interface of active_group dispatcher.
virtual disp_binder_shptr_t binder(nonempty_name_t group_name)=0
static dispatcher_handle_t make(actual_dispatcher_iface_shptr_t disp) noexcept
outliving_reference_t< dispatcher_template_t > m_dispatcher
Dispatcher to work with.
void distribute_value_for_work_thread(const so_5::mbox_t &mbox, const std::string &group_name, const thread_with_refcounter_t &wt)
disp_data_source_t(const std::string_view name_base, outliving_reference_t< dispatcher_template_t > disp)
void distribute(const so_5::mbox_t &mbox) override
Send appropriate notification about the current value.
void release_thread_for_group(const std::string &group_name) noexcept override
Release the thread for the specified active group.
void allocate_thread_for_group(const std::string &group_name) override
Create a new thread for a group if it necessary.
outliving_reference_t< environment_t > m_env
SObjectizer Environment to work in.
so_5::event_queue_t * query_thread_for_group(const std::string &group_name) noexcept override
Get the event_queue for the specified active group.
active_group_map_t m_groups
A map of dispatchers for active groups.
const disp_params_t m_params
Parameters for the dispatcher.
dispatcher_template_t(outliving_reference_t< environment_t > env, const std::string_view name_base, disp_params_t params)
work_thread_shptr_t search_and_try_remove_group_from_map(const std::string &group_name) noexcept
Helper function for searching and erasing agent's thread from map of active threads.
stats::auto_registered_source_holder_t< disp_data_source_t > m_data_source
Data source for run-time monitoring.
disp_binder_shptr_t binder(nonempty_name_t group_name) override
Container for storing parameters for MPSC queue.
A part of demand queue implementation for the case when activity tracking is not used.
std::size_t demands_count(const demands_counter_t &external_counter)
Get the count of demands in the queue.
virtual void push(execution_demand_t demand) override
Enqueue new event to the queue.
extraction_result_t pop(demand_container_t &demands, demands_counter_t &external_counter)
Try to extract demands from the queue.
A part of demand queue implementation for the case when activity tracking is used.
so_5::stats::activity_tracking_stuff::stats_collector_t< so_5::stats::activity_tracking_stuff::external_lock< queue_traits::lock_t, so_5::stats::activity_tracking_stuff::no_lock_at_start_stop_policy > > m_waiting_stats
Part of implementation of work thread with activity tracking.
so_5::stats::work_thread_activity_stats_t take_activity_stats()
Get the activity stats.
const so_5::stats::clock_type_t::time_point * m_activity_started_at
Pointer to time_point object related to the current activity.
activity_tracking_impl_t(work_thread_holder_t thread_holder, queue_traits::lock_factory_t queue_lock_factory)
activity_tracking_traits::lock_t m_stats_lock
Lock for manipulation of activity stats.
void serve_demands_block(demand_container_t &demands)
Main method for serving block of demands.
Part of implementation of work thread without activity tracking.
void serve_demands_block(demand_container_t &demands)
Main method for serving block of demands.
no_activity_tracking_impl_t(work_thread_holder_t thread_holder, queue_traits::lock_factory_t queue_lock_factory)
event_queue_t & event_queue()
Get the underlying event_queue object.
work_thread_template_t(work_thread_holder_t thread_holder, queue_traits::lock_factory_t queue_lock_factory)
event_queue_t * get_agent_binding()
Get a binding information for an agent.
so_5::current_thread_id_t thread_id() const
Get ID of work thread.
Mixin that holds optional work thread factory.
An analog of unique_ptr for abstract_work_thread.
Interface for dispatcher binders.
SObjectizer Environment.
An interface of event queue for agent.
A base class for agent messages.
Definition message.hpp:47
A class for the name which cannot be empty.
Helper class for indication of long-lived reference via its type.
Definition outliving.hpp:98
Base for the case of externals stats lock.
Base for the case of internal stats lock.
so_5::stats::activity_stats_t m_work_activity
A statistics for work activity.
void start_if_not_started()
A helper method for safe start if start method hasn't been called yet.
so_5::stats::clock_type_t::time_point m_work_started_at
A time point when current activity started.
bool m_is_in_working
A flag for indicating work activity.
A holder for data-souce that should be automatically registered and deregistered in registry.
A type for storing prefix of data_source name.
Definition prefix.hpp:32
bool operator<(const prefix_t &o) const noexcept
Is less than?
Definition prefix.hpp:123
constexpr prefix_t() noexcept
Default constructor creates empty prefix.
Definition prefix.hpp:40
constexpr bool empty() const noexcept
Is prefix empty?
Definition prefix.hpp:99
static constexpr const std::size_t max_buffer_size
Max size of buffer for prefix value (including 0-symbol at the end).
Definition prefix.hpp:37
constexpr std::string_view as_string_view() const noexcept(noexcept(std::string_view{std::declval< const char * >()}))
Access to prefix value as string_view.
Definition prefix.hpp:91
constexpr const char * c_str() const noexcept
Access to prefix value.
Definition prefix.hpp:80
constexpr prefix_t(const char *value) noexcept
Initializing constructor.
Definition prefix.hpp:54
bool operator!=(const prefix_t &o) const noexcept
Is not equal?
Definition prefix.hpp:115
static constexpr const std::size_t max_length
Max length of prefix (not including 0-symbol at the end).
Definition prefix.hpp:35
char m_value[max_buffer_size]
Actual value.
Definition prefix.hpp:130
prefix_t(const std::string &value) noexcept(noexcept(value.c_str()))
Initializing constructor.
Definition prefix.hpp:73
bool operator==(const prefix_t &o) const noexcept
Is equal?
Definition prefix.hpp:107
An interface of data source.
A type for representing the suffix of data_source name.
Definition prefix.hpp:156
constexpr bool operator<(const suffix_t &o) const noexcept
Compares suffixes by pointer value.
Definition prefix.hpp:203
constexpr bool operator==(const suffix_t &o) const noexcept
Compares suffixes by pointer values.
Definition prefix.hpp:187
constexpr const char * c_str() const noexcept
Access to suffix value.
Definition prefix.hpp:168
const char * m_value
Actual value.
Definition prefix.hpp:210
constexpr std::string_view as_string_view() const noexcept(noexcept(std::string_view{std::declval< const char * >()}))
Access to prefix value as string_view.
Definition prefix.hpp:179
constexpr suffix_t(const char *value) noexcept
Initializing constructor.
Definition prefix.hpp:159
constexpr bool operator!=(const suffix_t &o) const noexcept
Compares suffixes by pointer value.
Definition prefix.hpp:195
#define SO_5_TYPE
Definition declspec.hpp:46
#define SO_5_FUNC
Definition declspec.hpp:48
#define SO_5_THROW_EXCEPTION(error_code, desc)
Definition exception.hpp:74
#define SO_5_EXPORT_IMPORT_FOR_QUANTITY_MSG
Definition messages.hpp:45
Helpers for manipulation with standard C++ I/O streams.
Some reusable and low-level classes/functions which can be used in public header files.
void shutdown_and_wait(T &w)
Just a helper function for consequetive call to shutdown and wait.
void send_thread_activity_stats(const so_5::mbox_t &, const stats::prefix_t &, work_thread::work_thread_no_activity_tracking_t &)
void send_thread_activity_stats(const so_5::mbox_t &mbox, const stats::prefix_t &prefix, work_thread::work_thread_with_activity_tracking_t &wt)
Active groups dispatcher implemetation details.
Active groups dispatcher.
dispatcher_handle_t make_dispatcher(so_5::environment_t &env, const std::string_view data_sources_name_base)
Create an instance of active_group dispatcher.
dispatcher_handle_t make_dispatcher(so_5::environment_t &env)
Create an instance of active_group dispatcher.
SO_5_FUNC dispatcher_handle_t make_dispatcher(environment_t &env, const std::string_view data_sources_name_base, disp_params_t params)
Create an instance of active_group dispatcher.
Various stuff related to MPSC event queue implementation and tuning.
@ working
1 - thread execution should be continued.
@ stopped
0 - thread execution should be stopped.
Implemetation details of dispatcher's working thread.
extraction_result_t
Type for result of demand extraction.
@ shutting_down
Demand has not been extracted because of shutdown.
@ no_demands
Demand has not been extracted because the demand queue is empty.
Reusable components for dispatchers.
abstract_work_thread_factory_shptr_t actual_work_thread_factory_to_use(const work_thread_factory_mixin_t< Params > &params, const environment_t &env) noexcept
Helper to detect actual work thread factory to be used.
work_thread_holder_t acquire_work_thread(const work_thread_factory_mixin_t< Params > &params, environment_t &env)
Helper function for acquiring a new worker thread from an appropriate work thread factory.
so_5::stats::prefix_t make_disp_prefix(const std::string_view disp_type, const std::string_view data_sources_name_base, const void *disp_this_pointer)
Create basic prefix for dispatcher data source names.
void modify_disp_params(so_5::environment_t &env, Disp_Params_Type &params)
Helper functions to adjust some dispatcher parameters with respect to settings from environment.
so_5::stats::prefix_t make_disp_working_thread_prefix(const so_5::stats::prefix_t &disp_prefix, std::size_t thread_number)
Create prefix for dispatcher's working thread data source.
std::unique_ptr< Disp_Iface_Type > make_actual_dispatcher(outliving_reference_t< environment_t > env, const std::string_view name_base, Disp_Params_Type disp_params, Args &&...args)
Helper function for creation of dispatcher instance with respect to work thread activity tracking fla...
Event dispatchers.
Details of SObjectizer run-time implementations.
Definition agent.cpp:905
void ensure_join_from_different_thread(current_thread_id_t thread_to_be_joined)
Ensures that join will be called from different thread.
std::unique_ptr< Common_Disp_Iface_Type > create_appropriate_disp(outliving_reference_t< Env > env, const std::string_view name_base, Disp_Params disp_params, Args &&...args)
Helper function for creation of dispatcher with respect to activity tracking flag in dispatcher param...
void update_stats_from_current_time(activity_stats_t &value_to_update, clock_type_t::time_point activity_started_at)
Helper function for simplification of current stats update.
void update_stats_from_duration(activity_stats_t &value_to_update, clock_type_t::duration last_duration)
Helper function for simplification of current stats update.
duration_t calc_avg_time(std::uint_fast64_t count, duration_t previous, duration_t last)
A function for calculating average value.
Declarations of messages used by run-time monitoring and statistics.
Definition messages.hpp:36
All stuff related to run-time monitoring and statistics.
std::ostream & operator<<(std::ostream &to, const prefix_t &what)
Just a helper operator.
Definition prefix.hpp:139
std::ostream & operator<<(std::ostream &to, const suffix_t &what)
Just a helper operator.
Definition prefix.hpp:219
std::ostream & operator<<(std::ostream &to, const activity_stats_t &what)
Helper for printing value of activity_stats.
Private part of message limit implementation.
Definition agent.cpp:33
common_data_t(queue_traits::lock_unique_ptr_t lock)
Initializing constructor.
common_data_t(work_thread_holder_t thread_holder, queue_traits::lock_factory_t queue_lock_factory)
demands_counter_t m_demands_count
A counter for calculating count of demands in the queue.
A description of event execution demand.
Statistics of some activity.
std::optional< duration_t > m_current_activity_time
duration_t m_avg_time
Average time for one event.
duration_t m_total_time
Total time spent for events in that period of time.
std::uint_fast64_t m_count
Count of events in that period of time.
Default locking policy for stats_collector_t.
An analog of std::lock_guard but without actual locking actions.
A special class for cases where lock is not needed at all.
Various traits of activity tracking implementation.
Notification about finish of stats distribution.
Definition messages.hpp:100
Notification about start of new stats distribution.
Definition messages.hpp:90
A message with value of some quantity.
Definition messages.hpp:60
suffix_t m_suffix
Suffix of data_source name.
Definition messages.hpp:64
T m_value
Actual quantity value.
Definition messages.hpp:67
prefix_t m_prefix
Prefix of data_source name.
Definition messages.hpp:62
quantity(const prefix_t &prefix, const suffix_t &suffix, T value)
Initializing constructor.
Definition messages.hpp:70
Information about one work thread activity.
Definition messages.hpp:108
work_thread_activity_stats_t m_stats
Actual value.
Definition messages.hpp:118
work_thread_activity(const prefix_t &prefix, const suffix_t &suffix, const so_5::current_thread_id_t &thread_id, work_thread_activity_stats_t stats)
Definition messages.hpp:120
prefix_t m_prefix
Prefix of data_source name.
Definition messages.hpp:110
suffix_t m_suffix
Suffix of data_source name.
Definition messages.hpp:112
so_5::current_thread_id_t m_thread_id
ID of the thread.
Definition messages.hpp:115
activity_stats_t m_working_stats
Stats for processed events.
activity_stats_t m_waiting_stats
Stats for waiting periods.