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

Adding extended arithmetic performance counters #2745

Merged
merged 1 commit into from
Jul 12, 2017
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
45 changes: 45 additions & 0 deletions docs/manual/existing_performance_counters.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,51 @@ system and application performance.
this counter is accessed. Any wildcards in the counter names will
be expanded.]
]
[ [`/arithmetics/mean`]
[None]
[Returns the average value of all values queried from the
underlying counters (the ones specified as the parameters).]
[The parameter will be interpreted as a comma separated list of
full performance counter names which are queried whenever
this counter is accessed. Any wildcards in the counter names will
be expanded.]
]
[ [`/arithmetics/variance`]
[None]
[Returns the standard deviation of all values queried from the
underlying counters (the ones specified as the parameters).]
[The parameter will be interpreted as a comma separated list of
full performance counter names which are queried whenever
this counter is accessed. Any wildcards in the counter names will
be expanded.]
]
[ [`/arithmetics/median`]
[None]
[Returns the median value of all values queried from the
underlying counters (the ones specified as the parameters).]
[The parameter will be interpreted as a comma separated list of
full performance counter names which are queried whenever
this counter is accessed. Any wildcards in the counter names will
be expanded.]
]
[ [`/arithmetics/min`]
[None]
[Returns the minimum value of all values queried from the
underlying counters (the ones specified as the parameters).]
[The parameter will be interpreted as a comma separated list of
full performance counter names which are queried whenever
this counter is accessed. Any wildcards in the counter names will
be expanded.]
]
[ [`/arithmetics/max`]
[None]
[Returns the maximum value of all values queried from the
underlying counters (the ones specified as the parameters).]
[The parameter will be interpreted as a comma separated list of
full performance counter names which are queried whenever
this counter is accessed. Any wildcards in the counter names will
be expanded.]
]
]

[note The /arithmetics counters can consume an arbitrary number of other counters.
Expand Down
12 changes: 12 additions & 0 deletions hpx/performance_counters/counters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ namespace hpx { namespace performance_counters
HPX_EXPORT naming::gid_type arithmetics_counter_creator(
counter_info const&, error_code&);

// Creation function for extended aggregating performance counters; to
// be registered with the counter types.
HPX_EXPORT naming::gid_type arithmetics_counter_extended_creator(
counter_info const&, error_code&);

// Creation function for uptime counters.
HPX_EXPORT naming::gid_type uptime_counter_creator(
counter_info const&, error_code&);
Expand All @@ -733,6 +738,13 @@ namespace hpx { namespace performance_counters
std::vector<std::string> const& base_counter_names,
error_code& ec = throws);

// \brief Create a new extended arithmetics performance counter instance
// based on the given base counter names
HPX_EXPORT naming::gid_type create_arithmetics_counter_extended(
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
// counter info
HPX_EXPORT naming::gid_type create_counter(counter_info const& info,
Expand Down
3 changes: 3 additions & 0 deletions hpx/performance_counters/performance_counter_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ namespace hpx { namespace performance_counters
return get_values<T>(reset).get(ec);
}

std::size_t get_invocation_count() const;

protected:
bool find_counter(counter_info const& info, bool reset, error_code& ec);

Expand All @@ -121,6 +123,7 @@ namespace hpx { namespace performance_counters
std::vector<naming::id_type> ids_; // global ids of counter instances
std::vector<std::uint8_t> reset_; // != 0 if counter should be reset

mutable std::uint64_t invocation_count_;
bool print_counters_locally_; // handle only local counters
};
}}
Expand Down
10 changes: 8 additions & 2 deletions hpx/performance_counters/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,18 @@ namespace hpx { namespace performance_counters
naming::gid_type& id, error_code& ec = throws);

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

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

/// \brief Add an existing performance counter instance to the registry
counter_status add_counter(naming::id_type const& id,
counter_info const& info, error_code& ec = throws);
Expand Down
31 changes: 6 additions & 25 deletions hpx/performance_counters/server/arithmetics_counter.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2013 Hartmut Kaiser
// Copyright (c) 2007-2017 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 All @@ -7,13 +7,11 @@
#define HPX_PERFORMANCE_COUNTERS_SERVER_ARITHMETICS_COUNTER_APR_10_2013_1002AM

#include <hpx/config.hpp>
#include <hpx/lcos/local/spinlock.hpp>
#include <hpx/performance_counters/performance_counter_set.hpp>
#include <hpx/performance_counters/server/base_performance_counter.hpp>
#include <hpx/runtime/components/server/component_base.hpp>
#include <hpx/util/interval_timer.hpp>

#include <cstdint>
#include <mutex>
#include <string>
#include <vector>

Expand All @@ -26,20 +24,16 @@ namespace hpx { namespace performance_counters { namespace server
template <typename Operation>
class arithmetics_counter
: public base_performance_counter,
public components::component_base<
arithmetics_counter<Operation> >
public components::component_base<arithmetics_counter<Operation> >
{
typedef components::component_base<
arithmetics_counter<Operation> > base_type;
typedef lcos::local::spinlock mutex_type;

public:
typedef arithmetics_counter type_holder;
typedef base_performance_counter base_type_holder;

arithmetics_counter()
: mtx_(), invocation_count_(0)
{}
arithmetics_counter() = default;

arithmetics_counter(counter_info const& info,
std::vector<std::string> const& base_counter_names);
Expand All @@ -52,8 +46,6 @@ namespace hpx { namespace performance_counters { namespace server
bool stop();
void reset_counter_value();

/// \brief finalize() will be called just before the instance gets
/// destructed
void finalize()
{
base_performance_counter::finalize();
Expand All @@ -69,20 +61,9 @@ namespace hpx { namespace performance_counters { namespace server
base_type::set_component_type(t);
}

protected:
bool evaluate_base_counter(naming::id_type& base_counter_id,
std::string const& name, counter_value& value,
std::unique_lock<mutex_type>& l);
bool ensure_base_counter(naming::id_type& base_counter_id,
std::string const& name, std::unique_lock<mutex_type>& l);

private:
mutable mutex_type mtx_;

std::vector<std::string> base_counter_names_;
///^ names of base counters to be queried
std::vector<naming::id_type> base_counter_ids_;
std::uint64_t invocation_count_;
// base counters to be queried
performance_counter_set counters_;
};
}}}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2007-2017 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_PERFORMANCE_COUNTERS_SERVER_ARITHMETICS_COUNTER_EXTENDED)
#define HPX_PERFORMANCE_COUNTERS_SERVER_ARITHMETICS_COUNTER_EXTENDED

#include <hpx/config.hpp>
#include <hpx/performance_counters/performance_counter_set.hpp>
#include <hpx/performance_counters/server/base_performance_counter.hpp>
#include <hpx/runtime/components/server/component_base.hpp>

#include <cstdint>
#include <mutex>
#include <string>
#include <vector>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace performance_counters { namespace server
{
///////////////////////////////////////////////////////////////////////////
// This counter exposes the result of an arithmetic operation The counter
// relies on querying two base counters.
template <typename Statistic>
class arithmetics_counter_extended
: public base_performance_counter,
public components::component_base<
arithmetics_counter_extended<Statistic> >
{
typedef components::component_base<
arithmetics_counter_extended<Statistic> > base_type;

public:
typedef arithmetics_counter_extended type_holder;
typedef base_performance_counter base_type_holder;

arithmetics_counter_extended() = default;

arithmetics_counter_extended(counter_info const& info,
std::vector<std::string> const& base_counter_names);

/// Overloads from the base_counter base class.
hpx::performance_counters::counter_value
get_counter_value(bool reset = false);

bool start();
bool stop();
void reset_counter_value();

void finalize()
{
base_performance_counter::finalize();
base_type::finalize();
}

static components::component_type get_component_type()
{
return base_type::get_component_type();
}
static void set_component_type(components::component_type t)
{
base_type::set_component_type(t);
}

private:
// base counters to be queried
performance_counter_set counters_;
};
}}}

#endif
14 changes: 14 additions & 0 deletions src/performance_counters/counters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,20 @@ namespace hpx { namespace performance_counters
return gid;
}

// \brief Create a new aggregating extended performance counter instance
// based on given base counter name and given base time interval
// (milliseconds).
naming::gid_type create_arithmetics_counter_extended(
counter_info const& info,
std::vector<std::string> const& base_counter_names, error_code& ec)
{
naming::gid_type gid;
get_runtime().get_counter_registry().
create_arithmetics_counter_extended(info, base_counter_names,
gid, ec);
return gid;
}

///////////////////////////////////////////////////////////////////////
counter_status add_counter(naming::id_type const& id,
counter_info const& info, error_code& ec)
Expand Down
15 changes: 13 additions & 2 deletions src/performance_counters/performance_counter_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
namespace hpx { namespace performance_counters
{
performance_counter_set::performance_counter_set(std::string const& name,
bool reset)
bool reset)
: invocation_count_(0)
{
add_counters(name, reset);
}

performance_counter_set::performance_counter_set(
std::vector<std::string> const& names, bool reset)
std::vector<std::string> const& names, bool reset)
: invocation_count_(0)
{
add_counters(names, reset);
}
Expand Down Expand Up @@ -257,6 +259,7 @@ namespace hpx { namespace performance_counters
{
std::unique_lock<mutex_type> l(mtx_);
ids = ids_;
++invocation_count_;
}

std::vector<hpx::future<counter_value> > v;
Expand Down Expand Up @@ -298,6 +301,7 @@ namespace hpx { namespace performance_counters
{
std::unique_lock<mutex_type> l(mtx_);
ids = ids_;
++invocation_count_;
}

std::vector<hpx::future<counter_values_array> > v;
Expand Down Expand Up @@ -330,5 +334,12 @@ namespace hpx { namespace performance_counters
return std::vector<counter_values_array>();
}
}

///////////////////////////////////////////////////////////////////////////
std::size_t performance_counter_set::get_invocation_count() const
{
std::unique_lock<mutex_type> l(mtx_);
return invocation_count_;
}
}}