Example #1
0
    /// 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>/total}/<instancename>
    ///
    bool locality_counter_discoverer(counter_info const& info,
        HPX_STD_FUNCTION<discover_counter_func> const& f, 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;

        p.parentinstancename_ = "locality#<*>";
        p.parentinstanceindex_ = -1;
        p.instancename_ = "total";
        p.instanceindex_ = -1;

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

//         boost::uint32_t last_locality = get_num_localities();
//         for (boost::uint32_t l = 0; l < last_locality; ++l)
//         {
//             p.parentinstanceindex_ = static_cast<boost::int32_t>(l);
//             status = get_counter_name(p, i.fullname_, ec);
//             if (!status_is_valid(status) || !f(i, ec) || ec)
//                 return false;
//         }

        if (&ec != &throws)
            ec = make_success_code();
        return true;
    }
Example #2
0
    /// 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>(<objectinstance>/total)/<instancename>
    ///
    bool agas_counter_discoverer(counter_info const& info,
        HPX_STD_FUNCTION<discover_counter_func> const& f, error_code& ec)
    {
        performance_counters::counter_info i_ = info;

        // compose the counter names
        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;

        p.parentinstancename_ = "agas";
        p.parentinstanceindex_ = -1;
        p.instanceindex_ = -1;

        // list all counter related to agas
        for (std::size_t i = 0;
             i < sizeof(agas::detail::counter_services)/sizeof(agas::detail::counter_services[0]);
             ++i)
        {
            p.instancename_ = agas::detail::counter_services[i].name_;
            status = get_counter_name(p, i_.fullname_, ec);
            if (!status_is_valid(status) || !f(i_, ec) || ec)
                return false;
        }
        return true;
    }
Example #3
0
File: counters.hpp Project: 41i/hpx
        T get_value(error_code& ec = throws) const
        {
            if (!status_is_valid(status_)) {
                HPX_THROWS_IF(ec, invalid_status,
                    "counter_value::get_value<T>",
                    "counter value is in invalid status");
                return T();
            }

            T val = static_cast<T>(value_);

            if (scaling_ != 1) {
                if (scaling_ == 0) {
                    HPX_THROWS_IF(ec, uninitialized_value,
                        "counter_value::get_value<T>",
                        "scaling should not be zero");
                    return T();
                }

                // calculate and return the real counter value
                if (scale_inverse_)
                    return val / static_cast<T>(scaling_);

                return val * static_cast<T>(scaling_);
            }
            return val;
        }
Example #4
0
    T get_value(std::size_t index, error_code& ec = throws) const
    {
        if (!status_is_valid(status_)) {
            HPX_THROWS_IF(ec, invalid_status,
                          "counter_values_array::get_value<T>",
                          "counter value is in invalid status");
            return T();
        }
        if (index >= values_.size()) {
            HPX_THROWS_IF(ec, bad_parameter,
                          "counter_values_array::get_value<T>",
                          "index out of bounds");
            return T();
        }

        T val = static_cast<T>(values_[index]);

        if (scaling_ != 1) {
            if (scaling_ == 0) {
                HPX_THROWS_IF(ec, uninitialized_value,
                              "counter_values_array::get_value<T>",
                              "scaling should not be zero");
                return T();
            }

            // calculate and return the real counter value
            if (scale_inverse_)
                return val / static_cast<T>(scaling_);

            return val * static_cast<T>(scaling_);
        }
        return val;
    }
Example #5
0
        bool expand_counter_info_localities(
            counter_info& i, counter_path_elements& p,
            discover_counter_func const& f, error_code& ec)
        {
            bool expand_threads = false;
            if (is_thread_kind(p.instancename_))
            {
                p.instancename_ = get_thread_kind(p.instancename_) + "-thread";
                expand_threads = true;
            }

            boost::uint32_t last_locality = get_num_localities_sync();
            for (boost::uint32_t l = 0; l != last_locality; ++l)
            {
                p.parentinstanceindex_ = static_cast<boost::int32_t>(l);
                if (expand_threads) {
                    if (!detail::expand_counter_info_threads(i, p, f, ec))
                        return false;
                }
                else {
                    counter_status status = get_counter_name(p, i.fullname_, ec);
                    if (!status_is_valid(status) || !f(i, ec) || ec)
                        return false;
                }
            }
            return true;
        }
Example #6
0
    /// 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>/thread#<threadnum>}/<instancename>
    ///
    bool locality_thread_counter_discoverer(counter_info const& info,
        HPX_STD_FUNCTION<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())
        {
            if (p.parentinstancename_.empty())
            {
                p.parentinstancename_ = "locality#*";
                p.parentinstanceindex_ = -1;
            }

            if (p.instancename_.empty())
            {
                p.instancename_ = "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_ = "worker-thread#*";
            p.instanceindex_ = -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;
    }
Example #7
0
        ///////////////////////////////////////////////////////////////////////
        /// Expand all wild-cards in a counter base name (for aggregate counters)
        bool expand_basecounter(
            counter_info const& info, counter_path_elements& p,
            discover_counter_func const& f, error_code& ec)
        {
            // discover all base names
            std::vector<counter_info> counter_infos;
            counter_status status = discover_counter_type(p.parentinstancename_,
                counter_infos, discover_counters_full, ec);
            if (!status_is_valid(status) || ec)
                return false;

            counter_info i = info;
            for (counter_info& basei : counter_infos)
            {
                p.parentinstancename_ = basei.fullname_;
                counter_status status = get_counter_name(p, i.fullname_, ec);
                if (!status_is_valid(status) || !f(i, ec) || ec)
                    return false;
            }
            return true;
        }
Example #8
0
 ///////////////////////////////////////////////////////////////////////
 // expand main counter name
 bool expand_counter_info_threads(
     counter_info& i, counter_path_elements& p,
     discover_counter_func const& f, error_code& ec)
 {
     std::size_t num_threads = get_os_thread_count();
     for (std::size_t l = 0; l != num_threads; ++l)
     {
         p.instanceindex_ = static_cast<boost::int64_t>(l);
         counter_status status = get_counter_name(p, i.fullname_, ec);
         if (!status_is_valid(status) || !f(i, ec) || ec)
             return false;
     }
     return true;
 }