Skip to content

Commit

Permalink
Adding new statistics performance counters:
Browse files Browse the repository at this point in the history
- rolling_variance, rolling_max, rolling_min
  • Loading branch information
hkaiser committed Jun 6, 2017
1 parent 67870fc commit 340aca3
Show file tree
Hide file tree
Showing 7 changed files with 498 additions and 8 deletions.
50 changes: 46 additions & 4 deletions docs/manual/existing_performance_counters.qbk
Expand Up @@ -1295,6 +1295,20 @@ system and application performance.
milliseconds) at which the underlying counter should be queried. If
no value is specified, the counter will assume `1000` \[ms\] as the default.]
]
[ [`/statistics/rolling_average`]
[Any full performance counter name. The referenced performance counter
is queried at fixed time intervals as specified by the first parameter.]
[Returns the current rolling average (mean) value calculated based on the values
queried from the underlying counter (the one specified as the instance
name).]
[Any parameter will be interpreted as a list of two comma separated (integer)
values, where the first is the time interval (in
milliseconds) at which the underlying counter should be queried. If
no value is specified, the counter will assume `1000` \[ms\] as the default.
The second value will be interpreted as the size of the rolling window
(the number of latest values to use to calculate the rolling average). The
default value for this is `10`.]
]
[ [`/statistics/stddev`]
[Any full performance counter name. The referenced performance counter
is queried at fixed time intervals as specified by the first parameter.]
Expand All @@ -1306,12 +1320,12 @@ system and application performance.
no value is specified, the counter will assume `1000` \[ms\] as the
default.]
]
[ [`/statistics/rolling_average`]
[ [`/statistics/rolling_stddev`]
[Any full performance counter name. The referenced performance counter
is queried at fixed time intervals as specified by the first parameter.]
[Returns the current rolling average (mean) value calculated based on the values
queried from the underlying counter (the one specified as the instance
name).]
[Returns the current rolling variance (stddev) value calculated based on
the values queried from the underlying counter (the one specified as
the instance name).]
[Any parameter will be interpreted as a list of two comma separated (integer)
values, where the first is the time interval (in
milliseconds) at which the underlying counter should be queried. If
Expand Down Expand Up @@ -1340,6 +1354,20 @@ system and application performance.
milliseconds) at which the underlying counter should be queried. If
no value is specified, the counter will assume `1000` \[ms\] as the default.]
]
[ [`/statistics/rolling_max`]
[Any full performance counter name. The referenced performance counter
is queried at fixed time intervals as specified by the first parameter.]
[Returns the current rolling maximum value calculated based on
the values queried from the underlying counter (the one specified as
the instance name).]
[Any parameter will be interpreted as a list of two comma separated (integer)
values, where the first is the time interval (in
milliseconds) at which the underlying counter should be queried. If
no value is specified, the counter will assume `1000` \[ms\] as the default.
The second value will be interpreted as the size of the rolling window
(the number of latest values to use to calculate the rolling average). The
default value for this is `10`.]
]
[ [`/statistics/min`]
[Any full performance counter name. The referenced performance counter
is queried at fixed time intervals as specified by the first parameter.]
Expand All @@ -1350,6 +1378,20 @@ system and application performance.
milliseconds) at which the underlying counter should be queried. If
no value is specified, the counter will assume `1000` \[ms\] as the default.]
]
[ [`/statistics/rolling_min`]
[Any full performance counter name. The referenced performance counter
is queried at fixed time intervals as specified by the first parameter.]
[Returns the current rolling minimum value calculated based on
the values queried from the underlying counter (the one specified as
the instance name).]
[Any parameter will be interpreted as a list of two comma separated (integer)
values, where the first is the time interval (in
milliseconds) at which the underlying counter should be queried. If
no value is specified, the counter will assume `1000` \[ms\] as the default.
The second value will be interpreted as the size of the rolling window
(the number of latest values to use to calculate the rolling average). The
default value for this is `10`.]
]
]

[/////////////////////////////////////////////////////////////////////////////]
Expand Down
1 change: 0 additions & 1 deletion hpx/util/histogram.hpp
Expand Up @@ -10,7 +10,6 @@

#include <boost/range/iterator_range.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/numeric/functional.hpp>
Expand Down
111 changes: 111 additions & 0 deletions hpx/util/rolling_max.hpp
@@ -0,0 +1,111 @@
// Copyright (c) 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)

#ifndef ROLLING_MAX_HPP
#define ROLLING_MAX_HPP

#include <hpx/config.hpp>

#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/numeric/functional.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
#include <boost/accumulators/statistics/rolling_window.hpp>

namespace hpx { namespace util
{
namespace detail
{
template <typename Sample>
struct rolling_max_impl : boost::accumulators::accumulator_base
{
typedef Sample float_type;

// for boost::result_of
typedef float_type result_type;

template <typename Args>
rolling_max_impl(Args const& args)
: max_(boost::numeric::as_min(
args[boost::accumulators::sample | Sample()]))
{}

template <typename Args>
void operator()(Args const &args)
{
if (boost::accumulators::impl::is_rolling_window_plus1_full(args))
{
auto r = boost::accumulators::rolling_window_plus1(args);

this->max_ = boost::numeric::as_min(
args[boost::accumulators::sample]);

auto it = r.begin();
for (++it; it != r.end(); ++it)
{
boost::numeric::max_assign(this->max_, *it);
}
}
else
{
boost::numeric::max_assign(
this->max_, args[boost::accumulators::sample]);
}
}

template <typename Args>
result_type result(Args const &args) const
{
return this->max_;
}

private:
Sample max_;
};
}
}}

///////////////////////////////////////////////////////////////////////////////
// tag::rolling_max
namespace boost { namespace accumulators
{
namespace tag
{
struct rolling_max
: depends_on<rolling_window_plus1>
{
struct impl
{
template <typename Sample, typename Weight>
struct apply
{
typedef hpx::util::detail::rolling_max_impl<Sample> type;
};
};
};
}

///////////////////////////////////////////////////////////////////////////////
// extract::rolling_max
namespace extract
{
extractor<tag::rolling_max> const rolling_max = {};
}
}} // namespace boost::accumulators

namespace hpx { namespace util
{
namespace tag
{
using boost::accumulators::tag::rolling_max;
}

using boost::accumulators::extract::rolling_max;
}}

#endif

111 changes: 111 additions & 0 deletions hpx/util/rolling_min.hpp
@@ -0,0 +1,111 @@
// Copyright (c) 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)

#ifndef ROLLING_MIN_HPP
#define ROLLING_MIN_HPP

#include <hpx/config.hpp>

#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
#include <boost/accumulators/numeric/functional.hpp>
#include <boost/accumulators/framework/parameters/sample.hpp>
#include <boost/accumulators/framework/depends_on.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
#include <boost/accumulators/statistics/rolling_window.hpp>

namespace hpx { namespace util
{
namespace detail
{
template <typename Sample>
struct rolling_min_impl : boost::accumulators::accumulator_base
{
typedef Sample float_type;

// for boost::result_of
typedef float_type result_type;

template <typename Args>
rolling_min_impl(Args const& args)
: min_(boost::numeric::as_max(
args[boost::accumulators::sample | Sample()]))
{}

template <typename Args>
void operator()(Args const &args)
{
if (boost::accumulators::impl::is_rolling_window_plus1_full(args))
{
auto r = boost::accumulators::rolling_window_plus1(args);

this->min_ = boost::numeric::as_max(
args[boost::accumulators::sample]);

auto it = r.begin();
for (++it; it != r.end(); ++it)
{
boost::numeric::min_assign(this->min_, *it);
}
}
else
{
boost::numeric::min_assign(
this->min_, args[boost::accumulators::sample]);
}
}

template <typename Args>
result_type result(Args const &args) const
{
return this->min_;
}

private:
Sample min_;
};
}
}}

///////////////////////////////////////////////////////////////////////////////
// tag::rolling_min
namespace boost { namespace accumulators
{
namespace tag
{
struct rolling_min
: depends_on<rolling_window_plus1>
{
struct impl
{
template <typename Sample, typename Weight>
struct apply
{
typedef hpx::util::detail::rolling_min_impl<Sample> type;
};
};
};
}

///////////////////////////////////////////////////////////////////////////////
// extract::rolling_min
namespace extract
{
extractor<tag::rolling_min> const rolling_min = {};
}
}} // namespace boost::accumulators

namespace hpx { namespace util
{
namespace tag
{
using boost::accumulators::tag::rolling_min;
}

using boost::accumulators::extract::rolling_min;
}}

#endif

48 changes: 47 additions & 1 deletion src/performance_counters/registry.cpp
Expand Up @@ -16,10 +16,13 @@
#include <hpx/util/bind.hpp>
#include <hpx/util/function.hpp>
#include <hpx/util/logging.hpp>
#include <hpx/util/rolling_max.hpp>
#include <hpx/util/rolling_min.hpp>

#include <boost/format.hpp>
#include <boost/regex.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
#include <boost/accumulators/statistics/rolling_variance.hpp>

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -738,7 +741,22 @@ namespace hpx { namespace performance_counters
window_size = parameters[1];

gid = components::server::construct<counter_t>(
complemented_info, base_counter_name, sample_interval, window_size);
complemented_info, base_counter_name, sample_interval,
window_size);
}
else if (p.countername_ == "rolling_stddev") {
typedef hpx::components::component<
hpx::performance_counters::server::statistics_counter<
boost::accumulators::tag::rolling_variance>
> counter_t;

std::size_t window_size = 10; // default rolling window size
if (parameters.size() > 1)
window_size = parameters[1];

gid = components::server::construct<counter_t>(
complemented_info, base_counter_name, sample_interval,
window_size);
}
else if (p.countername_ == "median") {
typedef hpx::components::component<
Expand All @@ -764,6 +782,34 @@ namespace hpx { namespace performance_counters
gid = components::server::construct<counter_t>(
complemented_info, base_counter_name, sample_interval, 0);
}
else if (p.countername_ == "rolling_min") {
typedef hpx::components::component<
hpx::performance_counters::server::statistics_counter<
hpx::util::tag::rolling_min>
> counter_t;

std::size_t window_size = 10; // default rolling window size
if (parameters.size() > 1)
window_size = parameters[1];

gid = components::server::construct<counter_t>(
complemented_info, base_counter_name, sample_interval,
window_size);
}
else if (p.countername_ == "rolling_max") {
typedef hpx::components::component<
hpx::performance_counters::server::statistics_counter<
hpx::util::tag::rolling_max>
> counter_t;

std::size_t window_size = 10; // default rolling window size
if (parameters.size() > 1)
window_size = parameters[1];

gid = components::server::construct<counter_t>(
complemented_info, base_counter_name, sample_interval,
window_size);
}
else {
HPX_THROWS_IF(ec, bad_parameter,
"registry::create_statistics_counter",
Expand Down

0 comments on commit 340aca3

Please sign in to comment.