• 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

27.2
/libs/full/performance_counters/src/component_namespace_counters.cpp
1
//  Copyright (c) 2011 Bryce Adelstein-Lelbach
2
//  Copyright (c) 2012-2021 Hartmut Kaiser
3
//  Copyright (c) 2016 Thomas Heller
4
//
5
//  SPDX-License-Identifier: BSL-1.0
6
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
7
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8

9
#include <hpx/config.hpp>
10
#include <hpx/agas/addressing_service.hpp>
11
#include <hpx/agas/agas_fwd.hpp>
12
#include <hpx/agas_base/server/component_namespace.hpp>
13
#include <hpx/assert.hpp>
14
#include <hpx/format.hpp>
15
#include <hpx/modules/errors.hpp>
16
#include <hpx/modules/functional.hpp>
17
#include <hpx/naming/credit_handling.hpp>
18
#include <hpx/performance_counters/agas_namespace_action_code.hpp>
19
#include <hpx/performance_counters/component_namespace_counters.hpp>
20
#include <hpx/performance_counters/counter_creators.hpp>
21
#include <hpx/performance_counters/counters.hpp>
22
#include <hpx/performance_counters/manage_counter_type.hpp>
23
#include <hpx/performance_counters/server/component_namespace_counters.hpp>
24

25
#include <cstddef>
26
#include <cstdint>
27
#include <string>
28

29
#include <hpx/config/warnings_prefix.hpp>
30

31
namespace hpx::agas::server {
32

33
    // register all performance counter types exposed by this component
29✔
34
    void component_namespace_register_counter_types(error_code& ec)
35
    {
36
        performance_counters::create_counter_func const creator(
37
            hpx::bind_back(&performance_counters::agas_raw_counter_creator,
38
                agas::server::component_namespace_service_name));
39

493✔
40
        for (auto const& component_namespace_service :
493✔
41
            detail::component_namespace_services)
42
        {
43
            // global counters are handled elsewhere
464✔
44
            if (component_namespace_service.code_ ==
45
                component_ns_statistics_counter)
46
            {
58✔
47
                continue;
48
            }
49

406✔
50
            std::string name(component_namespace_service.name_);
51
            std::string help;
52
            performance_counters::counter_type type;
53
            std::string::size_type const p = name.find_last_of('/');
54
            HPX_ASSERT(p != std::string::npos);
55

406✔
56
            if (component_namespace_service.target_ ==
57
                detail::counter_target_count)
58
            {
348✔
59
                help = hpx::util::format("returns the number of invocations "
60
                                         "of the AGAS service '{}'",
522✔
61
                    name.substr(p + 1));
62
                type = performance_counters::counter_type::
63
                    monotonically_increasing;
64
            }
65
            else
66
            {
464✔
67
                help = hpx::util::format("returns the overall execution "
68
                                         "time of the AGAS service '{}'",
696✔
69
                    name.substr(p + 1));
70
                type = performance_counters::counter_type::elapsed_time;
71
            }
72

812✔
73
            performance_counters::install_counter_type(
812✔
74
                agas::performance_counter_basename + name, type, help, creator,
812✔
75
                &performance_counters::locality0_counter_discoverer,
406✔
76
                HPX_PERFORMANCE_COUNTER_V1, component_namespace_service.uom_,
77
                ec);
406✔
78
            if (ec)
79
            {
80
                return;
81
            }
82
        }
83
    }
84

29✔
85
    void component_namespace_register_global_counter_types(error_code& ec)
86
    {
87
        performance_counters::create_counter_func const creator(
88
            hpx::bind_back(&performance_counters::agas_raw_counter_creator,
89
                agas::server::component_namespace_service_name));
90

493✔
91
        for (auto const& component_namespace_service :
493✔
92
            detail::component_namespace_services)
93
        {
94
            // local counters are handled elsewhere
464✔
95
            if (component_namespace_service.code_ !=
96
                component_ns_statistics_counter)
97
            {
406✔
98
                continue;
99
            }
100

101
            std::string help;
102
            performance_counters::counter_type type;
58✔
103
            if (component_namespace_service.target_ ==
104
                detail::counter_target_count)
105
            {
106
                help = "returns the overall number of invocations of all "
107
                       "component AGAS services";
108
                type = performance_counters::counter_type::
109
                    monotonically_increasing;
110
            }
111
            else
112
            {
113
                help = "returns the overall execution time of all "
114
                       "component AGAS services";
115
                type = performance_counters::counter_type::elapsed_time;
116
            }
117

116✔
118
            performance_counters::install_counter_type(
58✔
119
                std::string(agas::performance_counter_basename) +
116✔
120
                    component_namespace_service.name_,
121
                type, help, creator,
116✔
122
                &performance_counters::locality0_counter_discoverer,
58✔
123
                HPX_PERFORMANCE_COUNTER_V1, component_namespace_service.uom_,
124
                ec);
58✔
125
            if (ec)
126
            {
127
                return;
128
            }
129
        }
130
    }
131

132
    ///////////////////////////////////////////////////////////////////////////
×
133
    naming::gid_type component_namespace_statistics_counter(
134
        component_namespace& service, std::string const& name)
135
    {    // statistics_counter implementation
×
136
        LAGAS_(info).format("component_namespace::statistics_counter");
137

138
        hpx::error_code ec;
139

140
        performance_counters::counter_path_elements p;
×
141
        performance_counters::get_counter_path_elements(name, p, ec);
×
142
        if (ec)
143
        {
144
            return naming::invalid_gid;
145
        }
146

×
147
        if (p.objectname_ != "agas")
148
        {
×
149
            HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
150
                "component_namespace::statistics_counter",
151
                "unknown performance counter (unrelated to AGAS)");
152
        }
153

154
        namespace_action_code code = invalid_request;
155
        detail::counter_target target = detail::counter_target_invalid;
×
156
        for (auto const& component_namespace_service :
×
157
            detail::component_namespace_services)
158
        {
×
159
            if (p.countername_ == component_namespace_service.name_)
160
            {
×
161
                code = component_namespace_service.code_;
×
162
                target = component_namespace_service.target_;
×
163
                break;
164
            }
165
        }
166

×
167
        if (code == invalid_request || target == detail::counter_target_invalid)
168
        {
×
169
            HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
170
                "component_namespace::statistics_counter",
171
                "unknown performance counter (unrelated to AGAS)");
172
        }
173

174
        using cd = component_namespace::counter_data;
175

×
176
        hpx::function<std::int64_t(bool)> get_data_func;
×
177
        if (target == detail::counter_target_count)
178
        {
×
179
            switch (code)
180
            {
×
181
            case component_ns_bind_prefix:
182
                get_data_func = hpx::bind_front(
×
183
                    &cd::get_bind_prefix_count, &service.counter_data_);
×
184
                service.counter_data_.bind_prefix_.enabled_ = true;
×
185
                break;
×
186
            case component_ns_bind_name:
187
                get_data_func = hpx::bind_front(
×
188
                    &cd::get_bind_name_count, &service.counter_data_);
189
                service.counter_data_.bind_name_.enabled_ = true;
×
190
                break;
×
191
            case component_ns_resolve_id:
192
                get_data_func = hpx::bind_front(
×
193
                    &cd::get_resolve_id_count, &service.counter_data_);
×
194
                service.counter_data_.resolve_id_.enabled_ = true;
×
195
                break;
×
196
            case component_ns_unbind_name:
197
                get_data_func = hpx::bind_front(
×
198
                    &cd::get_unbind_name_count, &service.counter_data_);
×
199
                service.counter_data_.unbind_name_.enabled_ = true;
×
200
                break;
×
201
            case component_ns_iterate_types:
202
                get_data_func = hpx::bind_front(
×
203
                    &cd::get_iterate_types_count, &service.counter_data_);
×
204
                service.counter_data_.iterate_types_.enabled_ = true;
×
205
                break;
×
206
            case component_ns_get_component_type_name:
207
                get_data_func = hpx::bind_front(
×
208
                    &cd::get_component_type_name_count, &service.counter_data_);
×
209
                service.counter_data_.get_component_type_name_.enabled_ = true;
×
210
                break;
×
211
            case component_ns_num_localities:
212
                get_data_func = hpx::bind_front(
×
213
                    &cd::get_num_localities_count, &service.counter_data_);
×
214
                service.counter_data_.num_localities_.enabled_ = true;
×
215
                break;
×
216
            case component_ns_statistics_counter:
217
                get_data_func = hpx::bind_front(
×
218
                    &cd::get_overall_count, &service.counter_data_);
×
219
                service.counter_data_.enable_all();
220
                break;
221
            default:
×
222
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
223
                    "component_namespace::statistics",
224
                    "bad action code while querying statistics");
225
            }
226
        }
227
        else
228
        {
229
            HPX_ASSERT(detail::counter_target_time == target);
×
230
            switch (code)
231
            {
×
232
            case component_ns_bind_prefix:
233
                get_data_func = hpx::bind_front(
×
234
                    &cd::get_bind_prefix_time, &service.counter_data_);
×
235
                service.counter_data_.bind_prefix_.enabled_ = true;
×
236
                break;
×
237
            case component_ns_bind_name:
238
                get_data_func = hpx::bind_front(
×
239
                    &cd::get_bind_name_time, &service.counter_data_);
×
240
                service.counter_data_.bind_name_.enabled_ = true;
×
241
                break;
×
242
            case component_ns_resolve_id:
243
                get_data_func = hpx::bind_front(
×
244
                    &cd::get_resolve_id_time, &service.counter_data_);
×
245
                service.counter_data_.resolve_id_.enabled_ = true;
×
246
                break;
×
247
            case component_ns_unbind_name:
248
                get_data_func = hpx::bind_front(
×
249
                    &cd::get_unbind_name_time, &service.counter_data_);
×
250
                service.counter_data_.unbind_name_.enabled_ = true;
×
251
                break;
×
252
            case component_ns_iterate_types:
253
                get_data_func = hpx::bind_front(
×
254
                    &cd::get_iterate_types_time, &service.counter_data_);
×
255
                service.counter_data_.iterate_types_.enabled_ = true;
×
256
                break;
×
257
            case component_ns_get_component_type_name:
258
                get_data_func = hpx::bind_front(
×
259
                    &cd::get_component_type_name_time, &service.counter_data_);
×
260
                service.counter_data_.get_component_type_name_.enabled_ = true;
×
261
                break;
×
262
            case component_ns_num_localities:
263
                get_data_func = hpx::bind_front(
×
264
                    &cd::get_num_localities_time, &service.counter_data_);
×
265
                service.counter_data_.num_localities_.enabled_ = true;
×
266
                break;
×
267
            case component_ns_statistics_counter:
268
                get_data_func = hpx::bind_front(
×
269
                    &cd::get_overall_time, &service.counter_data_);
×
270
                service.counter_data_.enable_all();
271
                break;
272
            default:
×
273
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
274
                    "component_namespace::statistics",
275
                    "bad action code while querying statistics");
276
            }
277
        }
278

×
279
        performance_counters::counter_info info;
×
280
        performance_counters::get_counter_type(name, info, ec);
×
281
        if (ec)
282
        {
283
            return naming::invalid_gid;
284
        }
×
285
        performance_counters::complement_counter_info(info, ec);
×
286
        if (ec)
287
        {
288
            return naming::invalid_gid;
289
        }
290
        using performance_counters::detail::create_raw_counter;
291
        naming::gid_type gid = create_raw_counter(
×
292
            info, hpx::function<std::int64_t(bool)>(get_data_func), ec);
×
293
        if (ec)
294
        {
295
            return naming::invalid_gid;
296
        }
297
        return naming::detail::strip_credits_from_gid(gid);
×
298
    }
299
}    // namespace hpx::agas::server
300

301
namespace hpx::agas {
302

303
    // register performance counters for component_namespace service
29✔
304
    void component_namespace_register_counter_types(error_code& ec)
305
    {
29✔
306
        server::component_namespace_register_counter_types(ec);
29✔
307
        if (!ec)
308
        {
29✔
309
            server::component_namespace_register_global_counter_types(ec);
310
        }
29✔
311
    }
312

313
    // statistics_counter implementation
×
314
    naming::gid_type component_namespace_statistics_counter(
315
        std::string const& name)
316
    {
317
        auto* component_service =
×
318
            naming::get_agas_client().get_local_component_namespace_service();
319
        if (component_service != nullptr)    //-V547
320
        {
321
            return server::component_namespace_statistics_counter(
322
                *component_service, name);
323
        }
324
        return naming::invalid_gid;
325
    }
326
}    // namespace hpx::agas
327

192✔
328
HPX_REGISTER_ACTION_ID(hpx::agas::component_namespace_statistics_counter_action,
329
    component_namespace_statistics_counter_action,
330
    hpx::actions::component_namespace_statistics_counter_action_id)
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