• 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/access_counter_set.cpp
1
//  Copyright (c) 2017 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
#include <hpx/iostream.hpp>
15

16
#include <hpx/modules/program_options.hpp>
17

18
#include <cstddef>
19
#include <iomanip>
20
#include <string>
21
#include <vector>
22

23
int hpx_main(hpx::program_options::variables_map& vm)
×
24
{
25
    // extract the counter name (pattern) from command line
26
    std::string name;
27
    if (vm.count("counter"))
×
28
    {
29
        name = vm["counter"].as<std::string>();
×
30
    }
31
    else
32
    {
33
        name = "/threads{locality#*/worker-thread#*}/count/cumulative";
34
    }
35

36
    // create the performance counter set from the given pattern (name)
37
    {
38
        using namespace hpx::performance_counters;
39
        performance_counter_set set(name);
×
40

41
        // retrieve the counter information for all attached counters
42
        std::vector<counter_info> infos = set.get_counter_infos();
×
43

44
        // retrieve the current counter values
45
        std::vector<double> values = set.get_values<double>(hpx::launch::sync);
×
46

47
        // print the values for all 'raw' (non-histogram) counters
48
        for (std::size_t i = 0, j = 0; i != infos.size(); ++i)
×
49
        {
50
            if (infos[i].type_ != counter_type::raw &&
×
51
                infos[i].type_ != counter_type::monotonically_increasing &&
×
52
                infos[i].type_ != counter_type::aggregating &&
×
53
                infos[i].type_ != counter_type::elapsed_time &&
×
54
                infos[i].type_ != counter_type::average_count &&
×
55
                infos[i].type_ != counter_type::average_timer)
56
            {
57
                continue;
×
58
            }
59

60
            if (infos[i].unit_of_measure_.empty())
×
61
            {
62
                hpx::cout << infos[i].fullname_ << ":" << values[j]
×
63
                          << std::endl;
×
64
            }
65
            else
66
            {
67
                hpx::cout << infos[i].fullname_ << ":" << values[j] << "["
×
68
                          << infos[i].unit_of_measure_ << "]" << std::endl;
×
69
            }
70
            ++j;
×
71
        }
72
    }
×
73

74
    return hpx::finalize();
×
75
}
76

77
int main(int argc, char* argv[])
×
78
{
79
    // Define application-specific command-line options.
80
    hpx::program_options::options_description cmdline(
81
        "usage: access_counter_set [options]");
×
82

83
    cmdline.add_options()("counter", hpx::program_options::value<std::string>(),
×
84
        "name (pattern) representing the of the performance counter(s) to "
85
        "query");
86

87
    hpx::init_params init_args;
×
88
    init_args.desc_cmdline = cmdline;
×
89

90
    // Initialize and run HPX.
91
    return hpx::init(argc, argv, init_args);
×
92
}
×
93

94
#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