• 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

2.63
/libs/full/performance_counters/src/server/elapsed_time_counter.cpp
1
//  Copyright (c) 2007-2025 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_distributed/continuation.hpp>
9
#include <hpx/modules/errors.hpp>
10
#include <hpx/modules/runtime_local.hpp>
11
#include <hpx/performance_counters/counter_creators.hpp>
12
#include <hpx/performance_counters/counters.hpp>
13
#include <hpx/performance_counters/server/elapsed_time_counter.hpp>
14
#include <hpx/runtime_components/derived_component_factory.hpp>
15

16
#include <cstdint>
17

18
///////////////////////////////////////////////////////////////////////////////
19
using elapsed_time_counter_type = hpx::components::component<
20
    hpx::performance_counters::server::elapsed_time_counter>;
21

22
HPX_REGISTER_DERIVED_COMPONENT_FACTORY(elapsed_time_counter_type,
23
    elapsed_time_counter, "base_performance_counter",
×
24
    hpx::components::factory_state::enabled)
25
HPX_DEFINE_GET_COMPONENT_TYPE(
26
    hpx::performance_counters::server::elapsed_time_counter)
32✔
27

28
///////////////////////////////////////////////////////////////////////////////
29
namespace hpx::performance_counters::server {
30

31
    elapsed_time_counter::elapsed_time_counter() = default;
32

×
33
    elapsed_time_counter::elapsed_time_counter(counter_info const& info)
34
      : base_type_holder(info)
×
35
    {
×
36
        if (info.type_ != counter_type::elapsed_time)
37
        {
×
38
            HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
39
                "elapsed_time_counter::elapsed_time_counter",
×
40
                "unexpected counter type specified for elapsed_time_counter");
41
        }
42
    }
43

×
44
    hpx::performance_counters::counter_value
45
    elapsed_time_counter::get_counter_value(bool reset)
46
    {
×
47
        if (reset)
48
        {
×
49
            HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
50
                "elapsed_time_counter::get_counter_value",
×
51
                "counter /runtime/uptime does no support reset");
52
        }
53

54
        // gather the current value
55
        std::int64_t const now =
56
            static_cast<std::int64_t>(hpx::get_system_uptime());
×
57
        hpx::performance_counters::counter_value value;
58
        value.value_ = now;
×
59
        value.scaling_ = 1000000000LL;    // coefficient to get seconds
×
60
        value.scale_inverse_ = true;
×
61
        value.status_ = counter_status::new_data;
62
        value.time_ = now;
×
63
        value.count_ = ++invocation_count_;
×
64
        return value;
×
65
    }
66

67
    void elapsed_time_counter::reset_counter_value()
×
68
    {
69
        HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
×
70
            "elapsed_time_counter::reset_counter_value",
71
            "counter /runtime/uptime does no support reset");
72
    }
73

74
    bool elapsed_time_counter::start()
×
75
    {
76
        return false;
×
77
    }
78
    bool elapsed_time_counter::stop()
×
79
    {
80
        return false;
×
81
    }
82

83
    void elapsed_time_counter::finalize()
×
84
    {
85
        base_performance_counter::finalize();
86
        base_type::finalize();
87
    }
×
88

89
    naming::address elapsed_time_counter::get_current_address() const
×
90
    {
91
        return naming::address(
92
            naming::get_gid_from_locality_id(agas::get_locality_id()),
×
93
            components::get_component_type<elapsed_time_counter>(),
94
            const_cast<elapsed_time_counter*>(this));
×
95
    }
96
}    // namespace hpx::performance_counters::server
97

98
///////////////////////////////////////////////////////////////////////////////
99
namespace hpx::performance_counters::detail {
100

101
    /// Creation function for uptime counters.
×
102
    naming::gid_type uptime_counter_creator(
103
        counter_info const& info, error_code& ec)
104
    {
×
105
        if (info.type_ != counter_type::elapsed_time)
106
        {
107
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
108
                "uptime_counter_creator", "invalid counter type requested");
109
            return naming::invalid_gid;
110
        }
×
111

×
112
        // verify the validity of the counter instance name
113
        counter_path_elements paths;
114
        get_counter_path_elements(info.fullname_, paths, ec);
115
        if (ec)
×
116
            return naming::invalid_gid;
117

×
118
        // allowed counter names: /runtime(locality#%d/*)/uptime
119
        if (paths.parentinstance_is_basename_)
120
        {
121
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
122
                "uptime_counter_creator",
123
                "invalid counter instance parent name: {}",
124
                paths.parentinstancename_);
125
            return naming::invalid_gid;
×
126
        }
×
127

128
        // create the counter
129
        return create_counter(info, ec);
×
130
    }
131
}    // 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

© 2025 Coveralls, Inc