Skip to content

Commit

Permalink
Fixed #598: Need an API that accesses the performance counter reporti…
Browse files Browse the repository at this point in the history
…ng the system uptime
  • Loading branch information
hkaiser committed Nov 3, 2012
1 parent 4f3d171 commit 60b6432
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
8 changes: 8 additions & 0 deletions hpx/hpx_fwd.hpp
Expand Up @@ -920,6 +920,14 @@ namespace hpx
/// identifies the thread in the context of HPX. If the function is called
/// while no HPX runtime system is active, it will return zero.
HPX_API_EXPORT std::string const* get_thread_name();

///////////////////////////////////////////////////////////////////////////
/// \brief Return the system uptime measure on the thread executing this call.
///
/// This function returns the system uptime measured in nanoseconds for the
/// thread executing this call. If the function is called while no HPX
/// runtime system is active, it will return zero.
HPX_API_EXPORT boost::uint64_t get_system_uptime();
}

#include <hpx/lcos/async_fwd.hpp>
Expand Down
3 changes: 0 additions & 3 deletions hpx/performance_counters/server/elapsed_time_counter.hpp
Expand Up @@ -46,9 +46,6 @@ namespace hpx { namespace performance_counters { namespace server
{
base_type::set_component_type(t);
}

private:
boost::int64_t started_at_;
};
}}}

Expand Down
6 changes: 5 additions & 1 deletion hpx/runtime.hpp
Expand Up @@ -93,8 +93,9 @@ namespace hpx
// the TSS holds a pointer to the runtime associated with a given
// OS thread
struct tls_tag {};
static hpx::util::thread_specific_ptr<runtime*, tls_tag> runtime_;
static util::thread_specific_ptr<runtime*, tls_tag> runtime_;
static util::thread_specific_ptr<std::string, tls_tag> thread_name_;
static util::thread_specific_ptr<boost::uint64_t, tls_tag> uptime_;

/// \brief access configuration information
util::runtime_configuration& get_config()
Expand All @@ -114,6 +115,9 @@ namespace hpx
/// \brief Return the name of the calling thread.
static std::string const* get_thread_name();

/// \brief Return the system uptime measure on the thread executing this call
static boost::uint64_t runtime::get_system_uptime();

/// \brief Allow access to the registry counter registry instance used
/// by the HPX runtime.
performance_counters::registry& get_counter_registry()
Expand Down
8 changes: 3 additions & 5 deletions src/performance_counters/server/elapsed_time_counter.cpp
Expand Up @@ -28,8 +28,7 @@ HPX_DEFINE_GET_COMPONENT_TYPE(
namespace hpx { namespace performance_counters { namespace server
{
elapsed_time_counter::elapsed_time_counter(counter_info const& info)
: base_type_holder(info),
started_at_(static_cast<boost::int64_t>(util::high_resolution_clock::now()))
: base_type_holder(info)
{
if (info.type_ != counter_elapsed_time) {
HPX_THROW_EXCEPTION(bad_parameter,
Expand All @@ -41,12 +40,11 @@ namespace hpx { namespace performance_counters { namespace server
void elapsed_time_counter::get_counter_value(counter_value& value)
{
// gather the current value
boost::int64_t now = static_cast<boost::int64_t>(util::high_resolution_clock::now());
value.value_ = now - started_at_;
value.value_ = static_cast<boost::int64_t>(hpx::get_system_uptime());
value.scaling_ = 1000000000LL; // coefficient to get seconds
value.scale_inverse_ = true;
value.status_ = status_new_data;
value.time_ = static_cast<boost::uint64_t>(now);
value.time_ = static_cast<boost::uint64_t>(util::high_resolution_clock::now());
value.count_ = ++invocation_count_;
}
}}}
Expand Down
19 changes: 17 additions & 2 deletions src/runtime.cpp
Expand Up @@ -16,6 +16,7 @@
#include <hpx/runtime/threads/threadmanager.hpp>
#include <hpx/include/performance_counters.hpp>
#include <hpx/runtime/agas/big_boot_barrier.hpp>
#include <hpx/util/high_resolution_clock.hpp>

#if defined(HPX_HAVE_HWLOC)
#include <hpx/runtime/threads/policies/hwloc_topology.hpp>
Expand Down Expand Up @@ -180,8 +181,9 @@ namespace hpx


///////////////////////////////////////////////////////////////////////////
hpx::util::thread_specific_ptr<runtime *, runtime::tls_tag> runtime::runtime_;
hpx::util::thread_specific_ptr<std::string, runtime::tls_tag> runtime::thread_name_;
util::thread_specific_ptr<runtime *, runtime::tls_tag> runtime::runtime_;
util::thread_specific_ptr<std::string, runtime::tls_tag> runtime::thread_name_;
util::thread_specific_ptr<boost::uint64_t, runtime::tls_tag> runtime::uptime_;

void runtime::init_tss()
{
Expand All @@ -191,6 +193,7 @@ namespace hpx
BOOST_ASSERT(NULL == threads::coroutine_type::impl_type::get_self());

runtime::runtime_.reset(new runtime* (this));
runtime::uptime_.reset(new boost::uint64_t (util::high_resolution_clock::now()));
threads::coroutine_type::impl_type::init_self();
}
}
Expand All @@ -199,6 +202,7 @@ namespace hpx
{
// reset our TSS
threads::coroutine_type::impl_type::reset_self();
runtime::uptime_.reset();
runtime::runtime_.reset();
}

Expand All @@ -207,6 +211,12 @@ namespace hpx
return runtime::thread_name_.get();
}

boost::uint64_t runtime::get_system_uptime()
{
boost::int64_t diff = util::high_resolution_clock::now() - *runtime::uptime_.get();
return diff < 0LL ? 0ULL : static_cast<boost::uint64_t>(diff);
}

/// \brief Register all performance counter types related to this runtime
/// instance
void runtime::register_counter_types()
Expand Down Expand Up @@ -548,5 +558,10 @@ namespace hpx
{
return runtime::get_thread_name();
}

boost::uint64_t get_system_uptime()
{
return runtime::get_system_uptime();
}
}

0 comments on commit 60b6432

Please sign in to comment.