• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #853

19 Dec 2022 01:01AM UTC coverage: 86.287% (+0.4%) from 85.912%
#853

push

StellarBot
Merge #6109

6109: Modernize serialization module r=hkaiser a=hkaiser

- flyby separate serialization of Boost types

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

53 of 53 new or added lines in 6 files covered. (100.0%)

173939 of 201582 relevant lines covered (86.29%)

1931657.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.33
/libs/full/performance_counters/src/server/arithmetics_counter.cpp
1
//  Copyright (c) 2007-2021 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/async_base/launch_policy.hpp>
9
#include <hpx/async_distributed/continuation.hpp>
10
#include <hpx/components_base/agas_interface.hpp>
11
#include <hpx/modules/string_util.hpp>
12
#include <hpx/performance_counters/counter_creators.hpp>
13
#include <hpx/performance_counters/counters.hpp>
14
#include <hpx/performance_counters/performance_counter.hpp>
15
#include <hpx/performance_counters/server/arithmetics_counter.hpp>
16
#include <hpx/runtime_components/derived_component_factory.hpp>
17
#include <hpx/runtime_local/runtime_local_fwd.hpp>
18
#include <hpx/timing/high_resolution_clock.hpp>
19

20
#include <cstddef>
21
#include <cstdint>
22
#include <mutex>
23
#include <string>
24
#include <utility>
25
#include <vector>
26

27
///////////////////////////////////////////////////////////////////////////////
28
namespace hpx { namespace performance_counters { namespace server {
29
    ///////////////////////////////////////////////////////////////////////////
30
    namespace detail {
31
        template <typename Operation>
32
        struct init_value;
33

34
        template <>
35
        struct init_value<std::plus<double>>
36
        {
37
            static double call()
×
38
            {
39
                return 0.0;
×
40
            }
41
        };
42

43
        template <>
44
        struct init_value<std::minus<double>>
45
        {
46
            static double call()
×
47
            {
48
                return 0.0;
×
49
            }
50
        };
51

52
        template <>
53
        struct init_value<std::multiplies<double>>
54
        {
55
            static double call()
×
56
            {
57
                return 1.0;
×
58
            }
59
        };
60

61
        template <>
62
        struct init_value<std::divides<double>>
63
        {
64
            static double call()
×
65
            {
66
                return 1.0;
×
67
            }
68
        };
69
    }    // namespace detail
70

71
    ///////////////////////////////////////////////////////////////////////////
72
    template <typename Operation>
73
    arithmetics_counter<Operation>::arithmetics_counter() = default;
74

75
    template <typename Operation>
76
    arithmetics_counter<Operation>::arithmetics_counter(
×
77
        counter_info const& info,
78
        std::vector<std::string> const& base_counter_names)
79
      : base_type_holder(info)
×
80
      , counters_(base_counter_names)
×
81
    {
×
82
        if (info.type_ != counter_type::aggregating)
×
83
        {
84
            HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
×
85
                "arithmetics_counter<Operation>::arithmetics_counter",
86
                "unexpected counter type specified");
87
        }
88

89
        counter_path_elements paths;
×
90
        get_counter_path_elements(info.fullname_, paths);
×
91

92
        if (paths.countername_ == "divide")
×
93
        {
94
            if (counters_.size() < 2)
×
95
            {
96
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
×
97
                    "arithmetics_counter<Operation>::arithmetics_counter",
98
                    "the parameter specification for an arithmetic counter "
99
                    "'/arithmetics/divide' has to expand to more than one "
100
                    "counter name: {}",
101
                    paths.parameters_);
102
            }
103
        }
×
104
    }
×
105

106
    template <typename Operation>
107
    hpx::performance_counters::counter_value
108
    arithmetics_counter<Operation>::get_counter_value(bool /* reset */)
×
109
    {
110
        std::vector<counter_value> base_values =
111
            counters_.get_counter_values(hpx::launch::sync);
×
112

113
        // apply arithmetic operation
114
        double value = detail::init_value<Operation>::call();
×
115
        for (counter_value const& base_value : base_values)
×
116
        {
117
            value = Operation()(value, base_value.get_value<double>());
×
118
        }
119

120
        if (base_values[0].scale_inverse_ &&
×
121
            base_values[0].scaling_ != 1.0)    //-V550
×
122
        {
123
            base_values[0].value_ =
×
124
                static_cast<std::int64_t>(value * base_values[0].scaling_);
×
125
        }
×
126
        else
127
        {
128
            base_values[0].value_ =
×
129
                static_cast<std::int64_t>(value / base_values[0].scaling_);
×
130
        }
131

132
        base_values[0].time_ =
×
133
            static_cast<std::int64_t>(hpx::get_system_uptime());
×
134
        base_values[0].count_ = counters_.get_invocation_count();
×
135

136
        return base_values[0];
×
137
    }
×
138

139
    template <typename Operation>
140
    bool arithmetics_counter<Operation>::start()
×
141
    {
142
        return counters_.start(hpx::launch::sync);
×
143
    }
144

145
    template <typename Operation>
146
    bool arithmetics_counter<Operation>::stop()
×
147
    {
148
        return counters_.stop(hpx::launch::sync);
×
149
    }
150

151
    template <typename Operation>
152
    void arithmetics_counter<Operation>::reset_counter_value()
×
153
    {
154
        counters_.reset(hpx::launch::sync);
×
155
    }
×
156

157
    template <typename Operation>
158
    void arithmetics_counter<Operation>::finalize()
×
159
    {
160
        base_performance_counter::finalize();
×
161
        base_type::finalize();
×
162
    }
×
163

164
    template <typename Operation>
165
    naming::address arithmetics_counter<Operation>::get_current_address() const
×
166
    {
167
        return naming::address(
×
168
            naming::get_gid_from_locality_id(agas::get_locality_id()),
×
169
            components::get_component_type<arithmetics_counter>(),
×
170
            const_cast<arithmetics_counter*>(this));
×
171
    }
172
}}}    // namespace hpx::performance_counters::server
173

174
///////////////////////////////////////////////////////////////////////////////
175
template class HPX_EXPORT
176
    hpx::performance_counters::server::arithmetics_counter<std::plus<double>>;
×
177
template class HPX_EXPORT
178
    hpx::performance_counters::server::arithmetics_counter<std::minus<double>>;
×
179
template class HPX_EXPORT hpx::performance_counters::server::
180
    arithmetics_counter<std::multiplies<double>>;
×
181
template class HPX_EXPORT hpx::performance_counters::server::
182
    arithmetics_counter<std::divides<double>>;
×
183

184
///////////////////////////////////////////////////////////////////////////////
185
// Addition
186
typedef hpx::components::component<
187
    hpx::performance_counters::server::arithmetics_counter<std::plus<double>>>
188
    adding_counter_type;
189

190
HPX_REGISTER_DERIVED_COMPONENT_FACTORY(adding_counter_type, adding_counter,
23,132✔
191
    "base_performance_counter", hpx::components::factory_enabled)
192
HPX_DEFINE_GET_COMPONENT_TYPE(adding_counter_type::wrapped_type)
1,082✔
193

194
///////////////////////////////////////////////////////////////////////////////
195
// Subtraction
196
typedef hpx::components::component<
197
    hpx::performance_counters::server::arithmetics_counter<std::minus<double>>>
198
    subtracting_counter_type;
199

200
HPX_REGISTER_DERIVED_COMPONENT_FACTORY(subtracting_counter_type,
28,927✔
201
    subtracting_counter, "base_performance_counter",
202
    hpx::components::factory_enabled)
203
HPX_DEFINE_GET_COMPONENT_TYPE(subtracting_counter_type::wrapped_type)
1,082✔
204

205
///////////////////////////////////////////////////////////////////////////////
206
// Multiply
207
typedef hpx::components::component<hpx::performance_counters::server::
208
        arithmetics_counter<std::multiplies<double>>>
209
    multiplying_counter_type;
210

211
HPX_REGISTER_DERIVED_COMPONENT_FACTORY(multiplying_counter_type,
28,927✔
212
    multiplying_counter, "base_performance_counter",
213
    hpx::components::factory_enabled)
214
HPX_DEFINE_GET_COMPONENT_TYPE(multiplying_counter_type::wrapped_type)
1,082✔
215

216
///////////////////////////////////////////////////////////////////////////////
217
// Division
218
typedef hpx::components::component<hpx::performance_counters::server::
219
        arithmetics_counter<std::divides<double>>>
220
    dividing_counter_type;
221

222
HPX_REGISTER_DERIVED_COMPONENT_FACTORY(dividing_counter_type, dividing_counter,
25,450✔
223
    "base_performance_counter", hpx::components::factory_enabled)
224
HPX_DEFINE_GET_COMPONENT_TYPE(dividing_counter_type::wrapped_type)
1,082✔
225

226
///////////////////////////////////////////////////////////////////////////////
227
namespace hpx { namespace performance_counters { namespace detail {
228
    /// Creation function for aggregating performance counters to be registered
229
    /// with the counter types.
230
    naming::gid_type arithmetics_counter_creator(
×
231
        counter_info const& info, error_code& ec)
232
    {
233
        switch (info.type_)
×
234
        {
235
        case counter_type::aggregating:
236
        {
237
            counter_path_elements paths;
×
238
            get_counter_path_elements(info.fullname_, paths, ec);
×
239
            if (ec)
×
240
                return naming::invalid_gid;
×
241

242
            if (!paths.parameters_.empty())
×
243
            {
244
                // try to interpret the additional parameter as a list of
245
                // two performance counter names
246
                std::vector<std::string> names;
×
247
                hpx::string_util::split(
×
248
                    names, paths.parameters_, hpx::string_util::is_any_of(","));
×
249

250
                if (names.empty())
×
251
                {
252
                    HPX_THROWS_IF(ec, hpx::error::bad_parameter,
×
253
                        "arithmetics_counter_creator",
254
                        "the parameter specification for an arithmetic counter "
255
                        "has to expand to at least one counter name: {}",
256
                        paths.parameters_);
257
                    return naming::invalid_gid;
×
258
                }
259

260
                for (std::string const& name : names)
×
261
                {
262
                    counter_path_elements paths;
×
263
                    if (counter_status::valid_data !=
×
264
                            get_counter_path_elements(name, paths, ec) ||
×
265
                        ec)
×
266
                    {
267
                        HPX_THROWS_IF(ec, hpx::error::bad_parameter,
×
268
                            "arithmetics_counter_creator",
269
                            "the given (expanded) counter name is not "
270
                            "a validly formed performance counter name: {}",
271
                            name);
272
                        return naming::invalid_gid;
×
273
                    }
274
                }
×
275

276
                return create_arithmetics_counter(info, names, ec);
×
277
            }
×
278
            else
279
            {
280
                HPX_THROWS_IF(ec, hpx::error::bad_parameter,
×
281
                    "arithmetics_counter_creator",
282
                    "the parameter specification for an arithmetic counter "
283
                    "has to be a comma separated list of performance "
284
                    "counter names, none is given: {}",
285
                    remove_counter_prefix(info.fullname_));
286
            }
287
        }
×
288
        break;
×
289

290
        default:
291
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
×
292
                "arithmetics_counter_creator",
293
                "invalid counter type requested");
294
            break;
×
295
        }
296
        return naming::invalid_gid;
×
297
    }
×
298
}}}    // namespace hpx::performance_counters::detail
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