Skip to content

Commit

Permalink
Adding pool specific performance counters
Browse files Browse the repository at this point in the history
- for instance /threadqueue{locality#0/pool#default/worker-thread#1}/length
  • Loading branch information
hkaiser committed Jul 29, 2017
1 parent 45fccbd commit 2f5062f
Show file tree
Hide file tree
Showing 11 changed files with 527 additions and 117 deletions.
10 changes: 10 additions & 0 deletions hpx/performance_counters/counter_creators.hpp
Expand Up @@ -55,6 +55,16 @@ namespace hpx { namespace performance_counters
HPX_API_EXPORT bool locality_thread_counter_discoverer(counter_info const&,
discover_counter_func const&, discover_counters_mode, error_code&);

/// Default discoverer function for performance counters; to be registered
/// with the counter types. It is suitable to be used for all counters
/// following the naming scheme:
///
/// /<objectname>{locality#<locality_id>/pool#<poolnum>/thread#<threadnum>}/<instancename>
///
bool locality_pool_thread_counter_discoverer(counter_info const& info,
discover_counter_func const& f,
discover_counters_mode mode, error_code& ec);

/// Default discoverer function for performance counters; to be registered
/// with the counter types. It is suitable to be used for all counters
/// following the naming scheme:
Expand Down
26 changes: 23 additions & 3 deletions hpx/performance_counters/counters.hpp
Expand Up @@ -242,14 +242,33 @@ namespace hpx { namespace performance_counters
bool parentinstance_is_basename = false)
: counter_type_path_elements(objectname, countername, parameters),
parentinstancename_(parentname), instancename_(instancename),
subinstancename_(),
parentinstanceindex_(parentindex), instanceindex_(instanceindex),
subinstanceindex_(-1),
parentinstance_is_basename_(parentinstance_is_basename)
{}

counter_path_elements(std::string const& objectname,
std::string const& countername, std::string const& parameters,
std::string const& parentname, std::string const& instancename,
std::string const& subinstancename,
std::int64_t parentindex = -1, std::int64_t instanceindex = -1,
std::int64_t subinstanceindex = -1,
bool parentinstance_is_basename = false)
: counter_type_path_elements(objectname, countername, parameters),
parentinstancename_(parentname), instancename_(instancename),
subinstancename_(subinstancename),
parentinstanceindex_(parentindex), instanceindex_(instanceindex),
subinstanceindex_(subinstanceindex),
parentinstance_is_basename_(parentinstance_is_basename)
{}

std::string parentinstancename_; ///< the name of the parent instance
std::string instancename_; ///< the name of the object instance
std::string subinstancename_; ///< the name of the object sub-instance
std::int64_t parentinstanceindex_; ///< the parent instance index
std::int64_t instanceindex_; ///< the instance index
std::int64_t subinstanceindex_; ///< the sub-instance index
bool parentinstance_is_basename_; ///< the parentinstancename_
///member holds a base counter name

Expand All @@ -264,9 +283,10 @@ namespace hpx { namespace performance_counters
hpx::serialization::base_object_type<
counter_path_elements, base_type> base =
hpx::serialization::base_object<base_type>(*this);
ar & base & parentinstancename_ & instancename_ &
parentinstanceindex_ & instanceindex_ &
parentinstance_is_basename_;
ar & base &
parentinstancename_ & instancename_ & subinstancename_ &
parentinstanceindex_ & instanceindex_ & subinstanceindex_ &
parentinstance_is_basename_;
}
};

Expand Down
28 changes: 14 additions & 14 deletions hpx/runtime/resource_partitioner.hpp
Expand Up @@ -195,6 +195,7 @@ namespace resource {
scheduler_function create_function_;
};

///////////////////////////////////////////////////////////////////////////
class HPX_EXPORT resource_partitioner
{
public:
Expand Down Expand Up @@ -259,16 +260,20 @@ namespace resource {
std::size_t init();

////////////////////////////////////////////////////////////////////////

scheduling_policy which_scheduler(const std::string &pool_name);
threads::topology &get_topology() const;
util::command_line_handling &get_command_line_switches();

std::size_t get_num_threads() const;
size_t get_num_pools() const;
size_t get_num_threads(const std::string &pool_name) const;
size_t get_num_threads(std::size_t pool_index) const;
init_pool_data const& get_pool(std::size_t pool_index) const;
const std::string &get_pool_name(size_t index) const;
std::size_t get_num_pools() const;
std::size_t get_num_threads(std::string const& pool_name) const;
std::size_t get_num_threads(std::size_t pool_index) const;

init_pool_data const& get_pool_data(std::size_t pool_index) const;

std::string const& get_pool_name(std::size_t index) const;
std::size_t get_pool_index(const std::string &pool_name) const;

size_t get_pu_num(std::size_t global_thread_num);
threads::mask_cref_type get_pu_mask(
std::size_t num_thread, bool numa_sensitive) const;
Expand All @@ -291,27 +296,22 @@ namespace resource {

private:
////////////////////////////////////////////////////////////////////////

void fill_topology_vectors();

////////////////////////////////////////////////////////////////////////

// called in hpx_init run_or_start
void set_init_affinity_data();
void setup_pools();
void setup_schedulers();
void reconfigure_affinities();
bool check_empty_pools() const;

//! this is ugly, I should probably delete it
uint64_t get_pool_index(const std::string &pool_name) const;

// has to be private bc pointers become invalid after data member
// thread_pools_ is resized
// we don't want to allow the user to use it
init_pool_data const& get_pool(const std::string &pool_name) const;
init_pool_data& get_pool(const std::string &pool_name);
init_pool_data& get_default_pool();
init_pool_data const& get_pool_data(const std::string &pool_name) const;
init_pool_data& get_pool_data(std::string const& pool_name);
init_pool_data& get_default_pool_data();

////////////////////////////////////////////////////////////////////////

Expand Down
3 changes: 2 additions & 1 deletion hpx/runtime/threads/detail/thread_pool.hpp
Expand Up @@ -12,6 +12,7 @@
#include <hpx/compat/thread.hpp>
#include <hpx/exception_fwd.hpp>
#include <hpx/lcos/local/no_mutex.hpp>
#include <hpx/runtime/thread_pool_helpers.hpp>
#include <hpx/runtime/threads/cpu_mask.hpp>
#include <hpx/runtime/threads/policies/affinity_data.hpp>
#include <hpx/runtime/threads/policies/callback_notifier.hpp>
Expand Down Expand Up @@ -69,7 +70,7 @@ namespace hpx { namespace threads { namespace detail

///////////////////////////////////////////////////////////////////////////
// note: this data structure has to be protected from races from the outside
class HPX_EXPORT thread_pool
class thread_pool
{
public:
thread_pool(threads::policies::callback_notifier& notifier,
Expand Down
4 changes: 4 additions & 0 deletions hpx/runtime/threads/threadmanager.hpp
Expand Up @@ -75,6 +75,7 @@ namespace hpx { namespace threads

// Get functions
detail::thread_pool& default_pool() const;

scheduler_type& default_scheduler() const;

detail::thread_pool& get_pool(std::string const& pool_name) const;
Expand Down Expand Up @@ -319,6 +320,9 @@ namespace hpx { namespace threads
naming::gid_type busy_loop_count_counter_creator(
performance_counters::counter_info const& info, error_code& ec);

// performance counters
std::int64_t get_queue_length();

private:
mutable mutex_type mtx_; // mutex protecting the members

Expand Down
63 changes: 63 additions & 0 deletions src/performance_counters/counter_creators.cpp
Expand Up @@ -187,6 +187,69 @@ namespace hpx { namespace performance_counters
return true;
}

/// Default discoverer function for performance counters; to be registered
/// with the counter types. It is suitable to be used for all counters
/// following the naming scheme:
///
/// /<objectname>{locality#<locality_id>/pool#<poolnum>/thread#<threadnum>}/<instancename>
///
bool locality_pool_thread_counter_discoverer(counter_info const& info,
discover_counter_func const& f,
discover_counters_mode mode, error_code& ec)
{
performance_counters::counter_info i = info;

// compose the counter name templates
performance_counters::counter_path_elements p;
performance_counters::counter_status status =
get_counter_path_elements(info.fullname_, p, ec);
if (!status_is_valid(status)) return false;

if (mode == discover_counters_minimal ||
p.parentinstancename_.empty() || p.instancename_.empty() ||
p.subinstancename_.empty())
{
if (p.parentinstancename_.empty())
{
p.parentinstancename_ = "locality#*";
p.parentinstanceindex_ = -1;
}

if (p.instancename_.empty())
{
p.instancename_ = "total";
p.instanceindex_ = -1;
}
else if (p.subinstancename_.empty())
{
p.subinstancename_ = "total";
p.instanceindex_ = -1;
}

status = get_counter_name(p, i.fullname_, ec);
if (!status_is_valid(status) || !f(i, ec) || ec)
return false;

p.instancename_ = "pool#*";
p.instanceindex_ = -1;

p.subinstancename_ = "worker-thread#*";
p.subinstanceindex_ = -1;

status = get_counter_name(p, i.fullname_, ec);
if (!status_is_valid(status) || !f(i, ec) || ec)
return false;
}
else if (!f(i, ec) || ec) {
return false;
}

if (&ec != &throws)
ec = make_success_code();

return true;
}

/// Default discoverer function for performance counters; to be registered
/// with the counter types. It is suitable to be used for all counters
/// following the naming scheme:
Expand Down

0 comments on commit 2f5062f

Please sign in to comment.