• 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/action_invocation_counter_discoverer.cpp
1
//  Copyright (c) 2007-2022 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/actions_base/detail/invocation_count_registry.hpp>
9
#include <hpx/modules/errors.hpp>
10
#include <hpx/modules/format.hpp>
11
#include <hpx/modules/util.hpp>
12
#include <hpx/performance_counters/action_invocation_counter_discoverer.hpp>
13
#include <hpx/performance_counters/counters.hpp>
14
#include <hpx/performance_counters/registry.hpp>
15

16
#include <regex>
17
#include <sstream>
18
#include <string>
19
#include <utility>
20

21
namespace hpx { namespace performance_counters {
22

23
    bool action_invocation_counter_discoverer(
×
24
        hpx::actions::detail::invocation_count_registry const& registry,
25
        performance_counters::counter_info const& info,
26
        performance_counters::counter_path_elements& p,
27
        performance_counters::discover_counter_func const& f,
28
        performance_counters::discover_counters_mode mode, error_code& ec)
29
    {
30
        using map_type =
31
            hpx::actions::detail::invocation_count_registry::map_type;
32

33
        map_type const& map = registry.registered_counters();
34

35
        if (mode == performance_counters::discover_counters_mode::minimal ||
×
36
            p.parentinstancename_.empty() || p.instancename_.empty())
×
37
        {
38
            if (p.parentinstancename_.empty())
×
39
            {
40
                p.parentinstancename_ = "locality#*";
×
41
                p.parentinstanceindex_ = -1;
×
42
            }
43

44
            if (p.instancename_.empty())
×
45
            {
46
                p.instancename_ = "total";
×
47
                p.instanceindex_ = -1;
×
48
            }
49
        }
50

51
        if (p.parameters_.empty())
×
52
        {
53
            if (mode == performance_counters::discover_counters_mode::minimal)
×
54
            {
55
                std::string fullname;
56
                performance_counters::get_counter_name(p, fullname, ec);
×
57
                if (ec)
×
58
                    return false;
59

60
                performance_counters::counter_info cinfo = info;
×
61
                cinfo.fullname_ = HPX_MOVE(fullname);
×
62
                return f(cinfo, ec) && !ec;
×
63
            }
×
64

65
#if defined(HPX_GCC_VERSION) && HPX_GCC_VERSION >= 110000
×
66
#pragma GCC diagnostic push
67
#pragma GCC diagnostic ignored "-Wrestrict"
68
#endif
×
69
            p.parameters_ = "*";
70
#if defined(HPX_GCC_VERSION) && HPX_GCC_VERSION >= 110000
×
71
#pragma GCC diagnostic pop
×
72
#endif
73
        }
74

75
        if (p.parameters_.find_first_of("*?[]") != std::string::npos)
×
76
        {
77
            std::string str_rx(util::regex_from_pattern(p.parameters_, ec));
×
78
            if (ec)
79
                return false;
×
80

×
81
            bool found_one = false;
82
            std::regex rx(str_rx);
83

84
            for (auto const& e : map)
85
            {
×
86
                if (!std::regex_match(e.first, rx))
×
87
                    continue;
88
                found_one = true;
×
89

×
90
                // propagate parameters
91
                std::string fullname;
92
                performance_counters::counter_path_elements cp = p;
×
93
                cp.parameters_ = e.first;
×
94

95
                performance_counters::get_counter_name(cp, fullname, ec);
×
96
                if (ec)
97
                    return false;
×
98

99
                performance_counters::counter_info cinfo = info;
×
100
                cinfo.fullname_ = HPX_MOVE(fullname);
101

102
                if (!f(cinfo, ec) || ec)
×
103
                    return false;
×
104
            }
105

106
            if (!found_one)
107
            {
×
108
                // compose a list of known action types
109
                std::ostringstream strm;
×
110
                hpx::util::format_to(strm,
111
                    "action type {} does not match any known type, "
112
                    "known action types: \n",
×
113
                    p.parameters_);
114
                for (auto const& e : map)
115
                {
116
                    strm << "  " << e.first << "\n";
×
117
                }
118

×
119
                HPX_THROWS_IF(ec, hpx::error::bad_parameter,
×
120
                    "invocation_count_registry::counter_discoverer",
121
                    strm.str());
×
122
                return false;
×
123
            }
124

125
            if (&ec != &throws)
126
                ec = make_success_code();
×
127

128
            return true;
129
        }
130

×
131
        // use given action type directly
132
        map_type::const_iterator it = map.find(p.parameters_);
×
133
        if (it == map.end())
134
        {
135
            // compose a list of known action types
×
136
            std::string types;
137
            for (auto const& e : map)
138
            {
139
                types += "  " + e.first + "\n";
140
            }
141

142
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
143
                "invocation_count_registry::counter_discoverer",
144
                "action type {} does not match any known type, known action "
145
                "types: \n{}",
×
146
                p.parameters_, types);
×
147
            return false;
148
        }
149

×
150
        // propagate parameters
×
151
        std::string fullname;
152
        performance_counters::get_counter_name(p, fullname, ec);
×
153
        if (ec)
154
            return false;
155

×
156
        performance_counters::counter_info cinfo = info;
×
157
        cinfo.fullname_ = HPX_MOVE(fullname);
158

159
        if (!f(cinfo, ec) || ec)
×
160
            return false;
161

162
        if (&ec != &throws)
163
            ec = make_success_code();
164

165
        return true;
166
    }
167
}}    // namespace hpx::performance_counters
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