Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action invocation count #1774

Merged
merged 5 commits into from Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/manual/existing_performance_counters.qbk
Expand Up @@ -1136,6 +1136,38 @@ system and application performance.
[Returns the overall number of currently active components of the
specified type on the given locality.]
]
[ [`/runtime/count/action_invocation`]
[`locality#*/total`

where:[br] `*` is the locality id of the locality the number of
action invocations should be queried. The locality id is a (zero based)
number identifying the locality.
]
[The action type. This is the string which has been used
while registering the action with __hpx__, e.g. which has been
passed as the second parameter to the macro
[macroref HPX_REGISTER_ACTION `HPX_REGISTER_ACTION`] or
[macroref HPX_REGISTER_ACTION_ID `HPX_REGISTER_ACTION_ID`].
]
[Returns the overall (local) invocation count of the specified action
type on the given locality.]
]
[ [`/runtime/count/remote_action_invocation`]
[`locality#*/total`

where:[br] `*` is the locality id of the locality the number of
action invocations should be queried. The locality id is a (zero based)
number identifying the locality.
]
[The action type. This is the string which has been used
while registering the action with __hpx__, e.g. which has been
passed as the second parameter to the macro
[macroref HPX_REGISTER_ACTION `HPX_REGISTER_ACTION`] or
[macroref HPX_REGISTER_ACTION_ID `HPX_REGISTER_ACTION_ID`].
]
[Returns the overall (remote) invocation count of the specified action
type on the given locality.]
]
[ [`/runtime/uptime`]
[`locality#*/total`

Expand Down
18 changes: 18 additions & 0 deletions hpx/performance_counters/counter_creators.hpp
Expand Up @@ -81,6 +81,24 @@ namespace hpx { namespace performance_counters
///
HPX_API_EXPORT bool agas_counter_discoverer(counter_info const&,
discover_counter_func const&, discover_counters_mode, error_code&);

///////////////////////////////////////////////////////////////////////////
// Creation function for action invocation counters.
HPX_API_EXPORT naming::gid_type local_action_invocation_counter_creator(
counter_info const&, error_code&);

// Discoverer function for action invocation counters.
HPX_API_EXPORT bool local_action_invocation_counter_discoverer(
counter_info const&, discover_counter_func const&,
discover_counters_mode, error_code&);

HPX_API_EXPORT naming::gid_type remote_action_invocation_counter_creator(
counter_info const&, error_code&);

// Discoverer function for action invocation counters.
HPX_API_EXPORT bool remote_action_invocation_counter_discoverer(
counter_info const&, discover_counter_func const&,
discover_counters_mode, error_code&);
}}

#endif
Expand Down
7 changes: 4 additions & 3 deletions hpx/performance_counters/counters.hpp
Expand Up @@ -613,12 +613,13 @@ namespace hpx { namespace performance_counters
// (milliseconds).
naming::gid_type create_statistics_counter(
counter_info const& info, std::string const& base_counter_name,
std::vector<boost::int64_t> const& parameters, error_code& ec = throws);
std::vector<boost::int64_t> const& parameters,
error_code& ec = throws);

// \brief Create a new arithmetics performance counter instance based on
// the given base counter names
naming::gid_type create_arithmetics_counter(
counter_info const& info, std::vector<std::string> const& base_counter_names,
naming::gid_type create_arithmetics_counter(counter_info const& info,
std::vector<std::string> const& base_counter_names,
error_code& ec = throws);

// \brief Create a new performance counter instance based on given
Expand Down
6 changes: 6 additions & 0 deletions hpx/performance_counters/registry.hpp
Expand Up @@ -140,6 +140,12 @@ namespace hpx { namespace performance_counters
private:
counter_type_map_type countertypes_;
};

namespace detail
{
std::string regex_from_pattern(std::string const& pattern,
error_code& ec);
}
}}

#endif
Expand Down
Expand Up @@ -38,12 +38,12 @@ namespace hpx { namespace performance_counters { namespace server

virtual bool start()
{
return true; // nothing to do
return false; // nothing to do
}

virtual bool stop()
{
return true; // nothing to do
return false; // nothing to do
}

virtual counter_info get_counter_info() const
Expand Down
1 change: 1 addition & 0 deletions hpx/runtime/actions/action_support.hpp
Expand Up @@ -260,6 +260,7 @@ namespace hpx { namespace actions
template <typename Archive>
void serialize(Archive &, unsigned)
{}

HPX_SERIALIZATION_POLYMORPHIC_ABSTRACT(base_action);
};

Expand Down
43 changes: 40 additions & 3 deletions hpx/runtime/actions/basic_action.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2014 Hartmut Kaiser
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
// Copyright (c) 2011 Thomas Heller
//
Expand All @@ -18,6 +18,7 @@
#include <hpx/runtime/actions/action_support.hpp>
#include <hpx/runtime/actions/basic_action_fwd.hpp>
#include <hpx/runtime/actions/continuation.hpp>
#include <hpx/runtime/actions/invocation_count_registry.hpp>
#include <hpx/runtime/threads/thread_helpers.hpp>
#include <hpx/traits/action_decorate_function.hpp>
#include <hpx/util/bind.hpp>
Expand All @@ -26,6 +27,7 @@
#include <hpx/util/move.hpp>
#include <hpx/util/tuple.hpp>
#include <hpx/util/void_guard.hpp>
#include <hpx/util/get_and_reset_value.hpp>
#include <hpx/util/detail/count_num_args.hpp>
#include <hpx/util/detail/pack.hpp>

Expand All @@ -37,6 +39,7 @@
#include <boost/preprocessor/stringize.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/atomic.hpp>

#include <sstream>

Expand All @@ -60,8 +63,9 @@ namespace hpx { namespace actions

public:
template <typename F_, typename ...Ts_>
explicit continuation_thread_function(std::unique_ptr<continuation> cont,
naming::address::address_type lva, F_&& f, Ts_&&... vs)
explicit continuation_thread_function(
std::unique_ptr<continuation> cont,
naming::address::address_type lva, F_&& f, Ts_&&... vs)
: cont_(std::move(cont))
, lva_(lva)
, f_(util::deferred_call(
Expand Down Expand Up @@ -398,14 +402,45 @@ namespace hpx { namespace actions
return base_action::plain_action;
}

/// Extract the current invocation count for this action
static boost::int64_t get_invocation_count(bool reset)
{
return util::get_and_reset_value(invocation_count_, reset);
}

private:
// serialization support
friend class hpx::serialization::access;

template <typename Archive>
BOOST_FORCEINLINE void serialize(Archive& ar, const unsigned int) {}

static boost::atomic<boost::int64_t> invocation_count_;

protected:
static void increment_invocation_count()
{
++invocation_count_;
}
};

template <typename Component, typename R, typename ...Args, typename Derived>
boost::atomic<boost::int64_t>
basic_action<Component, R(Args...), Derived>::invocation_count_(0);

namespace detail
{
template <typename Action>
void register_local_action_invocation_count(
invocation_count_registry& registry)
{
registry.register_class(
hpx::actions::detail::get_action_name<Action>(),
&Action::get_invocation_count
);
}
}

///////////////////////////////////////////////////////////////////////////
namespace detail
{
Expand Down Expand Up @@ -659,7 +694,9 @@ namespace hpx { namespace actions
/**/
#define HPX_REGISTER_ACTION_2(action, actionname) \
HPX_DEFINE_GET_ACTION_NAME_(action, actionname) \
HPX_REGISTER_ACTION_INVOCATION_COUNT(action) \
/**/

///////////////////////////////////////////////////////////////////////////////
#define HPX_REGISTER_ACTION_DECLARATION_NO_DEFAULT_GUID(action) \
namespace hpx { namespace actions { namespace detail { \
Expand Down
24 changes: 16 additions & 8 deletions hpx/runtime/actions/component_action.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2013 Hartmut Kaiser
// Copyright (c) 2007-2015 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -32,7 +32,7 @@ namespace hpx { namespace actions
/// \cond NOINTERNAL

///////////////////////////////////////////////////////////////////////////
// Specialized generic non-conts component action types allowing to hold
// Specialized generic non-const component action types allowing to hold
// a different number of arguments
///////////////////////////////////////////////////////////////////////////
template <
Expand All @@ -46,9 +46,11 @@ namespace hpx { namespace actions
static std::string get_action_name(naming::address::address_type lva)
{
std::stringstream name;
name << "component action(" << detail::get_action_name<Derived>() <<
") lva(" << reinterpret_cast<void const*>(
get_lva<Component>::call(lva)) << ")";
name << "component action("
<< detail::get_action_name<Derived>()
<< ") lva("
<< reinterpret_cast<void const*>(get_lva<Component>::call(lva))
<< ")";
return name.str();
}

Expand All @@ -61,6 +63,8 @@ namespace hpx { namespace actions
template <typename ...Ts>
static R invoke(naming::address::address_type lva, Ts&&... vs)
{
basic_action<Component, R(Ps...), Derived>::
increment_invocation_count();
return (get_lva<Component>::call(lva)->*F)
(std::forward<Ts>(vs)...);
}
Expand All @@ -81,9 +85,11 @@ namespace hpx { namespace actions
static std::string get_action_name(naming::address::address_type lva)
{
std::stringstream name;
name << "component action(" << detail::get_action_name<Derived>() <<
") lva(" << reinterpret_cast<void const*>(
get_lva<Component>::call(lva)) << ")";
name << "component action("
<< detail::get_action_name<Derived>()
<< ") lva("
<< reinterpret_cast<void const*>(get_lva<Component>::call(lva))
<< ")";
return name.str();
}

Expand All @@ -96,6 +102,8 @@ namespace hpx { namespace actions
template <typename ...Ts>
static R invoke(naming::address::address_type lva, Ts&&... vs)
{
basic_action<Component const, R(Ps...), Derived>::
increment_invocation_count();
return (get_lva<Component const>::call(lva)->*F)
(std::forward<Ts>(vs)...);
}
Expand Down
94 changes: 94 additions & 0 deletions hpx/runtime/actions/invocation_count_registry.hpp
@@ -0,0 +1,94 @@
// Copyright (c) 2015 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(HPX_ACTIONS_INVOCATION_COUNT_REGISTRY_SEP_25_2015_0727AM)
#define HPX_ACTIONS_INVOCATION_COUNT_REGISTRY_SEP_25_2015_0727AM

#include <hpx/config.hpp>
#include <hpx/performance_counters/counters.hpp>

#include <hpx/util/jenkins_hash.hpp>
#include <hpx/util/static.hpp>

#include <boost/preprocessor/cat.hpp>
#include <boost/noncopyable.hpp>
#include <boost/unordered_map.hpp>
#include <boost/atomic.hpp>

#include <hpx/config/warnings_prefix.hpp>

namespace hpx { namespace actions { namespace detail
{
class HPX_EXPORT invocation_count_registry : boost::noncopyable
{
public:
typedef boost::int64_t (*get_invocation_count_type)(bool);
typedef boost::unordered_map<
std::string, get_invocation_count_type, hpx::util::jenkins_hash
> map_type;

static invocation_count_registry& local_instance();
static invocation_count_registry& remote_instance();

void register_class(std::string const& name, get_invocation_count_type fun);

get_invocation_count_type
get_invocation_counter(std::string const& name) const;

bool counter_discoverer(
performance_counters::counter_info const& info,
performance_counters::counter_path_elements const& p,
performance_counters::discover_counter_func const& f,
performance_counters::discover_counters_mode mode, error_code& ec);

private:
struct local_tag {};
struct remote_tag {};

friend struct hpx::util::static_<invocation_count_registry, local_tag>;
friend struct hpx::util::static_<invocation_count_registry, remote_tag>;

map_type map_;
};

template <typename Action>
void register_local_action_invocation_count(
invocation_count_registry& registry);

template <typename Action>
void register_remote_action_invocation_count(
invocation_count_registry& registry);

template <typename Action>
struct register_action_invocation_count
{
register_action_invocation_count()
{
register_local_action_invocation_count<Action>(
invocation_count_registry::local_instance());

register_remote_action_invocation_count<Action>(
invocation_count_registry::remote_instance());
}

static register_action_invocation_count instance;
};

template <typename Action>
register_action_invocation_count<Action>
register_action_invocation_count<Action>::instance;
}}}

#define HPX_REGISTER_ACTION_INVOCATION_COUNT(Action) \
namespace hpx { namespace actions { namespace detail \
{ \
template register_action_invocation_count<Action> \
register_action_invocation_count<Action>::instance; \
}}} \
/**/

#include <hpx/config/warnings_suffix.hpp>

#endif