Skip to content

Commit

Permalink
Adding performance_counter::reinit to allow for dynamically changing …
Browse files Browse the repository at this point in the history
…counter sets

- This change adds a new API function for performance counters that instructs a
  counter to re-initialize the set of counters it refers to
- This also adds a new `hpx::reinit_active_counters()` API that triggers a
  reinit for all active counters
  • Loading branch information
hkaiser committed Jan 21, 2018
1 parent 519a2f4 commit ac55fa6
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 24 deletions.
2 changes: 1 addition & 1 deletion hpx/performance_counters/base_performance_counter.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2012 Hartmut Kaiser
// Copyright (c) 2007-2018 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
6 changes: 5 additions & 1 deletion hpx/performance_counters/performance_counter.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2013 Hartmut Kaiser
// Copyright (c) 2007-2018 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 @@ -110,6 +110,10 @@ namespace hpx { namespace performance_counters
future<void> reset();
void reset(launch::sync_policy, error_code& ec = throws);

future<void> reinit(bool reset = true);
void reinit(
launch::sync_policy, bool reset = true, error_code& ec = throws);

#if defined(HPX_HAVE_ASYNC_FUNCTION_COMPATIBILITY)
HPX_DEPRECATED(HPX_DEPRECATED_MSG)
bool start_sync(error_code& ec = throws)
Expand Down
5 changes: 4 additions & 1 deletion hpx/performance_counters/performance_counter_base.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2014 Hartmut Kaiser
// Copyright (c) 2007-2018 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 @@ -42,6 +42,9 @@ namespace hpx { namespace performance_counters

// Stop the Performance Counter.
virtual bool stop() = 0;

// Re-initialize the Performance Counter.
virtual void reinit(bool reset) = 0;
};
//]
}}
Expand Down
6 changes: 5 additions & 1 deletion hpx/performance_counters/performance_counter_set.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2017 Hartmut Kaiser
// Copyright (c) 2016-2018 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 @@ -80,6 +80,10 @@ namespace hpx { namespace performance_counters
std::vector<hpx::future<bool> > stop();
bool stop(launch::sync_policy, error_code& ec = throws);

/// Re-initialize all counters in this set
std::vector<hpx::future<void> > reinit(bool reset = true);
void reinit(launch::sync_policy, bool reset = true, error_code& ec = throws);

/// Release all references to counters in the set
void release();

Expand Down
30 changes: 22 additions & 8 deletions hpx/performance_counters/server/base_performance_counter.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2007-2018 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 @@ -26,44 +26,49 @@ namespace hpx { namespace performance_counters { namespace server
protected:
/// the following functions are not implemented by default, they will
/// just throw
virtual void reset_counter_value()
virtual void reset_counter_value() override
{
HPX_THROW_EXCEPTION(invalid_status, "reset_counter_value",
"reset_counter_value is not implemented for this counter");
}

virtual void set_counter_value(counter_value const& /*value*/)
virtual void set_counter_value(counter_value const& /*value*/) override
{
HPX_THROW_EXCEPTION(invalid_status, "set_counter_value",
"set_counter_value is not implemented for this counter");
}

virtual counter_value get_counter_value(bool reset)
virtual counter_value get_counter_value(bool reset) override
{
HPX_THROW_EXCEPTION(invalid_status, "get_counter_value",
"get_counter_value is not implemented for this counter");
return counter_value();
}

virtual counter_values_array get_counter_values_array(bool reset)
virtual counter_values_array get_counter_values_array(
bool reset) override
{
HPX_THROW_EXCEPTION(invalid_status, "get_counter_values_array",
"get_counter_values_array is not implemented for this "
"counter");
return counter_values_array();
}

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

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

virtual counter_info get_counter_info() const
virtual void reinit(bool reset) override
{
}

virtual counter_info get_counter_info() const override
{
return info_;
}
Expand Down Expand Up @@ -137,6 +142,11 @@ namespace hpx { namespace performance_counters { namespace server
return this->stop();
}

void reinit_nonvirt(bool reset)
{
reinit(reset);
}

/// Each of the exposed functions needs to be encapsulated into an action
/// type, allowing to generate all required boilerplate code for threads,
/// serialization, etc.
Expand Down Expand Up @@ -173,6 +183,10 @@ namespace hpx { namespace performance_counters { namespace server
HPX_DEFINE_COMPONENT_ACTION(
base_performance_counter, stop_nonvirt, stop_action);

/// The \a reinit_action
HPX_DEFINE_COMPONENT_ACTION(
base_performance_counter, reinit_nonvirt, reinit_action);

protected:
hpx::performance_counters::counter_info info_;
util::atomic_count invocation_count_;
Expand Down
6 changes: 5 additions & 1 deletion hpx/performance_counters/stubs/performance_counter.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2018 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 @@ -67,13 +67,17 @@ namespace hpx { namespace performance_counters { namespace stubs
naming::id_type const& targetid);
static lcos::future<void> reset(launch::async_policy,
naming::id_type const& targetid);
static lcos::future<void> reinit(launch::async_policy,
naming::id_type const& targetid, bool reset);

static bool start(launch::sync_policy, naming::id_type const& targetid,
error_code& ec = throws);
static bool stop(launch::sync_policy, naming::id_type const& targetid,
error_code& ec = throws);
static void reset(launch::sync_policy, naming::id_type const& targetid,
error_code& ec = throws);
static void reinit(launch::sync_policy, naming::id_type const& targetid,
bool reset, error_code& ec = throws);

#if defined(HPX_HAVE_ASYNC_FUNCTION_COMPATIBILITY)
HPX_DEPRECATED(HPX_DEPRECATED_MSG)
Expand Down
3 changes: 2 additions & 1 deletion hpx/runtime.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2013 Hartmut Kaiser
// Copyright (c) 2007-2018 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -289,6 +289,7 @@ namespace hpx
void start_active_counters(error_code& ec = throws);
void stop_active_counters(error_code& ec = throws);
void reset_active_counters(error_code& ec = throws);
void reinit_active_counters(bool reset = true, error_code& ec = throws);
void evaluate_active_counters(bool reset = false,
char const* description = nullptr, error_code& ec = throws);

Expand Down
21 changes: 20 additions & 1 deletion hpx/runtime_fwd.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2014 Hartmut Kaiser
// Copyright (c) 2007-2018 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -176,6 +176,25 @@ namespace hpx
/// line option \--hpx:print-counter)
HPX_API_EXPORT void reset_active_counters(error_code& ec = throws);

/// \brief Re-initialize all active performance counters.
///
/// \param reset [in] Reset the current values before re-initializing
/// counters (default: true)
/// \param ec [in,out] this represents the error status on exit, if this
/// is pre-initialized to \a hpx#throws the function will throw
/// on error instead.
///
/// \note As long as \a ec is not pre-initialized to \a hpx::throws this
/// function doesn't throw but returns the result code using the
/// parameter \a ec. Otherwise it throws an instance of
/// hpx::exception.
///
/// \note The active counters are those which have been specified on
/// the command line while executing the application (see command
/// line option \--hpx:print-counter)
HPX_API_EXPORT void reinit_active_counters(
bool reset = true, error_code& ec = throws);

/// \brief Stop all active performance counters.
///
/// \param ec [in,out] this represents the error status on exit, if this
Expand Down
3 changes: 2 additions & 1 deletion hpx/util/query_counters.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2007-2018 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 @@ -47,6 +47,7 @@ namespace hpx { namespace util
void start_counters(error_code& ec = throws);
void stop_counters(error_code& ec = throws);
void reset_counters(error_code& ec = throws);
void reinit_counters(bool reset = true, error_code& ec = throws);
bool evaluate_counters(bool reset = false,
char const* description = nullptr, error_code& ec = throws);

Expand Down
12 changes: 11 additions & 1 deletion src/performance_counters/performance_counter.cpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2007-2018 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 @@ -130,6 +130,16 @@ namespace hpx { namespace performance_counters
stubs::performance_counter::reset(launch::sync, get_id(), ec);
}

future<void> performance_counter::reinit(bool reset)
{
return stubs::performance_counter::reinit(launch::async, get_id(), reset);
}
void performance_counter::reinit(
launch::sync_policy, bool reset, error_code& ec)
{
stubs::performance_counter::reinit(launch::sync, get_id(), reset, ec);
}

///
future<std::string> performance_counter::get_name() const
{
Expand Down
40 changes: 37 additions & 3 deletions src/performance_counters/performance_counter_set.cpp
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2017 Hartmut Kaiser
// Copyright (c) 2016-2018 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 @@ -214,7 +214,7 @@ namespace hpx { namespace performance_counters
return std::all_of(v.begin(), v.end(), [](bool val) { return val; });
}
catch (hpx::exception const& e) {
HPX_RETHROWS_IF(ec, e, "performance_counter_set::start");
HPX_RETHROWS_IF(ec, e, "performance_counter_set::stop");
return false;
}
}
Expand Down Expand Up @@ -247,7 +247,41 @@ namespace hpx { namespace performance_counters
hpx::util::unwrap(reset());
}
catch (hpx::exception const& e) {
HPX_RETHROWS_IF(ec, e, "performance_counter_set::start");
HPX_RETHROWS_IF(ec, e, "performance_counter_set::reset");
}
}

std::vector<hpx::future<void> > performance_counter_set::reinit(bool reset)
{
std::vector<hpx::id_type> ids;

{
std::unique_lock<mutex_type> l(mtx_);
ids = ids_;
}

std::vector<hpx::future<void> > v;
v.reserve(ids.size());

// re-initialize all performance counters
for (std::size_t i = 0; i != ids.size(); ++i)
{
using performance_counters::stubs::performance_counter;
v.push_back(
performance_counter::reinit(launch::async, ids[i], reset));
}

return v;
}

void performance_counter_set::reinit(
launch::sync_policy, bool reset, error_code& ec)
{
try {
hpx::util::unwrap(reinit(reset));
}
catch (hpx::exception const& e) {
HPX_RETHROWS_IF(ec, e, "performance_counter_set::reinit");
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/performance_counters/stubs/performance_counter_stub.cpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2018 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 @@ -79,6 +79,14 @@ namespace hpx { namespace performance_counters { namespace stubs
return hpx::async<action_type>(targetid);
}

lcos::future<void> performance_counter::reinit(launch::async_policy,
naming::id_type const& targetid, bool reset)
{
typedef server::base_performance_counter::reinit_action
action_type;
return hpx::async<action_type>(targetid, reset);
}

bool performance_counter::start(launch::sync_policy,
naming::id_type const& targetid, error_code& ec)
{
Expand All @@ -96,4 +104,10 @@ namespace hpx { namespace performance_counters { namespace stubs
{
reset(launch::async, targetid).get(ec);
}

void performance_counter::reinit(launch::sync_policy,
naming::id_type const& targetid, bool reset, error_code& ec)
{
reinit(launch::async, targetid, reset).get(ec);
}
}}}
22 changes: 20 additions & 2 deletions src/runtime.cpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2007-2018 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -330,7 +330,7 @@ namespace hpx
return *thread_support_;
}

///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void runtime::register_query_counters(
std::shared_ptr<util::query_counters> const& active_counters)
{
Expand All @@ -355,6 +355,12 @@ namespace hpx
active_counters_->reset_counters(ec);
}

void runtime::reinit_active_counters(bool reset, error_code& ec)
{
if (active_counters_.get())
active_counters_->reinit_counters(reset, ec);
}

void runtime::evaluate_active_counters(bool reset,
char const* description, error_code& ec)
{
Expand Down Expand Up @@ -1287,6 +1293,18 @@ namespace hpx
}
}

void reinit_active_counters(bool reset, error_code& ec)
{
runtime* rt = get_runtime_ptr();
if (nullptr != rt) {
rt->reinit_active_counters(reset, ec);
}
else {
HPX_THROWS_IF(ec, invalid_status, "reinit_active_counters",
"the runtime system is not available at this time");
}
}

void evaluate_active_counters(bool reset, char const* description, error_code& ec)
{
runtime* rt = get_runtime_ptr();
Expand Down

0 comments on commit ac55fa6

Please sign in to comment.