• 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/simplest_performance_counter.cpp
1
//  Copyright (c) 2007-2012 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
// The purpose of this example is to demonstrate the simplest way to create and
8
// use a performance counter for HPX.
9

10
#include <hpx/config.hpp>
11
#if !defined(HPX_COMPUTE_DEVICE_CODE)
12
#include <hpx/hpx_init.hpp>
13
#include <hpx/include/performance_counters.hpp>
14

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

18
///////////////////////////////////////////////////////////////////////////////
19
// The atomic variable 'counter' ensures the thread safety of the counter.
20
std::atomic<std::int64_t> counter(0);
21

22
std::int64_t some_performance_data(bool reset)
×
23
{
24
    ++counter;
25
    return hpx::util::get_and_reset_value(counter, reset);
×
26
}
27

28
void register_counter_type()
×
29
{
30
    // Call the HPX API function to register the counter type.
31
    hpx::performance_counters::install_counter_type(
×
32
        // counter type name
33
        "/test/data",
34
        // function providing counter data
35
        &some_performance_data,
×
36
        // description text
37
        "returns a linearly increasing counter value",
38
        // unit of measure
39
        "",
40
        // counter type
41
        hpx::performance_counters::counter_type::monotonically_increasing);
42
}
×
43

44
///////////////////////////////////////////////////////////////////////////////
45
int hpx_main()
×
46
{
47
    {
48
        // Now it is possible to instantiate a new counter instance based on
49
        // the naming scheme "/test{locality#0/total}/data". Try invoking this
50
        // example using the command line option:
51
        //
52
        //    --hpx:print-counter=/test{locality#0/total}/data
53
        //
54
        // This will print something like:
55
        //
56
        //    test{locality#0/total}/data,1,1.005240[s],1
57
        //
58
        // where the first value is a sequence counter of the invocation of the
59
        // counter. The next is the timestamp marking the point in time since
60
        // application startup at which this counter has been queried. The last
61
        // value printed is the counter value retrieved at the listed point in
62
        // time.
63

64
        // By invoking this example with the command line options:
65
        //
66
        //    --hpx:print-counter=/test{locality#0/total}/data
67
        //    --hpx:print-counter-interval=100
68
        //
69
        // the counter will be queried periodically and the output will look
70
        // like:
71
        //
72
        //    test{locality#0/total}/data,1,0.001937[s],1
73
        //    test{locality#0/total}/data,2,0.109625[s],2
74
        //    test{locality#0/total}/data,3,0.217192[s],3
75
        //    test{locality#0/total}/data,4,0.323497[s],4
76
        //    test{locality#0/total}/data,5,0.430867[s],5
77
        //    test{locality#0/total}/data,6,0.536965[s],6
78
        //    test{locality#0/total}/data,7,0.643422[s],7
79
        //    test{locality#0/total}/data,8,0.750788[s],8
80
        //    test{locality#0/total}/data,9,0.857031[s],9
81
        //    test{locality#0/total}/data,10,0.963330[s],10
82
        //    test{locality#0/total}/data,11,1.015063[s],11
83
        //
84
        // which shows that the counter has been queried roughly every 100
85
        // milliseconds, as specified. Additionally it will be queried during
86
        // application shutdown, as before.
87

88
        hpx::this_thread::suspend(1000);    // wait for one second
×
89
    }
90
    return hpx::finalize();
×
91
}
92

93
int main(int argc, char* argv[])
×
94
{
95
    // By registering the counter type we make it available to any consumer
96
    // creating and querying an instance of the type "/test/data".
97
    //
98
    // This registration should be performed during startup. We register the
99
    // function 'register_counter_type' to be executed as an HPX thread right
100
    // before hpx_main will be executed.
101
    hpx::register_startup_function(&register_counter_type);
×
102

103
    // Initialize and run HPX.
104
    return hpx::init(argc, argv);
×
105
}
106
#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

© 2025 Coveralls, Inc