• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/full/performance_counters/src/server/component_instance_counter.cpp
1
//  Copyright (c) 2007-2025 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/config.hpp>
8
#include <hpx/components_base/agas_interface.hpp>
9
#include <hpx/components_base/component_type.hpp>
10
#include <hpx/modules/errors.hpp>
11
#include <hpx/modules/functional.hpp>
12
#include <hpx/performance_counters/counter_creators.hpp>
13
#include <hpx/performance_counters/counters.hpp>
14

15
#include <cstdint>
16
#include <sstream>
17
#include <utility>
18

19
///////////////////////////////////////////////////////////////////////////////
20
namespace hpx::performance_counters::detail {
21

22
    ///////////////////////////////////////////////////////////////////////////
23
    // Extract the current number of instances for the given component type
24
    static std::int64_t get_instance_count(components::component_type type)
×
25
    {
26
        return hpx::components::instance_count(type);
×
27
    }
28

29
    ///////////////////////////////////////////////////////////////////////////
30
    /// Creation function for instance counter
31
    naming::gid_type component_instance_counter_creator(
×
32
        counter_info const& info, error_code& ec)
33
    {
34
        if (info.type_ != counter_type::raw)
×
35
        {
36
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
37
                "component_instance_counter_creator",
38
                "invalid counter type requested");
39
            return naming::invalid_gid;
×
40
        }
×
41

42
        counter_path_elements paths;
43
        get_counter_path_elements(info.fullname_, paths, ec);
×
44
        if (ec)
45
            return naming::invalid_gid;
×
46

47
        if (paths.parentinstance_is_basename_)
48
        {
49
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
50
                "component_instance_counter_creator",
51
                "invalid instance counter name (instance name must not "
52
                "be a valid base counter name)");
×
53
            return naming::invalid_gid;
54
        }
×
55

56
        if (paths.parameters_.empty())
57
        {
×
58
            std::stringstream strm;
59
            strm << "invalid instance counter parameter: must specify "
×
60
                    "a component type\n"
×
61
                    "known component types:\n";
×
62

×
63
            components::enumerate_instance_counts(
×
64
                [&strm](components::component_type type) -> bool {
65
                    strm << "  " << agas::get_component_type_name(type) << "\n";
66
                    return true;
×
67
                });
68

69
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
70
                "component_instance_counter_creator", strm.str());
×
71

72
            return naming::invalid_gid;
73
        }
74

×
75
        // ask AGAS to resolve the component type
76
        components::component_type type =
×
77
            agas::get_component_id(paths.parameters_);
78

×
79
        if (type == to_int(hpx::components::component_enum_type::invalid))
80
        {
81
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
82
                "component_instance_counter_creator",
83
                "invalid component type as counter parameter: {}",
84
                paths.parameters_);
85
            return naming::invalid_gid;
86
        }
87

×
88
        hpx::function<std::int64_t()> f =
×
89
            hpx::bind_front(&get_instance_count, type);
90
        return create_raw_counter(info, HPX_MOVE(f), ec);
91
    }
92
}    // namespace hpx::performance_counters::detail
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc