]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/stopwatches/include/boost/chrono/stopwatches/formatters/accumulator_set_formatter.hpp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / libs / chrono / stopwatches / include / boost / chrono / stopwatches / formatters / accumulator_set_formatter.hpp
1 // boost/chrono/stopwatches/formatters/ accumulator_set_formatter.hpp ------------------------------------------------------------//
2 // Copyright 2011 Vicente J. Botet Escriba
3 // Distributed under the Boost Software License, Version 1.0.
4 // See http://www.boost.org/LICENSE_1_0.txt
5 // See http://www.boost.org/libs/chrono/stopwatches for documentation.
6
7 #ifndef BOOST_CHRONO_STOPWATCHES_FORMATTERS_ACCUMULATOR_SET_HPP
8 #define BOOST_CHRONO_STOPWATCHES_FORMATTERS_ACCUMULATOR_SET_HPP
9
10 #include <boost/chrono/stopwatches/formatters/base_formatter.hpp>
11 #include <boost/chrono/chrono_io.hpp>
12 #include <boost/current_function.hpp>
13 #include <boost/accumulators/framework/accumulator_set.hpp>
14 #include <boost/accumulators/statistics/count.hpp>
15 #include <boost/accumulators/statistics/sum.hpp>
16 #include <boost/accumulators/statistics/min.hpp>
17 #include <boost/accumulators/statistics/max.hpp>
18 #include <boost/accumulators/statistics/mean.hpp>
19 #include <boost/accumulators/accumulators.hpp>
20 #include <boost/format.hpp>
21 #include <boost/format/group.hpp>
22 #include <boost/cstdint.hpp>
23 #include <boost/assert.hpp>
24 #include <string>
25 #include <iostream>
26 #include <cassert>
27 #include <iomanip>
28
29 #define BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT "count=%1%, sum=%2%, min=%3%, max=%4%, mean=%5%\n"
30
31 namespace boost
32 {
33 namespace chrono
34 {
35
36 template<typename Ratio = milli, typename CharT = char,
37 typename Traits = std::char_traits<CharT>,
38 class Alloc = std::allocator<CharT> >
39 class basic_accumulator_set_formatter: public base_formatter<CharT, Traits> , public basic_format<
40 CharT, Traits>
41 {
42
43 public:
44 typedef base_formatter<CharT, Traits> base_type;
45 typedef basic_format<CharT, Traits> format_type;
46 typedef std::basic_string<CharT, Traits, Alloc> string_type;
47 typedef CharT char_type;
48 typedef std::basic_ostream<CharT, Traits> ostream_type;
49
50 basic_accumulator_set_formatter() :
51 base_type(),
52 format_type(BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT)
53 {
54 }
55 basic_accumulator_set_formatter(ostream_type& os) :
56 base_type(os),
57 format_type(BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT)
58 {
59 }
60 basic_accumulator_set_formatter(const char* fmt, ostream_type& os =
61 std::cout) :
62 base_type(os), format_type(fmt)
63 {
64 }
65 basic_accumulator_set_formatter(string_type const& fmt, ostream_type& os =
66 std::cout) :
67 base_type(os), format_type(fmt)
68 {
69 }
70
71 // static string_type format(const char* s)
72 // {
73 // string_type res(s);
74 // res += boost::chrono::detail::adaptive_string(" : ");
75 // res += BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT;
76 // return res;
77 // }
78
79 template<class Stopwatch>
80 void operator()(Stopwatch & stopwatch_
81 //, system::error_code & ec = BOOST_CHRONO_THROWS
82 )
83 {
84
85 typedef typename Stopwatch::laps_collector::storage_type
86 laps_collector_acc;
87 laps_collector_acc const& acc =
88 stopwatch_.get_laps_collector().accumulator_set();
89
90 typedef typename Stopwatch::duration duration_t;
91
92 duration_style_io_saver dsios(this->os_);
93 this->os_
94 << static_cast<format_type&> (*this)
95 % boost::accumulators::count(acc)
96 % io::group(std::fixed, std::setprecision(this->precision_), duration_fmt(this->duration_style_), (boost::accumulators::count(acc)
97 == 0) ? boost::chrono::duration<double, Ratio>(duration_t::zero()) : boost::chrono::duration<
98 double, Ratio>(duration_t(boost::accumulators::sum(acc))))
99 % io::group(std::fixed, std::setprecision(this->precision_), duration_fmt(this->duration_style_), (boost::accumulators::count(acc)
100 == 0) ? boost::chrono::duration<double, Ratio>(duration_t::zero()) : boost::chrono::duration<
101 double, Ratio>(duration_t((boost::accumulators::min)(acc))))
102 % io::group(std::fixed, std::setprecision(this->precision_), duration_fmt(this->duration_style_), (boost::accumulators::count(acc)
103 == 0) ? boost::chrono::duration<double, Ratio>(duration_t::zero()) : boost::chrono::duration<
104 double, Ratio>(duration_t((boost::accumulators::max)(acc))))
105 % io::group(std::fixed, std::setprecision(this->precision_), duration_fmt(this->duration_style_), ((boost::accumulators::count(acc)
106 > 0) ? boost::chrono::duration<double, Ratio>(duration_t(boost::accumulators::sum(acc)
107 / boost::accumulators::count(acc))) : boost::chrono::duration<
108 double, Ratio>(duration_t::zero())));
109
110 }
111 };
112
113 typedef basic_accumulator_set_formatter<milli, char>
114 accumulator_set_formatter;
115 typedef basic_accumulator_set_formatter<milli, wchar_t>
116 waccumulator_set_formatter;
117
118 } // namespace chrono
119 } // namespace boost
120
121 #if 0
122 #define BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT(F) \
123 boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT)
124 #ifdef __GNUC__
125 #define BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FUNCTION_FORMAT \
126 boost::chrono::elapsed_formatter::format(BOOST_CURRENT_FUNCTION)
127 #else
128 #define BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FUNCTION_FORMAT \
129 BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT(BOOST_CURRENT_FUNCTION)
130 #endif
131 #endif
132
133 #endif