• 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.35
/libs/full/performance_counters/src/locality_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/locality_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/counter_creators.hpp>
20
#include <hpx/performance_counters/counters.hpp>
21
#include <hpx/performance_counters/locality_namespace_counters.hpp>
22
#include <hpx/performance_counters/manage_counter_type.hpp>
23
#include <hpx/performance_counters/server/locality_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 locality_namespace_register_counter_types(error_code& ec)
35
    {
36
        performance_counters::create_counter_func creator(
37
            hpx::bind_back(&performance_counters::agas_raw_counter_creator,
38
                agas::server::locality_namespace_service_name));
39

377✔
40
        for (std::size_t i = 0; i != detail::num_locality_namespace_services;
41
            ++i)
42
        {
43
            // global counters are handled elsewhere
348✔
44
            if (detail::locality_namespace_services[i].code_ ==
45
                locality_ns_statistics_counter)
46
            {
58✔
47
                continue;
48
            }
49

290✔
50
            std::string name(detail::locality_namespace_services[i].name_);
51
            std::string help;
52
            performance_counters::counter_type type;
53
            std::string::size_type p = name.find_last_of('/');
54
            HPX_ASSERT(p != std::string::npos);
55

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

580✔
73
            performance_counters::install_counter_type(
580✔
74
                agas::performance_counter_basename + name, type, help, creator,
580✔
75
                &performance_counters::locality0_counter_discoverer,
76
                HPX_PERFORMANCE_COUNTER_V1,
290✔
77
                detail::locality_namespace_services[i].uom_, ec);
290✔
78
            if (ec)
79
            {
80
                return;
81
            }
82
        }
83
    }
84

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

377✔
91
        for (std::size_t i = 0; i != detail::num_locality_namespace_services;
92
            ++i)
93
        {
94
            // local counters are handled elsewhere
348✔
95
            if (detail::locality_namespace_services[i].code_ !=
96
                locality_ns_statistics_counter)
97
            {
290✔
98
                continue;
99
            }
100

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

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

134
    ///////////////////////////////////////////////////////////////////////////
×
135
    naming::gid_type locality_namespace_statistics_counter(
136
        locality_namespace& service, std::string const& name)
137
    {    // statistics_counter implementation
×
138
        LAGAS_(info).format("locality_namespace::statistics_counter");
139

140
        hpx::error_code ec;
141

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

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

156
        namespace_action_code code = invalid_request;
157
        detail::counter_target target = detail::counter_target_invalid;
×
158
        for (std::size_t i = 0; i != detail::num_locality_namespace_services;
159
            ++i)
160
        {
×
161
            if (p.countername_ == detail::locality_namespace_services[i].name_)
162
            {
×
163
                code = detail::locality_namespace_services[i].code_;
×
164
                target = detail::locality_namespace_services[i].target_;
×
165
                break;
166
            }
167
        }
168

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

176
        typedef locality_namespace::counter_data cd;
177

×
178
        hpx::function<std::int64_t(bool)> get_data_func;
×
179
        if (target == detail::counter_target_count)
180
        {
×
181
            switch (code)
182
            {
×
183
            case locality_ns_allocate:
184
                get_data_func = hpx::bind_front(
×
185
                    &cd::get_allocate_count, &service.counter_data_);
×
186
                service.counter_data_.allocate_.enabled_ = true;
×
187
                break;
×
188
            case locality_ns_resolve_locality:
189
                get_data_func = hpx::bind_front(
×
190
                    &cd::get_resolve_locality_count, &service.counter_data_);
×
191
                service.counter_data_.resolve_locality_.enabled_ = true;
×
192
                break;
×
193
            case locality_ns_free:
194
                get_data_func = hpx::bind_front(
×
195
                    &cd::get_free_count, &service.counter_data_);
×
196
                service.counter_data_.free_.enabled_ = true;
×
197
                break;
×
198
            case locality_ns_localities:
199
                get_data_func = hpx::bind_front(
×
200
                    &cd::get_localities_count, &service.counter_data_);
×
201
                service.counter_data_.localities_.enabled_ = true;
×
202
                break;
×
203
            case locality_ns_num_localities:
204
                get_data_func = hpx::bind_front(
×
205
                    &cd::get_num_localities_count, &service.counter_data_);
×
206
                service.counter_data_.num_localities_.enabled_ = true;
×
207
                break;
×
208
            case locality_ns_num_threads:
209
                get_data_func = hpx::bind_front(
×
210
                    &cd::get_num_threads_count, &service.counter_data_);
×
211
                service.counter_data_.num_threads_.enabled_ = true;
×
212
                break;
×
213
            case locality_ns_statistics_counter:
214
                get_data_func = hpx::bind_front(
×
215
                    &cd::get_overall_count, &service.counter_data_);
×
216
                service.counter_data_.enable_all();
217
                break;
218
            default:
×
219
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
220
                    "locality_namespace::statistics",
221
                    "bad action code while querying statistics");
222
            }
223
        }
224
        else
225
        {
226
            HPX_ASSERT(detail::counter_target_time == target);
×
227
            switch (code)
228
            {
×
229
            case locality_ns_allocate:
230
                get_data_func = hpx::bind_front(
×
231
                    &cd::get_allocate_time, &service.counter_data_);
×
232
                service.counter_data_.allocate_.enabled_ = true;
×
233
                break;
×
234
            case locality_ns_resolve_locality:
235
                get_data_func = hpx::bind_front(
×
236
                    &cd::get_resolve_locality_time, &service.counter_data_);
×
237
                service.counter_data_.resolve_locality_.enabled_ = true;
×
238
                break;
×
239
            case locality_ns_free:
240
                get_data_func =
×
241
                    hpx::bind_front(&cd::get_free_time, &service.counter_data_);
×
242
                service.counter_data_.free_.enabled_ = true;
×
243
                break;
×
244
            case locality_ns_localities:
245
                get_data_func = hpx::bind_front(
×
246
                    &cd::get_localities_time, &service.counter_data_);
×
247
                service.counter_data_.localities_.enabled_ = true;
×
248
                break;
×
249
            case locality_ns_num_localities:
250
                get_data_func = hpx::bind_front(
×
251
                    &cd::get_num_localities_time, &service.counter_data_);
×
252
                service.counter_data_.num_localities_.enabled_ = true;
×
253
                break;
×
254
            case locality_ns_num_threads:
255
                get_data_func = hpx::bind_front(
×
256
                    &cd::get_num_threads_time, &service.counter_data_);
×
257
                service.counter_data_.num_threads_.enabled_ = true;
×
258
                break;
×
259
            case locality_ns_statistics_counter:
260
                get_data_func = hpx::bind_front(
×
261
                    &cd::get_overall_time, &service.counter_data_);
×
262
                service.counter_data_.enable_all();
263
                break;
264
            default:
×
265
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
266
                    "locality_namespace::statistics",
267
                    "bad action code while querying statistics");
268
            }
269
        }
270

×
271
        performance_counters::counter_info info;
×
272
        performance_counters::get_counter_type(name, info, ec);
×
273
        if (ec)
274
        {
275
            return naming::invalid_gid;
276
        }
×
277
        performance_counters::complement_counter_info(info, ec);
×
278
        if (ec)
279
        {
280
            return naming::invalid_gid;
281
        }
282
        using performance_counters::detail::create_raw_counter;
283
        naming::gid_type gid = create_raw_counter(
×
284
            info, hpx::function<std::int64_t(bool)>(get_data_func), ec);
×
285
        if (ec)
286
        {
287
            return naming::invalid_gid;
288
        }
289
        return naming::detail::strip_credits_from_gid(gid);
×
290
    }
291
}    // namespace hpx::agas::server
292

293
namespace hpx::agas {
294

295
    // register performance counters for locality_namespace service
29✔
296
    void locality_namespace_register_counter_types(error_code& ec)
297
    {
29✔
298
        server::locality_namespace_register_counter_types(ec);
29✔
299
        if (!ec)
300
        {
29✔
301
            server::locality_namespace_register_global_counter_types(ec);
302
        }
29✔
303
    }
304

305
    // statistics_counter implementation
×
306
    naming::gid_type locality_namespace_statistics_counter(
307
        std::string const& name)
308
    {
309
        auto* locality_service =
×
310
            naming::get_agas_client().get_local_locality_namespace_service();
×
311
        if (locality_service != nullptr)
312
        {
313
            return server::locality_namespace_statistics_counter(
×
314
                *locality_service, name);
315
        }
316
        return naming::invalid_gid;
317
    }
318
}    // namespace hpx::agas
319

192✔
320
HPX_REGISTER_ACTION_ID(hpx::agas::locality_namespace_statistics_counter_action,
321
    locality_namespace_statistics_counter_action,
322
    hpx::actions::locality_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