• 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/performance_counter.cpp
1
//  Copyright (c) 2007-2023 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/assert.hpp>
9
#include <hpx/async_distributed/continuation.hpp>
10
#include <hpx/async_distributed/post.hpp>
11
#include <hpx/modules/async_distributed.hpp>
12
#include <hpx/modules/errors.hpp>
13

14
#include <hpx/performance_counters/counters.hpp>
15
#include <hpx/performance_counters/performance_counter.hpp>
16

17
#include <string>
18
#include <vector>
19

20
#include <hpx/config/warnings_prefix.hpp>
21

22
///////////////////////////////////////////////////////////////////////////////
23
namespace hpx::performance_counters {
24

×
25
    ///////////////////////////////////////////////////////////////////////////
×
26
    performance_counter::performance_counter(std::string const& name)
27
      : base_type(performance_counters::get_counter_async(name))
×
28
    {
29
    }
×
30

×
31
    performance_counter::performance_counter(
32
        std::string const& name, hpx::id_type const& locality)
33
    {
34
        HPX_ASSERT(naming::is_locality(locality));
35

×
36
        counter_path_elements p;
37
        get_counter_path_elements(name, p);
38

×
39
        std::string full_name;
×
40
        p.parentinstanceindex_ = naming::get_locality_id_from_id(locality);
41
        get_counter_name(p, full_name);
×
42

×
43
        this->base_type::reset(
×
44
            performance_counters::get_counter_async(full_name));
45
    }
46

×
47
    ///////////////////////////////////////////////////////////////////////////
48
    hpx::future<counter_info> performance_counter::get_info() const
49
    {
50
#if !defined(HPX_COMPUTE_DEVICE_CODE)
51
        using action_type =
×
52
            server::base_performance_counter::get_counter_info_action;
53
        return hpx::async<action_type>(get_id());
54
#else
55
        HPX_ASSERT(false);
56
        return hpx::make_ready_future(counter_info{});
57
#endif
×
58
    }
59
    counter_info performance_counter::get_info(
60
        launch::sync_policy, [[maybe_unused]] error_code& ec) const
61
    {
×
62
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
63
        hpx::id_type id = get_id(ec);
64
        if (ec)
65
            return counter_info{};
66
        using action_type =
×
67
            server::base_performance_counter::get_counter_info_action;
68
        return hpx::async(action_type(), HPX_MOVE(id)).get(ec);
69
#else
70
        HPX_ASSERT(false);
71
        return counter_info{};
72
#endif
73
    }
×
74

75
    hpx::future<counter_value> performance_counter::get_counter_value(
76
        [[maybe_unused]] bool reset) const
77
    {
78
#if !defined(HPX_COMPUTE_DEVICE_CODE)
79
        using action_type =
×
80
            server::base_performance_counter::get_counter_value_action;
81
        return hpx::async<action_type>(get_id(), reset);
82
#else
83
        HPX_ASSERT(false);
84
        return hpx::make_ready_future(counter_value{});
85
#endif
×
86
    }
87
    counter_value performance_counter::get_counter_value(launch::sync_policy,
88
        [[maybe_unused]] bool reset, [[maybe_unused]] error_code& ec) const
89
    {
×
90
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
91
        hpx::id_type id = get_id(ec);
92
        if (ec)
93
            return counter_value{};
94
        using action_type =
×
95
            server::base_performance_counter::get_counter_value_action;
96
        return hpx::async(action_type(), HPX_MOVE(id), reset).get(ec);
97
#else
98
        HPX_ASSERT(false);
99
        return counter_value{};
100
#endif
101
    }
×
102

103
    hpx::future<counter_value> performance_counter::get_counter_value() const
×
104
    {
105
        return get_counter_value(false);
×
106
    }
107
    counter_value performance_counter::get_counter_value(
108
        launch::sync_policy l, error_code& ec) const
×
109
    {
110
        return get_counter_value(l, false, ec);
111
    }
112

×
113
    hpx::future<counter_values_array>
114
    performance_counter::get_counter_values_array(
115
        [[maybe_unused]] bool reset) const
116
    {
117
#if !defined(HPX_COMPUTE_DEVICE_CODE)
118
        using action_type =
×
119
            server::base_performance_counter::get_counter_values_array_action;
120
        return hpx::async(action_type(), get_id(), reset);
121
#else
122
        HPX_ASSERT(false);
123
        return hpx::make_ready_future(counter_values_array{});
124
#endif
×
125
    }
126
    counter_values_array performance_counter::get_counter_values_array(
127
        launch::sync_policy, bool reset, error_code& ec) const
128
    {
×
129
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
130
        hpx::id_type id = get_id(ec);
131
        if (ec)
132
            return counter_values_array{};
133
        using action_type =
×
134
            server::base_performance_counter::get_counter_values_array_action;
135
        return hpx::async(action_type(), HPX_MOVE(id), reset).get(ec);
136
#else
137
        HPX_ASSERT(false);
138
        return counter_values_array{};
139
#endif
140
    }
141

×
142
    hpx::future<counter_values_array>
143
    performance_counter::get_counter_values_array() const
×
144
    {
145
        return get_counter_values_array(false);
×
146
    }
147
    counter_values_array performance_counter::get_counter_values_array(
148
        launch::sync_policy l, error_code& ec) const
×
149
    {
150
        return get_counter_values_array(l, false, ec);
151
    }
152

×
153
    ///////////////////////////////////////////////////////////////////////////
154
    hpx::future<bool> performance_counter::start() const
155
    {
156
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
157
        using action_type = server::base_performance_counter::start_action;
158
        return hpx::async<action_type>(get_id());
159
#else
160
        HPX_ASSERT(false);
161
        return hpx::make_ready_future(true);
162
#endif
×
163
    }
164
    bool performance_counter::start(
165
        launch::sync_policy, [[maybe_unused]] error_code& ec) const
166
    {
×
167
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
168
        hpx::id_type id = get_id(ec);
169
        if (ec)
170
            return false;
×
171
        using action_type = server::base_performance_counter::start_action;
172
        return hpx::async(action_type(), HPX_MOVE(id)).get(ec);
173
#else
174
        HPX_ASSERT(false);
175
        return false;
176
#endif
177
    }
×
178

179
    hpx::future<bool> performance_counter::stop() const
180
    {
181
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
182
        using action_type = server::base_performance_counter::stop_action;
183
        return hpx::async<action_type>(get_id());
184
#else
185
        HPX_ASSERT(false);
186
        return hpx::make_ready_future(true);
187
#endif
×
188
    }
189
    bool performance_counter::stop(
190
        launch::sync_policy, [[maybe_unused]] error_code& ec) const
191
    {
×
192
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
193
        hpx::id_type id = get_id(ec);
194
        if (ec)
195
            return false;
×
196
        using action_type = server::base_performance_counter::stop_action;
197
        return hpx::async(action_type(), HPX_MOVE(id)).get(ec);
198
#else
199
        HPX_ASSERT(false);
200
        return false;
201
#endif
202
    }
×
203

204
    hpx::future<void> performance_counter::reset() const
205
    {
206
#if !defined(HPX_COMPUTE_DEVICE_CODE)
207
        using action_type =
×
208
            server::base_performance_counter::reset_counter_value_action;
209
        return hpx::async<action_type>(get_id());
210
#else
211
        HPX_ASSERT(false);
212
        return hpx::make_ready_future();
213
#endif
×
214
    }
215
    void performance_counter::reset(
216
        launch::sync_policy, [[maybe_unused]] error_code& ec) const
217
    {
×
218
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
219
        hpx::id_type id = get_id(ec);
220
        if (ec)
221
            return;
222
        using action_type =
×
223
            server::base_performance_counter::reset_counter_value_action;
224
        hpx::async(action_type(), HPX_MOVE(id)).get(ec);
225
#else
226
        HPX_ASSERT(false);
227
#endif
228
    }
×
229

230
    hpx::future<void> performance_counter::reinit(
231
        [[maybe_unused]] bool reset) const
232
    {
233
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
234
        using action_type = server::base_performance_counter::reinit_action;
235
        return hpx::async<action_type>(get_id(), reset);
236
#else
237
        HPX_ASSERT(false);
238
        return hpx::make_ready_future();
239
#endif
×
240
    }
241
    void performance_counter::reinit(
242
        launch::sync_policy, bool reset, error_code& ec) const
243
    {
×
244
#if !defined(HPX_COMPUTE_DEVICE_CODE)
×
245
        hpx::id_type id = get_id(ec);
246
        if (ec)
247
            return;
×
248
        using action_type = server::base_performance_counter::reinit_action;
249
        hpx::async(action_type(), HPX_MOVE(id), reset).get(ec);
250
#else
251
        HPX_ASSERT(false);
252
#endif
253
    }
254

×
255
    ///////////////////////////////////////////////////////////////////////////
256
    hpx::future<std::string> performance_counter::get_name() const
×
257
    {
×
258
        return hpx::make_future<std::string>(get_info(),
259
            [](counter_info&& info) -> std::string { return info.fullname_; });
260
    }
×
261

262
    std::string performance_counter::get_name(
263
        launch::sync_policy, error_code& ec) const
×
264
    {
265
        return get_name().get(ec);
266
    }
267

268
    ///////////////////////////////////////////////////////////////////////////
×
269
    /// Return all counters matching the given name (with optional wild-cards).
270
    std::vector<performance_counter> discover_counters(
271
        std::string const& name, error_code& ec)
×
272
    {
273
        std::vector<performance_counter> counters;
×
274

×
275
        std::vector<counter_info> infos;
276
        counter_status const status = discover_counter_type(
×
277
            name, infos, discover_counters_mode::full, ec);
278
        if (!status_is_valid(status) || ec)
279
            return counters;
×
280

×
281
        counters.reserve(infos.size());
282
        for (counter_info const& info : infos)
283
        {
284
            try
×
285
            {
×
286
                performance_counter counter(info.fullname_);
287
                counters.push_back(counter);
×
288
            }
289
            catch (hpx::exception const& e)
×
290
            {
×
291
                HPX_RETHROWS_IF(ec, e, "discover_counters");
292
            }
293
        }
294

×
295
        return counters;
296
    }
297
}    // 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