• 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

62.0
/libs/full/performance_counters/src/manage_counter_type.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//  Copyright (c) 2007-2012 Hartmut Kaiser
3
//  Copyright (c) 2011 Bryce Adelstein-Lelbach
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

10
#include <hpx/config.hpp>
11
#include <hpx/async_distributed/continuation.hpp>
12
#include <hpx/modules/errors.hpp>
13
#include <hpx/modules/functional.hpp>
14
#include <hpx/modules/runtime_local.hpp>
15
#include <hpx/performance_counters/counter_creators.hpp>
16
#include <hpx/performance_counters/counters.hpp>
17
#include <hpx/performance_counters/manage_counter_type.hpp>
18
#include <hpx/version.hpp>
19

20
#include <cstddef>
21
#include <cstdint>
22
#include <memory>
23
#include <string>
24
#include <vector>
25

26
namespace hpx { namespace performance_counters {
27
    struct manage_counter_type
28
    {
29
        manage_counter_type(counter_info const& info)
30
          : status_(counter_status::invalid_data)
31
          , info_(info)
32
        {
4,030✔
33
        }
4,030✔
34

35
        ~manage_counter_type()
36
        {
37
            hpx::error_code ec;
4,030✔
38
            uninstall(ec);
39
        }
40

4,030✔
41
        counter_status install(error_code& ec = throws)
42
        {
×
43
            if (counter_status::invalid_data != status_)
44
            {
×
45
                HPX_THROWS_IF(ec, hpx::error::invalid_status,
46
                    "manage_counter_type::install",
×
47
                    "counter type {} has been already installed.",
48
                    info_.fullname_);
49
                return counter_status::invalid_data;
50
            }
×
51

52
            return status_ = add_counter_type(info_, ec);
53
        }
×
54

55
        counter_status install(create_counter_func const& create_counter,
56
            discover_counters_func const& discover_counters,
4,030✔
57
            error_code& ec = throws)
58
        {
59
            if (counter_status::invalid_data != status_)
60
            {
4,030✔
61
                HPX_THROWS_IF(ec, hpx::error::invalid_status,
62
                    "manage_counter_type::install",
×
63
                    "generic counter type {} has been already installed.",
64
                    info_.fullname_);
65
                return counter_status::invalid_data;
66
            }
×
67

68
            return status_ = add_counter_type(
69
                       info_, create_counter, discover_counters, ec);
8,060✔
70
        }
4,030✔
71

72
        void uninstall(error_code& ec = throws)
73
        {
74
            if (counter_status::invalid_data != status_)
75
                remove_counter_type(info_, ec);    // ignore errors
8,060✔
76
        }
8,060✔
77

78
    private:
79
        counter_status status_;
80
        counter_info info_;
81
    };
82

83
    static void counter_type_shutdown(
84
        std::shared_ptr<manage_counter_type> const& p)
4,030✔
85
    {
86
        error_code ec(throwmode::lightweight);
87
        p->uninstall(ec);
88
    }
89

90
    ///////////////////////////////////////////////////////////////////////////
91
    counter_status install_counter_type(std::string const& name,
92
        counter_type type, std::string const& helptext, std::string const& uom,
×
93
        std::uint32_t version, error_code& ec)
94
    {
95
        counter_info info(type, name, helptext,
96
            version ? version : HPX_PERFORMANCE_COUNTER_V1, uom);
97
        std::shared_ptr<manage_counter_type> p =
×
98
            std::make_shared<manage_counter_type>(info);
99

100
        // Install the counter type.
101
        p->install(ec);
102

×
103
        // Register the shutdown function which will clean up this counter type.
104
        get_runtime().add_shutdown_function(
105
            hpx::bind_front(&counter_type_shutdown, p));
×
106
        return counter_status::valid_data;
×
107
    }
×
108

×
109
    ///////////////////////////////////////////////////////////////////////////
110
    // Install a new generic performance counter type in a way, which will
111
    // uninstall it automatically during shutdown.
112
    counter_status install_counter_type(std::string const& name,
113
        counter_type type, std::string const& helptext,
4,030✔
114
        create_counter_func const& create_counter,
115
        discover_counters_func const& discover_counters, std::uint32_t version,
116
        std::string const& uom, error_code& ec)
117
    {
118
        counter_info info(type, name, helptext,
119
            version ? version : HPX_PERFORMANCE_COUNTER_V1, uom);
120
        std::shared_ptr<manage_counter_type> p =
4,030✔
121
            std::make_shared<manage_counter_type>(info);
122

123
        // Install the counter type.
124
        p->install(create_counter, discover_counters, ec);
125

4,030✔
126
        // Register the shutdown function which will clean up this counter type.
127
        get_runtime().add_shutdown_function(
128
            hpx::bind_front(&counter_type_shutdown, p));
8,060✔
129
        return counter_status::valid_data;
4,030✔
130
    }
4,030✔
131

4,030✔
132
    // Install a new generic performance counter type which uses a function to
133
    // provide the data in a way, which will uninstall it automatically during
134
    // shutdown.
135
    counter_status install_counter_type(std::string const& name,
136
        hpx::function<std::int64_t(bool)> const& counter_value,
320✔
137
        std::string const& helptext, std::string const& uom, counter_type type,
138
        error_code& ec)
139
    {
140
        using hpx::placeholders::_1;
141
        using hpx::placeholders::_2;
142
        return install_counter_type(name, type, helptext,
143
            hpx::bind(&hpx::performance_counters::locality_raw_counter_creator,
320✔
144
                _1, counter_value, _2),
320✔
145
            &hpx::performance_counters::locality_counter_discoverer,
146
            HPX_PERFORMANCE_COUNTER_V1, uom, ec);
320✔
147
    }
320✔
148

149
    counter_status install_counter_type(std::string const& name,
150
        hpx::function<std::vector<std::int64_t>(bool)> const& counter_value,
×
151
        std::string const& helptext, std::string const& uom, error_code& ec)
152
    {
153
        using hpx::placeholders::_1;
154
        using hpx::placeholders::_2;
155
        return install_counter_type(name, counter_type::raw_values, helptext,
156
            hpx::bind(
×
157
                &hpx::performance_counters::locality_raw_values_counter_creator,
×
158
                _1, counter_value, _2),
159
            &hpx::performance_counters::locality_counter_discoverer,
160
            HPX_PERFORMANCE_COUNTER_V1, uom, ec);
×
161
    }
×
162

163
    /// Install several new performance counter types in a way, which will
164
    /// uninstall them automatically during shutdown.
165
    void install_counter_types(generic_counter_type_data const* data,
166
        std::size_t count, error_code& ec)
202✔
167
    {
168
        for (std::size_t i = 0; i < count; ++i)
169
        {
2,076✔
170
            install_counter_type(data[i].name_, data[i].type_,
171
                data[i].helptext_, data[i].create_counter_,
1,874✔
172
                data[i].discover_counters_, data[i].version_,
1,874✔
173
                data[i].unit_of_measure_, ec);
1,874✔
174
            if (ec)
1,874✔
175
                break;
1,874✔
176
        }
177
    }
178
}}    // namespace hpx::performance_counters
202✔
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