• 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

28.07
/components/performance_counters/io/src/io_counters.cpp
1
//  Copyright (c) 2015 Maciej Brodowicz
2
//  Copyright (c) 2007-2012 Hartmut Kaiser
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/config.hpp>
9
#include <hpx/components_base/component_startup_shutdown.hpp>
10
#include <hpx/modules/format.hpp>
11
#include <hpx/modules/functional.hpp>
12
#include <hpx/modules/runtime_configuration.hpp>
13
#include <hpx/modules/runtime_local.hpp>
14
#include <hpx/performance_counters/manage_counter_type.hpp>
15

16
#include <hpx/components/performance_counters/io/io_counters.hpp>
17

18
#include <hpx/modules/errors.hpp>
19
#include <boost/fusion/include/define_struct.hpp>
20
#include <boost/fusion/include/io.hpp>
21
#include <boost/phoenix/core.hpp>
22
#include <boost/phoenix/object.hpp>
23
#include <boost/phoenix/operator.hpp>
24
#include <boost/spirit/include/qi.hpp>
25
#include <boost/spirit/include/qi_uint.hpp>
26

27
#include <unistd.h>
28

29
#include <cstdint>
30
#include <fstream>
31
#include <iterator>
32
#include <string>
33
#if defined(HPX_HAVE_UNISTD_H)
34
#include <unistd.h>
35
#endif
36

37
// type to store parser output
38
BOOST_FUSION_DEFINE_STRUCT((hpx) (performance_counters) (io), proc_io,
×
39
    (std::uint64_t, riss)(std::uint64_t, wiss)(std::uint64_t, rsysc)(
40
        std::uint64_t, wsysc)(std::uint64_t, rstor)(std::uint64_t, wstor)(
41
        std::uint64_t, wcanc))
42

43
///////////////////////////////////////////////////////////////////////////////
44
// Add factory registration functionality, We register the module dynamically
45
// as no executable links against it.
46
HPX_REGISTER_COMPONENT_MODULE_DYNAMIC()
×
47

48
///////////////////////////////////////////////////////////////////////////////
49
namespace hpx { namespace performance_counters { namespace io {
50
    namespace qi = boost::spirit::qi;
51
    namespace ascii = boost::spirit::ascii;
52

53
    // grammar
54
    template <typename I>
55
    struct proc_io_parser : qi::grammar<I, proc_io(), ascii::space_type>
×
56
    {
57
        proc_io_parser()
×
58
          : proc_io_parser::base_type(start)
×
59
        {
60
            using qi::lit;
61

62
            start %= lit("rchar:") >> uint64_t_ >> lit("wchar:") >> uint64_t_ >>
×
63
                lit("syscr:") >> uint64_t_ >> lit("syscw:") >> uint64_t_ >>
×
64
                lit("read_bytes:") >> uint64_t_ >> lit("write_bytes:") >>
×
65
                uint64_t_ >> lit("cancelled_write_bytes:") >> uint64_t_;
×
66
        }
×
67

68
        qi::rule<I, proc_io(), ascii::space_type> start;
69
        qi::uint_parser<std::uint64_t> uint64_t_;
70
    };
71

72
    ///////////////////////////////////////////////////////////////////////////
73
    void parse_proc_io(proc_io& pio)
×
74
    {
75
#if defined(HPX_HAVE_UNISTD_H)
76
        pid_t pid = getpid();
×
77
#else
78
        pid_t pid = 0;
79
#endif
80
        std::string fn = hpx::util::format("/proc/{1}/io", pid);
×
81
        std::ifstream ins(fn);
×
82

83
        if (!ins.is_open())
×
84
            HPX_THROW_EXCEPTION(hpx::error::no_success,
×
85
                "hpx::performance_counters::io::parse_proc_io",
86
                hpx::util::format("failed to open /proc/{1}/io", pid));
87

88
        typedef boost::spirit::basic_istream_iterator<char> iterator;
89
        iterator it(ins), end;
90
        proc_io_parser<iterator> p;
×
91

92
        if (!qi::phrase_parse(it, end, p, ascii::space, pio))
×
93
            HPX_THROW_EXCEPTION(hpx::error::no_success,
×
94
                "hpx::performance_counters::io::parse_proc_io",
95
                hpx::util::format("failed to parse /proc/{1}/io", pid));
96
    }
×
97

98
    std::uint64_t get_pio_riss(bool)
×
99
    {
100
        proc_io pio;
101
        parse_proc_io(pio);
×
102
        return pio.riss;
×
103
    }
104

105
    std::uint64_t get_pio_wiss(bool)
×
106
    {
107
        proc_io pio;
108
        parse_proc_io(pio);
×
109
        return pio.wiss;
×
110
    }
111

112
    std::uint64_t get_pio_rsysc(bool)
×
113
    {
114
        proc_io pio;
115
        parse_proc_io(pio);
×
116
        return pio.rsysc;
×
117
    }
118

119
    std::uint64_t get_pio_wsysc(bool)
×
120
    {
121
        proc_io pio;
122
        parse_proc_io(pio);
×
123
        return pio.wsysc;
×
124
    }
125

126
    std::uint64_t get_pio_rstor(bool)
×
127
    {
128
        proc_io pio;
129
        parse_proc_io(pio);
×
130
        return pio.rstor;
×
131
    }
132

133
    std::uint64_t get_pio_wstor(bool)
×
134
    {
135
        proc_io pio;
136
        parse_proc_io(pio);
×
137
        return pio.wstor;
×
138
    }
139

140
    std::uint64_t get_pio_wcanc(bool)
×
141
    {
142
        proc_io pio;
143
        parse_proc_io(pio);
×
144
        return pio.wcanc;
×
145
    }
146

147
    ///////////////////////////////////////////////////////////////////////////
148
    void register_counter_types()
32✔
149
    {
150
        namespace pc = hpx::performance_counters;
151
        pc::install_counter_type("/runtime/io/read_bytes_issued", &get_pio_riss,
64✔
152
            "number of bytes read by process (aggregate of count "
153
            "arguments passed to read() call or its analogues)",
154
            "bytes", pc::counter_type::monotonically_increasing);
155
        pc::install_counter_type("/runtime/io/write_bytes_issued",
128✔
156
            &get_pio_wiss,
64✔
157
            "number of bytes the process has caused or shall cause to be "
158
            "written (aggregate of count arguments passed to write() call or "
159
            "its analogues)",
160
            "bytes", pc::counter_type::monotonically_increasing);
161
        pc::install_counter_type("/runtime/io/read_syscalls", &get_pio_rsysc,
64✔
162
            "number of system calls that perform I/O reads", "",
163
            pc::counter_type::monotonically_increasing);
164
        pc::install_counter_type("/runtime/io/write_syscalls", &get_pio_wsysc,
64✔
165
            "number of system calls that perform I/O writes", "",
166
            pc::counter_type::monotonically_increasing);
167
        pc::install_counter_type("/runtime/io/read_bytes_transferred",
128✔
168
            &get_pio_rstor,
64✔
169
            "number of bytes retrieved from storage by I/O operations", "bytes",
170
            pc::counter_type::monotonically_increasing);
171
        pc::install_counter_type("/runtime/io/write_bytes_transferred",
128✔
172
            &get_pio_wstor,
64✔
173
            "number of bytes transferred to storage by I/O operations", "bytes",
174
            pc::counter_type::monotonically_increasing);
175
        pc::install_counter_type("/runtime/io/write_bytes_cancelled",
128✔
176
            &get_pio_wcanc,
64✔
177
            "number of bytes accounted by write_bytes_transferred that has not "
178
            "been ultimately stored due to truncation or deletion",
179
            "bytes", pc::counter_type::monotonically_increasing);
180
    }
32✔
181

182
    bool get_startup(
32✔
183
        hpx::startup_function_type& startup_func, bool& pre_startup)
184
    {
185
#if defined(__linux) || defined(linux) || defined(__linux__) ||                \
186
    defined(__gnu_linux__)
187
        startup_func = register_counter_types;
188
        pre_startup = true;
189
        return true;
32✔
190
#else
191
        return false;
192
#endif
193
    }
194
}}}    // namespace hpx::performance_counters::io
195

196
// register component's startup function
197
HPX_REGISTER_STARTUP_MODULE_DYNAMIC(hpx::performance_counters::io::get_startup)
64✔
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