Skip to content

Commit

Permalink
More work on #731
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Mar 1, 2013
1 parent 764449d commit dffb281
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 53 deletions.
8 changes: 5 additions & 3 deletions hpx/hpx_fwd.hpp
Expand Up @@ -1098,7 +1098,9 @@ namespace hpx
/// \brief Query all active performance counters, optionally naming the
/// point in code marked by this function,
///
/// \param description [in] this is a optional value naming the point in
/// \param reset [in] this is an optional falg allowing to reset
/// the counter value after it has been evaluated.
/// \param description [in] this is an optional value naming the point in
/// the code marked by the call to this function.
/// \param ec [in,out] this represents the error status on exit, if this
/// is pre-initialized to \a hpx#throws the function will throw
Expand All @@ -1116,8 +1118,8 @@ namespace hpx
/// \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 evaluate_active_counters(char const* description = 0,
error_code& ec = throws);
HPX_API_EXPORT void evaluate_active_counters(bool reset = false,
char const* description = 0, error_code& ec = throws);
}

#include <hpx/lcos/async_fwd.hpp>
Expand Down
2 changes: 1 addition & 1 deletion hpx/performance_counters/performance_counter.hpp
Expand Up @@ -25,7 +25,7 @@ namespace hpx { namespace performance_counters
virtual counter_info get_counter_info() const = 0;

// Retrieve the current Performance Counter value.
virtual counter_value get_counter_value() = 0;
virtual counter_value get_counter_value(bool reset = false) = 0;

// Reset the Performance Counter (value).
virtual void reset_counter_value() = 0;
Expand Down
3 changes: 2 additions & 1 deletion hpx/performance_counters/server/aggregating_counter.hpp
Expand Up @@ -175,7 +175,8 @@ namespace hpx { namespace performance_counters { namespace server
boost::uint64_t parameter1, boost::uint64_t parameter2);

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

bool start();

Expand Down
8 changes: 4 additions & 4 deletions hpx/performance_counters/server/base_performance_counter.hpp
Expand Up @@ -82,9 +82,9 @@ namespace hpx { namespace performance_counters { namespace server
return this->get_counter_info();
}

counter_value get_counter_value_nonvirt()
counter_value get_counter_value_nonvirt(bool reset)
{
return this->get_counter_value();
return this->get_counter_value(reset);
}

void set_counter_value_nonvirt(counter_value const& info)
Expand Down Expand Up @@ -120,8 +120,8 @@ namespace hpx { namespace performance_counters { namespace server

/// The \a get_counter_value_action queries the value of a performance
/// counter.
typedef hpx::actions::result_action0<
base_performance_counter, counter_value,
typedef hpx::actions::result_action1<
base_performance_counter, counter_value, bool,
&base_performance_counter::get_counter_value_nonvirt
> get_counter_value_action;

Expand Down
2 changes: 1 addition & 1 deletion hpx/performance_counters/server/elapsed_time_counter.hpp
Expand Up @@ -28,7 +28,7 @@ namespace hpx { namespace performance_counters { namespace server
elapsed_time_counter() {}
elapsed_time_counter(counter_info const& info);

hpx::performance_counters::counter_value get_counter_value();
hpx::performance_counters::counter_value get_counter_value(bool reset);

/// \brief finalize() will be called just before the instance gets
/// destructed
Expand Down
3 changes: 2 additions & 1 deletion hpx/performance_counters/server/raw_counter.hpp
Expand Up @@ -25,7 +25,8 @@ namespace hpx { namespace performance_counters { namespace server
raw_counter() {}
raw_counter(counter_info const& info, HPX_STD_FUNCTION<boost::int64_t(bool)> f);

hpx::performance_counters::counter_value get_counter_value();
hpx::performance_counters::counter_value
get_counter_value(bool reset = false);
void reset_counter_value();

/// \brief finalize() will be called just before the instance gets
Expand Down
7 changes: 4 additions & 3 deletions hpx/performance_counters/stubs/performance_counter.hpp
Expand Up @@ -19,7 +19,7 @@ namespace hpx { namespace performance_counters { namespace stubs
static lcos::future<counter_info> get_info_async(
naming::id_type const& targetid);
static lcos::future<counter_value> get_value_async(
naming::id_type const& targetid);
naming::id_type const& targetid, bool reset = false);

static counter_info get_info(naming::id_type const& targetid,
error_code& ec = throws);
Expand All @@ -40,9 +40,10 @@ namespace hpx { namespace performance_counters { namespace stubs

template <typename T>
static T
get_typed_value(naming::id_type const& targetid, error_code& ec = throws)
get_typed_value(naming::id_type const& targetid, bool reset = false,
error_code& ec = throws)
{
counter_value value = get_value(targetid);
counter_value value = get_value(targetid, reset);
return value.get_value<T>(ec);
}
};
Expand Down
4 changes: 2 additions & 2 deletions hpx/runtime.hpp
Expand Up @@ -214,8 +214,8 @@ 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 evaluate_active_counters(char const* description = 0,
error_code& ec = throws);
void evaluate_active_counters(bool reset = false,
char const* description = 0, error_code& ec = throws);

protected:
void init_tss();
Expand Down
4 changes: 2 additions & 2 deletions hpx/util/query_counters.hpp
Expand Up @@ -35,8 +35,8 @@ 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);
bool evaluate_counters(char const* description = 0,
error_code& ec = throws);
bool evaluate_counters(bool reset = false,
char const* description = 0, error_code& ec = throws);

protected:
void find_counters();
Expand Down
4 changes: 2 additions & 2 deletions src/performance_counters/server/aggregating_counter.cpp
Expand Up @@ -53,7 +53,7 @@ namespace hpx { namespace performance_counters { namespace server

template <typename Statistic>
hpx::performance_counters::counter_value
aggregating_counter<Statistic>::get_counter_value()
aggregating_counter<Statistic>::get_counter_value(bool reset)
{
mutex_type::scoped_lock l(mtx_);

Expand All @@ -65,7 +65,7 @@ namespace hpx { namespace performance_counters { namespace server
prev_value_.count_ = ++invocation_count_;
value = prev_value_; // return value

if (detail::counter_type_from_statistic<Statistic>::need_reset::value)
if (reset || detail::counter_type_from_statistic<Statistic>::need_reset::value)
{
value_.reset(detail::counter_type_from_statistic<Statistic>::create(
parameter2_)); // reset accumulator
Expand Down
2 changes: 1 addition & 1 deletion src/performance_counters/server/elapsed_time_counter.cpp
Expand Up @@ -38,7 +38,7 @@ namespace hpx { namespace performance_counters { namespace server
}

hpx::performance_counters::counter_value
elapsed_time_counter::get_counter_value()
elapsed_time_counter::get_counter_value(bool)
{
// gather the current value
boost::int64_t now = static_cast<boost::int64_t>(hpx::get_system_uptime());
Expand Down
8 changes: 4 additions & 4 deletions src/performance_counters/server/raw_counter.cpp
Expand Up @@ -28,7 +28,7 @@ namespace hpx { namespace performance_counters { namespace server
{
raw_counter::raw_counter(counter_info const& info,
HPX_STD_FUNCTION<boost::int64_t(bool)> f)
: base_type_holder(info), f_(f), reset_(false)
: base_type_holder(info), f_(f)
{
if (info.type_ != counter_raw) {
HPX_THROW_EXCEPTION(bad_parameter,
Expand All @@ -38,10 +38,10 @@ namespace hpx { namespace performance_counters { namespace server
}

hpx::performance_counters::counter_value
raw_counter::get_counter_value()
raw_counter::get_counter_value(bool reset)
{
hpx::performance_counters::counter_value value;
value.value_ = f_(reset_); // gather the current value
value.value_ = f_(reset); // gather the current value
reset_ = false;
value.scaling_ = 1;
value.scale_inverse_ = false;
Expand All @@ -53,7 +53,7 @@ namespace hpx { namespace performance_counters { namespace server

void raw_counter::reset_counter_value()
{
reset_ = true;
f_(true);
}
}}}

4 changes: 2 additions & 2 deletions src/performance_counters/stubs/performance_counter.cpp
Expand Up @@ -19,10 +19,10 @@ namespace hpx { namespace performance_counters { namespace stubs
}

lcos::future<counter_value> performance_counter::get_value_async(
naming::id_type const& targetid)
naming::id_type const& targetid, bool reset)
{
typedef server::base_performance_counter::get_counter_value_action action_type;
return hpx::async<action_type>(targetid);
return hpx::async<action_type>(targetid, reset);
}

counter_info performance_counter::get_info(naming::id_type const& targetid,
Expand Down
9 changes: 5 additions & 4 deletions src/runtime.cpp
Expand Up @@ -235,10 +235,11 @@ namespace hpx
active_counters_->reset_counters(ec);
}

void runtime::evaluate_active_counters(char const* description, error_code& ec)
void runtime::evaluate_active_counters(bool reset,
char const* description, error_code& ec)
{
if (active_counters_.get())
active_counters_->evaluate_counters(description, ec);
active_counters_->evaluate_counters(reset, description, ec);
}

/// \brief Register all performance counter types related to this runtime
Expand Down Expand Up @@ -695,11 +696,11 @@ namespace hpx
}
}

void evaluate_active_counters(char const* description, error_code& ec)
void evaluate_active_counters(bool reset, char const* description, error_code& ec)
{
runtime* rt = get_runtime_ptr();
if (NULL != rt) {
rt->evaluate_active_counters(description, ec);
rt->evaluate_active_counters(reset, description, ec);
}
else {
HPX_THROWS_IF(ec, invalid_status, "evaluate_active_counters",
Expand Down
40 changes: 18 additions & 22 deletions src/util/query_counters.cpp
Expand Up @@ -8,6 +8,7 @@
#include <hpx/runtime/threads/thread_helpers.hpp>
#include <hpx/util/query_counters.hpp>
#include <hpx/util/high_resolution_clock.hpp>
#include <hpx/util/stringstream.hpp>
#include <hpx/util/apex.hpp>
#include <hpx/runtime/actions/continuation.hpp>
#include <hpx/performance_counters/counters.hpp>
Expand Down Expand Up @@ -234,7 +235,8 @@ namespace hpx { namespace util
wait_all(reset, ec);
}

bool query_counters::evaluate_counters(char const* description, error_code& ec)
bool query_counters::evaluate_counters(bool reset,
char const* description, error_code& ec)
{
if (timer_.is_terminated())
{
Expand Down Expand Up @@ -263,34 +265,28 @@ namespace hpx { namespace util
// Query the performance counters.
using performance_counters::stubs::performance_counter;
std::vector<future<performance_counters::counter_value> > values;

values.reserve(ids_.size());
for (std::size_t i = 0; i < ids_.size(); ++i)
values.push_back(performance_counter::get_value_async(ids_[i]));
values.push_back(performance_counter::get_value_async(ids_[i], reset));

util::osstream output;
if (description)
output << description << std::endl;

// wait for all values to be returned
wait_all(values, ec);

if (description) {
if (destination_is_cout) {
std::cout << description << std::endl;
}
else {
std::ofstream out(destination_, std::ios_base::app);
out << description << std::endl;
}
}

// print the values
// Output the performance counter value.
for (std::size_t i = 0; i < values.size(); ++i)
{
// Output the performance counter value.
if (destination_is_cout) {
print_value(std::cout, names_[i], values[i].get(), uoms_[i]);
}
else {
std::ofstream out(destination_, std::ios_base::app);
print_value(out, names_[i], values[i].get(), uoms_[i]);
}
print_value(output, names_[i], values[i].get(), uoms_[i]);

if (destination_is_cout) {
std::cout << util::osstream_get_string(output);
}
else {
std::ofstream out(destination_, std::ios_base::app);
out << util::osstream_get_string(output);
}

return true;
Expand Down

0 comments on commit dffb281

Please sign in to comment.