Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64933 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-08-20 02:53:59


Author: viboes
Date: 2010-08-20 02:53:51 EDT (Fri, 20 Aug 2010)
New Revision: 64933
URL: http://svn.boost.org/trac/boost/changeset/64933

Log:
Towards making process_cpu_clock::times an arithmetic type so process_cpu_clock can be a Clcok
Text files modified:
   sandbox/chrono/boost/chrono/process_cpu_clocks.hpp | 36 +++++++++++++++++++-----------------
   sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp | 18 ++++++++++--------
   2 files changed, 29 insertions(+), 25 deletions(-)

Modified: sandbox/chrono/boost/chrono/process_cpu_clocks.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/process_cpu_clocks.hpp (original)
+++ sandbox/chrono/boost/chrono/process_cpu_clocks.hpp 2010-08-20 02:53:51 EDT (Fri, 20 Aug 2010)
@@ -51,17 +51,14 @@
         static time_point now( system::error_code & ec = system::throws );
     };
 
- class BOOST_CHRONO_DECL process_cpu_clock
- {
- public:
- struct times : arithmetic<times, multiplicative<times, process_real_cpu_clock::rep, less_than_comparable<times> > >
+ struct process_cpu_clock_times : arithmetic<process_cpu_clock_times, multiplicative<process_cpu_clock_times, process_real_cpu_clock::rep, less_than_comparable<process_cpu_clock_times> > >
         {
             typedef process_real_cpu_clock::rep rep;
- times()
+ process_cpu_clock_times()
                 : real(0)
                 , user(0)
                 , system(0){}
- times(
+ process_cpu_clock_times(
                 process_real_cpu_clock::rep r,
                 process_user_cpu_clock::rep u,
                 process_system_cpu_clock::rep s)
@@ -73,49 +70,49 @@
             process_user_cpu_clock::rep user; // user cpu time
             process_system_cpu_clock::rep system; // system cpu time
 
- bool operator==(times const& rhs) {
+ bool operator==(process_cpu_clock_times const& rhs) {
                 return (real==rhs.real &&
                         user==rhs.user &&
                         system==rhs.system);
             }
 
- times operator+=(times const& rhs) {
+ process_cpu_clock_times operator+=(process_cpu_clock_times const& rhs) {
                 real+=rhs.real;
                 user+=rhs.user;
                 system+=rhs.system;
                 return *this;
             }
- times operator-=(times const& rhs) {
+ process_cpu_clock_times operator-=(process_cpu_clock_times const& rhs) {
                 real-=rhs.real;
                 user-=rhs.user;
                 system-=rhs.system;
                 return *this;
             }
- times operator*=(times const& rhs) {
+ process_cpu_clock_times operator*=(process_cpu_clock_times const& rhs) {
                 real*=rhs.real;
                 user*=rhs.user;
                 system*=rhs.system;
                 return *this;
             }
- times operator*=(rep const& rhs) {
+ process_cpu_clock_times operator*=(rep const& rhs) {
                 real*=rhs;
                 user*=rhs;
                 system*=rhs;
                 return *this;
             }
- times operator/=(times const& rhs) {
+ process_cpu_clock_times operator/=(process_cpu_clock_times const& rhs) {
                 real/=rhs.real;
                 user/=rhs.user;
                 system/=rhs.system;
                 return *this;
             }
- times operator/=(rep const& rhs) {
+ process_cpu_clock_times operator/=(rep const& rhs) {
                 real/=rhs;
                 user/=rhs;
                 system/=rhs;
                 return *this;
             }
- bool operator<(times const & rhs) const {
+ bool operator<(process_cpu_clock_times const & rhs) const {
                 if (real < rhs.real) return true;
                 if (real > rhs.real) return false;
                 if (user < rhs.user) return true;
@@ -129,7 +126,12 @@
                 os << "{"<< real <<","<< user <<","<< system << "}";
             };
         };
+
+ class BOOST_CHRONO_DECL process_cpu_clock
+ {
+ public:
 
+ typedef process_cpu_clock_times times;
         typedef boost::chrono::duration<times, nano> duration;
         typedef duration::rep rep;
         typedef duration::period period;
@@ -140,15 +142,15 @@
     };
 
     template <typename OSTREAM>
- OSTREAM& operator<<(OSTREAM& os, process_cpu_clock::times const& rhs) {
+ OSTREAM& operator<<(OSTREAM& os, process_cpu_clock_times const& rhs) {
         rhs.print(os);
         return os;
     }
     
     template <>
- struct duration_values<process_cpu_clock::times>
+ struct duration_values<process_cpu_clock_times>
     {
- typedef process_cpu_clock::times Rep;
+ typedef process_cpu_clock_times Rep;
     public:
         static Rep zero() {return Rep();}
         static Rep max BOOST_PREVENT_MACRO_SUBSTITUTION () {

Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp 2010-08-20 02:53:51 EDT (Fri, 20 Aug 2010)
@@ -32,7 +32,8 @@
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
-#define BOOST_CHRONO_ACCUMULATOR_TIME_FORMAT_DEFAULT "%c times, sum=%ss, min=%ms, max=%Ms, mean=%as, frequency=%fHz, lifetime=%ls, percentage=%p%\n"
+//~ #define BOOST_CHRONO_ACCUMULATOR_TIME_FORMAT_DEFAULT "%c times, sum=%s, min=%m, max=%M, mean=%a, frequency=%fHz, lifetime=%ls, percentage=%p%|real %rs, cpu %cs (%p%), user %us, system %ss\n"
+#define BOOST_CHRONO_ACCUMULATOR_TIME_FORMAT_DEFAULT "%c times, sum %s, min %m, max %M, mean=%a, frequency=%fHz, lifetime=%ls, percentage=%p%\n"
 
 
 namespace boost { namespace chrono {
@@ -82,10 +83,10 @@
             boost::io::ios_precision_saver ips( os );
             os.precision( places );
 
- const char_type* format2;
- for (format2=format ; *format2; ++format2 ) {
- if (*format2=='|') {++format2; break;}
- }
+ const char_type* format2=BOOST_CHRONO_TIME_FORMAT_DEFAULT;
+ //~ for (format2=format ; *format2; ++format2 ) {
+ //~ if (*format2=='|') {++format2; break;}
+ //~ }
 
             for ( ; *format; ++format ) {
                 if ( (*format != '%') || (!*(format+1)) || (!std::strchr("acflmMps", *(format+1))) ) {
@@ -112,7 +113,7 @@
                         if (accumulators::count(acc)>0)
                          //? os << boost::chrono::duration<double>(duration_t(typename duration_t::rep(accumulators::mean(acc)))).count()
                                 //~ os << boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count() / accumulators::count(acc)
- os << accumulators::sum(acc) / accumulators::count(acc);
+ time_formatter::show_time<process_cpu_clock>(accumulators::sum(acc) / accumulators::count(acc), format2, places, os, ec);
                         else
                             os << 0;
                         break;
@@ -151,7 +152,8 @@
 #ifndef BOOST_NO_STD_WSTRING
     template <>
     struct basic_stopwatch_accumulator_time_formatter_default_format<wchar_t> {
- static const wchar_t* apply() {return L"%c times, sum=%ss, min=%ms, max=%Ms, mean=%as, frequency=%fHz, lifetime=%ls, percentage=%p%\n"; }
+ //~ static const wchar_t* apply() {return L"%c times, sum=%ss, min=%ms, max=%Ms, mean=%as, frequency=%fHz, lifetime=%ls, percentage=%p%|real %rs, cpu %cs (%p%), user %us, system %ss\n"; }
+ static const wchar_t* apply() {return L"%c times, sum %s, min %m, max %M, mean %a, frequency=%fHz, lifetime=%ls, percentage=%p%\n"; }
     };
 
 #endif
@@ -176,7 +178,7 @@
 } // namespace chrono
 } // namespace boost
 
-#define BOOST_CHRONO_ACCUMULATOR_TIME_FORMAT(F) boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_ACCUMULATOR_FORMAT_DEFAULT)
+#define BOOST_CHRONO_ACCUMULATOR_TIME_FORMAT(F) boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_ACCUMULATOR_TIME_FORMAT_DEFAULT)
 #ifdef __GNUC__
 #define BOOST_CHRONO_ACCUMULATOR_TIME_FUNCTION_FORMAT boost::chrono::stopwatch_accumulator_time_formatter::format(BOOST_CURRENT_FUNCTION)
 #else


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk