• 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

30.63
/libs/full/performance_counters/src/symbol_namespace_counters.cpp
1
//  Copyright (c) 2011 Bryce Adelstein-Lelbach
2
//  Copyright (c) 2012-2023 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/symbol_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/performance_counters/agas_namespace_action_code.hpp>
18
#include <hpx/performance_counters/counter_creators.hpp>
19
#include <hpx/performance_counters/counters.hpp>
20
#include <hpx/performance_counters/manage_counter_type.hpp>
21
#include <hpx/performance_counters/server/symbol_namespace_counters.hpp>
22
#include <hpx/performance_counters/symbol_namespace_counters.hpp>
23

24
#include <cstdint>
25
#include <string>
26

27
#include <hpx/config/warnings_prefix.hpp>
28

29
namespace hpx::agas::server {
30

31
    // register all performance counter types exposed by this component
32✔
32
    void symbol_namespace_register_counter_types(error_code& ec)
33
    {
34
        performance_counters::create_counter_func const creator(
35
            hpx::bind_back(&performance_counters::agas_raw_counter_creator,
36
                agas::server::symbol_namespace_service_name));
37

416✔
38
        for (auto const& symbol_namespace_service :
416✔
39
            detail::symbol_namespace_services)
40
        {
41
            // global counters are handled elsewhere
384✔
42
            if (symbol_namespace_service.code_ == symbol_ns_statistics_counter)
43
            {
64✔
44
                continue;
45
            }
46

320✔
47
            std::string name(symbol_namespace_service.name_);
48
            std::string help;
49
            performance_counters::counter_type type;
50
            std::string::size_type const p = name.find_last_of('/');
51
            HPX_ASSERT(p != std::string::npos);
52

320✔
53
            if (symbol_namespace_service.target_ ==
54
                detail::counter_target_count)
55
            {
320✔
56
                help = hpx::util::format("returns the number of invocations "
57
                                         "of the AGAS service '{}'",
480✔
58
                    name.substr(p + 1));
59
                type = performance_counters::counter_type::
60
                    monotonically_increasing;
61
            }
62
            else
63
            {
320✔
64
                help = hpx::util::format("returns the overall execution "
65
                                         "time of the AGAS service '{}'",
480✔
66
                    name.substr(p + 1));
67
                type = performance_counters::counter_type::elapsed_time;
68
            }
69

640✔
70
            performance_counters::install_counter_type(
640✔
71
                agas::performance_counter_basename + name, type, help, creator,
640✔
72
                &performance_counters::locality_counter_discoverer,
320✔
73
                HPX_PERFORMANCE_COUNTER_V1, symbol_namespace_service.uom_, ec);
320✔
74
            if (ec)
75
                return;
76
        }
77
    }
78

32✔
79
    void symbol_namespace_register_global_counter_types(error_code& ec)
80
    {
81
        performance_counters::create_counter_func const creator(
82
            hpx::bind_back(&performance_counters::agas_raw_counter_creator,
83
                agas::server::symbol_namespace_service_name));
84

416✔
85
        for (auto const& symbol_namespace_service :
416✔
86
            detail::symbol_namespace_services)
87
        {
88
            // local counters are handled elsewhere
384✔
89
            if (symbol_namespace_service.code_ != symbol_ns_statistics_counter)
90
            {
320✔
91
                continue;
92
            }
93

94
            std::string help;
95
            performance_counters::counter_type type;
64✔
96
            if (symbol_namespace_service.target_ ==
97
                detail::counter_target_count)
98
            {
99
                help = "returns the overall number of invocations of all "
100
                       "symbol AGAS services";
101
                type = performance_counters::counter_type::
102
                    monotonically_increasing;
103
            }
104
            else
105
            {
106
                help = "returns the overall execution time of all symbol AGAS "
107
                       "services";
108
                type = performance_counters::counter_type::elapsed_time;
109
            }
110

128✔
111
            performance_counters::install_counter_type(
64✔
112
                std::string(agas::performance_counter_basename) +
128✔
113
                    symbol_namespace_service.name_,
114
                type, help, creator,
128✔
115
                &performance_counters::locality_counter_discoverer,
64✔
116
                HPX_PERFORMANCE_COUNTER_V1, symbol_namespace_service.uom_, ec);
64✔
117
            if (ec)
118
            {
119
                return;
120
            }
121
        }
122
    }
123

124
    ///////////////////////////////////////////////////////////////////////////
×
125
    naming::gid_type symbol_namespace_statistics_counter(
126
        symbol_namespace& service, std::string const& name)
127
    {    // statistics_counter implementation
×
128
        LAGAS_(info).format("symbol_namespace::statistics_counter");
129

130
        hpx::error_code ec;
131

132
        performance_counters::counter_path_elements p;
×
133
        performance_counters::get_counter_path_elements(name, p, ec);
×
134
        if (ec)
135
        {
136
            return naming::invalid_gid;
137
        }
138

×
139
        if (p.objectname_ != "agas")
140
        {
×
141
            HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
142
                "symbol_namespace::statistics_counter",
143
                "unknown performance counter (unrelated to AGAS)");
144
        }
145

146
        namespace_action_code code = invalid_request;
147
        detail::counter_target target = detail::counter_target_invalid;
×
148
        for (auto const& symbol_namespace_service :
×
149
            detail::symbol_namespace_services)
150
        {
×
151
            if (p.countername_ == name)
152
            {
×
153
                code = symbol_namespace_service.code_;
×
154
                target = symbol_namespace_service.target_;
×
155
                break;
156
            }
157
        }
158

×
159
        if (code == invalid_request || target == detail::counter_target_invalid)
160
        {
×
161
            HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
162
                "symbol_namespace::statistics_counter",
163
                "unknown performance counter (unrelated to AGAS)");
164
        }
165

166
        using cd = symbol_namespace::counter_data;
167

×
168
        hpx::function<std::int64_t(bool)> get_data_func;
×
169
        if (target == detail::counter_target_count)
170
        {
×
171
            switch (code)
172
            {
×
173
            case symbol_ns_bind:
174
                get_data_func = hpx::bind_front(
×
175
                    &cd::get_bind_count, &service.counter_data_);
×
176
                service.counter_data_.bind_.enabled_ = true;
×
177
                break;
×
178
            case symbol_ns_resolve:
179
                get_data_func = hpx::bind_front(
×
180
                    &cd::get_resolve_count, &service.counter_data_);
×
181
                service.counter_data_.resolve_.enabled_ = true;
×
182
                break;
×
183
            case symbol_ns_unbind:
184
                get_data_func = hpx::bind_front(
×
185
                    &cd::get_unbind_count, &service.counter_data_);
×
186
                service.counter_data_.unbind_.enabled_ = true;
×
187
                break;
×
188
            case symbol_ns_iterate_names:
189
                get_data_func = hpx::bind_front(
×
190
                    &cd::get_iterate_names_count, &service.counter_data_);
×
191
                service.counter_data_.iterate_names_.enabled_ = true;
×
192
                break;
×
193
            case symbol_ns_on_event:
194
                get_data_func = hpx::bind_front(
×
195
                    &cd::get_on_event_count, &service.counter_data_);
×
196
                service.counter_data_.on_event_.enabled_ = true;
×
197
                break;
×
198
            case symbol_ns_statistics_counter:
199
                get_data_func = hpx::bind_front(
×
200
                    &cd::get_overall_count, &service.counter_data_);
×
201
                service.counter_data_.enable_all();
202
                break;
203
            default:
×
204
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
205
                    "symbol_namespace::statistics",
206
                    "bad action code while querying statistics");
207
            }
208
        }
209
        else
210
        {
211
            HPX_ASSERT(detail::counter_target_time == target);
×
212
            switch (code)
213
            {
×
214
            case symbol_ns_bind:
215
                get_data_func =
×
216
                    hpx::bind_front(&cd::get_bind_time, &service.counter_data_);
×
217
                service.counter_data_.bind_.enabled_ = true;
×
218
                break;
×
219
            case symbol_ns_resolve:
220
                get_data_func = hpx::bind_front(
×
221
                    &cd::get_resolve_time, &service.counter_data_);
×
222
                service.counter_data_.resolve_.enabled_ = true;
×
223
                break;
×
224
            case symbol_ns_unbind:
225
                get_data_func = hpx::bind_front(
×
226
                    &cd::get_unbind_time, &service.counter_data_);
×
227
                service.counter_data_.unbind_.enabled_ = true;
×
228
                break;
×
229
            case symbol_ns_iterate_names:
230
                get_data_func = hpx::bind_front(
×
231
                    &cd::get_iterate_names_time, &service.counter_data_);
×
232
                service.counter_data_.iterate_names_.enabled_ = true;
×
233
                break;
×
234
            case symbol_ns_on_event:
235
                get_data_func = hpx::bind_front(
×
236
                    &cd::get_on_event_time, &service.counter_data_);
×
237
                service.counter_data_.on_event_.enabled_ = true;
×
238
                break;
×
239
            case symbol_ns_statistics_counter:
240
                get_data_func = hpx::bind_front(
×
241
                    &cd::get_overall_time, &service.counter_data_);
×
242
                service.counter_data_.enable_all();
243
                break;
244
            default:
×
245
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
246
                    "symbol_namespace::statistics",
247
                    "bad action code while querying statistics");
248
            }
249
        }
250

×
251
        performance_counters::counter_info info;
×
252
        performance_counters::get_counter_type(name, info, ec);
×
253
        if (ec)
254
        {
255
            return naming::invalid_gid;
256
        }
×
257
        performance_counters::complement_counter_info(info, ec);
×
258
        if (ec)
259
        {
260
            return naming::invalid_gid;
261
        }
262
        using performance_counters::detail::create_raw_counter;
×
263
        naming::gid_type gid = create_raw_counter(info, get_data_func, ec);
×
264
        if (ec)
265
        {
266
            return naming::invalid_gid;
267
        }
268
        return naming::detail::strip_credits_from_gid(gid);
×
269
    }
270
}    // namespace hpx::agas::server
271

272
namespace hpx::agas {
273

274
    // register performance counters for symbol_namespace service
32✔
275
    void symbol_namespace_register_counter_types(error_code& ec)
276
    {
32✔
277
        server::symbol_namespace_register_counter_types(ec);
32✔
278
        if (!ec)
279
        {
32✔
280
            server::symbol_namespace_register_global_counter_types(ec);
281
        }
32✔
282
    }
283

284
    // statistics_counter implementation
×
285
    naming::gid_type symbol_namespace_statistics_counter(
286
        std::string const& name)
287
    {
288
        return server::symbol_namespace_statistics_counter(
×
289
            naming::get_agas_client().get_local_symbol_namespace_service(),
×
290
            name);
291
    }
292
}    // namespace hpx::agas
293

192✔
294
HPX_REGISTER_ACTION_ID(hpx::agas::symbol_namespace_statistics_counter_action,
295
    symbol_namespace_statistics_counter_action,
296
    hpx::actions::symbol_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

© 2026 Coveralls, Inc