• 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
/examples/performance_counters/sine/server/sine.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
#if !defined(HPX_COMPUTE_DEVICE_CODE)
9
#include <hpx/hpx.hpp>
10
#include <hpx/include/actions.hpp>
11
#include <hpx/include/components.hpp>
12
#include <hpx/include/performance_counters.hpp>
13
#include <hpx/include/util.hpp>
14

15
#include <cstdint>
16
#include <mutex>
17

18
#include "sine.hpp"
19

20
///////////////////////////////////////////////////////////////////////////////
21
typedef hpx::components::component<
22
    ::performance_counters::sine::server::sine_counter>
23
    sine_counter_type;
24

25
HPX_REGISTER_DERIVED_COMPONENT_FACTORY_DYNAMIC(
×
26
    sine_counter_type, sine_counter, "base_performance_counter")
27

28
///////////////////////////////////////////////////////////////////////////////
29
namespace performance_counters { namespace sine { namespace server {
30
    ///////////////////////////////////////////////////////////////////////////
31
    sine_counter::sine_counter(
×
32
        hpx::performance_counters::counter_info const& info)
×
33
      : hpx::performance_counters::base_performance_counter<sine_counter>(info)
34
      , current_value_(0)
×
35
      , evaluated_at_(0)
×
36
      , timer_(hpx::bind(&sine_counter::evaluate, this), 1000000,
×
37
            "sine example performance counter")
×
38
    {
39
    }
×
40

41
    bool sine_counter::start()
×
42
    {
43
        return timer_.start();
×
44
    }
45

46
    bool sine_counter::stop()
×
47
    {
48
        return timer_.stop();
×
49
    }
50

51
    hpx::performance_counters::counter_value sine_counter::get_counter_value(
×
52
        bool reset)
53
    {
54
        std::int64_t const scaling = 100000;
55

56
        hpx::performance_counters::counter_value value;
57

58
        // gather the current value
59
        {
60
            std::lock_guard<mutex_type> mtx(mtx_);
×
61
            value.value_ = std::int64_t(current_value_ * scaling);
×
62
            if (reset)
×
63
                current_value_ = 0;
×
64
            value.time_ = evaluated_at_;
×
65
        }
66

67
        value.scaling_ = scaling;
×
68
        value.scale_inverse_ = true;
×
69
        value.status_ = hpx::performance_counters::counter_status::new_data;
×
70
        value.count_ = ++invocation_count_;
×
71

72
        return value;
×
73
    }
74

75
    void sine_counter::finalize()
×
76
    {
77
        timer_.stop();
78
        hpx::performance_counters::base_performance_counter<
79
            sine_counter>::finalize();
80
    }
×
81

82
    bool sine_counter::evaluate()
×
83
    {
84
        std::lock_guard<mutex_type> mtx(mtx_);
×
85
        evaluated_at_ = static_cast<std::int64_t>(hpx::get_system_uptime());
×
86
        current_value_ = std::sin(static_cast<double>(evaluated_at_) / 1e10);
×
87
        return true;
×
88
    }
89
}}}    // namespace performance_counters::sine::server
90
#endif
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