Ejemplo n.º 1
0
    ///////////////////////////////////////////////////////////////////////////
    /// Creation function for raw AGAS counters. This function checks the
    /// validity of the supplied counter name, it has to follow the scheme:
    ///
    ///   /agas(<objectinstance>/total)/<instancename>
    ///
    naming::gid_type agas_raw_counter_creator(
        counter_info const& info, error_code& ec, char const* const service_name)
    {
        // verify the validity of the counter instance name
        counter_path_elements paths;
        get_counter_path_elements(info.fullname_, paths, ec);
        if (ec) return naming::invalid_gid;

        if (paths.objectname_ != "agas") {
            HPX_THROWS_IF(ec, bad_parameter, "agas_raw_counter_creator",
                "unknown performance counter (unrelated to AGAS)");
            return naming::invalid_gid;
        }
        if (paths.parentinstance_is_basename_) {
            HPX_THROWS_IF(ec, bad_parameter, "agas_raw_counter_creator",
                "invalid counter instance parent name: " +
                    paths.parentinstancename_);
            return naming::invalid_gid;
        }

        // counter instance name: <agas_instance_name>/total
        // for instance: locality#0/total
        if (paths.instancename_ == "total" && paths.instanceindex_ == -1)
        {
            // find the referenced AGAS instance and dispatch the request there
            std::string service(agas::service_name);
            service += paths.parentinstancename_;

            if (-1 == paths.parentinstanceindex_) {
                HPX_THROWS_IF(ec, bad_parameter, "agas_raw_counter_creator",
                    "invalid parent instance index: -1");
                return naming::invalid_gid;
            }
            service += "#";
            service += boost::lexical_cast<std::string>(paths.parentinstanceindex_);

            service += "/";
            service += service_name;

            naming::id_type id;
            bool result = agas::resolve_name_sync(service, id, ec);
            if (!result) {
                HPX_THROWS_IF(ec, not_implemented,
                    "agas_raw_counter_creator",
                    "invalid counter name: " +
                        remove_counter_prefix(info.fullname_));
                return naming::invalid_gid;
            }

            return detail::retrieve_agas_counter(info.fullname_, id, ec);
        }

        HPX_THROWS_IF(ec, not_implemented, "agas_raw_counter_creator",
            "invalid counter type name: " + paths.instancename_);
        return naming::invalid_gid;
    }
Ejemplo n.º 2
0
        // create an arbitrary counter on this locality
        naming::gid_type create_counter_local(counter_info const& info)
        {
            // find create function for given counter
            error_code ec;

            create_counter_func f;
            get_runtime().get_counter_registry().get_counter_create_function(
                info, f, ec);
            if (ec) {
                HPX_THROW_EXCEPTION(bad_parameter, "create_counter_local",
                    "no create function for performance counter found: " +
                    remove_counter_prefix(info.fullname_) +
                        " (" + ec.get_message() + ")");
                return naming::invalid_gid;
            }

            counter_path_elements paths;
            get_counter_path_elements(info.fullname_, paths, ec);
            if (ec) return hpx::naming::invalid_gid;

            if (paths.parentinstancename_ == "locality" &&
                paths.parentinstanceindex_ !=
                    static_cast<boost::int64_t>(hpx::get_locality_id()))
            {
                HPX_THROW_EXCEPTION(bad_parameter, "create_counter_local",
                    "attempt to create counter on wrong locality ("
                     + ec.get_message() + ")");
                return hpx::naming::invalid_gid;
            }

            // attempt to create the new counter instance
            naming::gid_type gid = f(info, ec);
            if (ec) {
                HPX_THROW_EXCEPTION(bad_parameter, "create_counter_local",
                    "couldn't create performance counter: " +
                    remove_counter_prefix(info.fullname_) +
                        " (" + ec.get_message() + ")");
                return naming::invalid_gid;
            }

            return gid;
        }
Ejemplo n.º 3
0
Archivo: counters.hpp Proyecto: 41i/hpx
 inline std::string remove_counter_prefix(std::string const& counter) //-V659
 {
     std::string name(counter);
     return remove_counter_prefix(name);
 }
Ejemplo n.º 4
0
    /// Creation function for aggregating performance counters to be registered
    /// with the counter types.
    naming::gid_type arithmetics_counter_extended_creator(
        counter_info const& info, error_code& ec)
    {
        switch (info.type_) {
        case counter_aggregating:
            {
                counter_path_elements paths;
                get_counter_path_elements(info.fullname_, paths, ec);
                if (ec) return naming::invalid_gid;

                if (!paths.parameters_.empty()) {
                    // try to interpret the additional parameter as a list of
                    // two performance counter names
                    std::vector<std::string> names;
                    boost::split(names, paths.parameters_, boost::is_any_of(","));

                    if (names.empty())
                    {
                        HPX_THROWS_IF(ec, bad_parameter,
                            "arithmetics_counter_extended_creator",
                            "the parameter specification for an arithmetic counter "
                            "has to expand to at least one counter name: " +
                            paths.parameters_);
                        return naming::invalid_gid;
                    }

                    for (std::string const& name : names)
                    {
                        counter_path_elements paths;
                        if (status_valid_data != get_counter_path_elements(
                                name, paths, ec) || ec)
                        {
                            HPX_THROWS_IF(ec, bad_parameter,
                                "arithmetics_counter_extended_creator",
                                "the given (expanded) counter name is not "
                                "a validly formed performance counter name: " +
                                    name);
                            return naming::invalid_gid;
                        }
                    }

                    return create_arithmetics_counter_extended(info, names, ec);
                }
                else {
                    HPX_THROWS_IF(ec, bad_parameter,
                        "arithmetics_counter_extended_creator",
                        "the parameter specification for an arithmetic counter "
                        "has to be a comma separated list of performance "
                        "counter names, none is given: " +
                            remove_counter_prefix(info.fullname_));
                }
            }
            break;

        default:
            HPX_THROWS_IF(ec, bad_parameter,
                "arithmetics_counter_extended_creator",
                "invalid counter type requested");
            break;
        }
        return naming::invalid_gid;
    }