Skip to content

Commit

Permalink
Making sure statistics counters work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Jun 2, 2017
1 parent 9df93c3 commit 206f747
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions hpx/performance_counters/server/statistics_counter.hpp
Expand Up @@ -105,6 +105,7 @@ namespace hpx { namespace performance_counters { namespace server

boost::scoped_ptr<detail::counter_type_from_statistic_base> value_;
counter_value prev_value_;
bool has_prev_value_;

std::size_t parameter1_, parameter2_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/performance_counters/performance_counter_set.cpp
Expand Up @@ -265,7 +265,7 @@ namespace hpx { namespace performance_counters
// reset all performance counters
for (std::size_t i = 0; i != ids.size(); ++i)
{
if (infos_[i].type_ != counter_raw)
if (infos_[i].type_ == counter_histogram)
continue;

using performance_counters::stubs::performance_counter;
Expand Down
13 changes: 12 additions & 1 deletion src/performance_counters/server/statistics_counter.cpp
Expand Up @@ -258,6 +258,7 @@ namespace hpx { namespace performance_counters { namespace server
1000 * parameter1, info.fullname_, true),
base_counter_name_(ensure_counter_prefix(base_counter_name)),
value_(new detail::counter_type_from_statistic<Statistic>(parameter2)),
has_prev_value_(false),
parameter1_(parameter1), parameter2_(parameter2)
{
if (parameter1 == 0) {
Expand Down Expand Up @@ -288,6 +289,8 @@ namespace hpx { namespace performance_counters { namespace server
prev_value_.status_ = status_new_data;
prev_value_.time_ = static_cast<std::int64_t>(hpx::get_system_uptime());
prev_value_.count_ = ++invocation_count_;
has_prev_value_ = true;

value = prev_value_; // return value

if (reset || value_->need_reset())
Expand Down Expand Up @@ -345,9 +348,10 @@ namespace hpx { namespace performance_counters { namespace server
util::unlock_guard<std::unique_lock<mutex_type> > unlock(l);
base_counter_id = get_counter(base_counter_name_, ec);
}

// After reacquiring the lock, we need to check again if base_counter_id_
// hasn't been set yet
if(!base_counter_id_)
if (!base_counter_id_)
{
base_counter_id_ = base_counter_id;
}
Expand Down Expand Up @@ -383,6 +387,13 @@ namespace hpx { namespace performance_counters { namespace server

value = stubs::performance_counter::get_value(
launch::sync, base_counter_id_);

if (!has_prev_value_)
{
has_prev_value_ = true;
prev_value_ = value;
}

return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/util/query_counters.cpp
Expand Up @@ -108,6 +108,7 @@ namespace hpx { namespace util
void query_counters::stop_evaluating_counters()
{
timer_.stop();
counters_.stop(launch::sync);
}

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -411,7 +412,7 @@ namespace hpx { namespace util

for (std::size_t i = 0; i != infos.size(); ++i)
{
if (infos[i].type_ != performance_counters::counter_raw)
if (infos[i].type_ == performance_counters::counter_histogram)
continue;
indicies.push_back(i);
}
Expand Down
1 change: 1 addition & 0 deletions tests/regressions/performance_counters/CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@

set(tests
discover_counters_1787
statistics_2666
uptime_1737)

if(HPX_WITH_PAPI)
Expand Down
27 changes: 27 additions & 0 deletions tests/regressions/performance_counters/statistics_2666.cpp
@@ -0,0 +1,27 @@
// 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)

#include <hpx/hpx.hpp>
#include <hpx/hpx_main.hpp>
#include <hpx/util/lightweight_test.hpp>

int main()
{
using hpx::performance_counters::performance_counter;

performance_counter average("/statistics{/runtime/uptime}/average@200");
average.start(hpx::launch::sync);

hpx::this_thread::sleep_for(std::chrono::seconds(1));
double val1 = average.get_value<double>(hpx::launch::sync);
hpx::this_thread::sleep_for(std::chrono::seconds(1));
double val2 = average.get_value<double>(hpx::launch::sync);

HPX_TEST_NEQ(val1, val2);

average.stop(hpx::launch::sync);

return hpx::util::report_errors();
}

0 comments on commit 206f747

Please sign in to comment.