Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59079 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-01-16 12:58:17


Author: viboes
Date: 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
New Revision: 59079
URL: http://svn.boost.org/trac/boost/changeset/59079

Log:
Boost.Chrono: Version 0.3.0,
* Added function_stopclock
* Code cleanup
* Add format function on formatters + macros using the current function
Added:
   sandbox/chrono/boost/chrono/function_stopclock.hpp (contents, props changed)
Removed:
   sandbox/chrono/boost/chrono/TBRprocess_clocks.hpp
   sandbox/chrono/boost/chrono/TBRprocess_stopwatches.hpp
   sandbox/chrono/boost/chrono/TBRprocess_stopwatches_reporter.hpp
Text files modified:
   sandbox/chrono/boost/chrono/digital_time_formatter.hpp | 24 ++++++++++++++++++++----
   sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp | 24 ++++++++++++++++++++----
   sandbox/chrono/boost/chrono/stopwatch_formatter.hpp | 23 ++++++++++++++++++-----
   sandbox/chrono/boost/chrono/stopwatch_reporter.hpp | 20 ++++++++++----------
   sandbox/chrono/boost/chrono/time_formatter.hpp | 25 ++++++++++++++++++++-----
   5 files changed, 88 insertions(+), 28 deletions(-)

Deleted: sandbox/chrono/boost/chrono/TBRprocess_clocks.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/TBRprocess_clocks.hpp 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
+++ (empty file)
@@ -1,61 +0,0 @@
-// boost/chrono/process_clocks.hpp -----------------------------------------------------------//
-
-// Copyright Beman Dawes 1994, 2007, 2008
-// Copyright 2009-2010 Vicente J. Botet Escriba
-
-// Distributed under the Boost Software License, Version 1.0.
-// See http://www.boost.org/LICENSE_1_0.txt
-
-// See http://www.boost.org/libs/system for documentation.
-
-#ifndef BOOST_PROCESS_CLOCKS_HPP
-#define BOOST_PROCESS_CLOCKS_HPP
-
-#include <boost/chrono/chrono.hpp>
-#include <boost/system/error_code.hpp>
-//#include <boost/cstdint.hpp>
-//#include <string>
-//#include <ostream>
-
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
-namespace boost
-{
- namespace chrono
- {
-
- class BOOST_CHRONO_DECL process_clocks
- {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_clocks> time_point;
- static const bool is_monotonic = true;
-
- struct durations
- {
- process_clocks::duration real; // real (i.e wall clock) time
- process_clocks::duration user; // user cpu time
- process_clocks::duration system; // system cpu time
- };
- struct time_points
- {
- process_clocks::time_point real; // real (i.e wall clock) time
- process_clocks::time_point user; // user cpu time
- process_clocks::time_point system; // system cpu time
- };
-
- static void now( durations & times,
- system::error_code & ec = system::throws );
- static void now( time_points & times,
- system::error_code & ec = system::throws );
- };
-
-
- } // namespace chrono
-} // namespace boost
-
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
-
-#endif // BOOST_PROCESS_TIMES_HPP

Deleted: sandbox/chrono/boost/chrono/TBRprocess_stopwatches.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/TBRprocess_stopwatches.hpp 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
+++ (empty file)
@@ -1,67 +0,0 @@
-// boost/chrono/process_stopwatches.hpp -----------------------------------------------------------//
-
-// Copyright Beman Dawes 1994, 2007, 2008
-
-// Distributed under the Boost Software License, Version 1.0.
-// See http://www.boost.org/LICENSE_1_0.txt
-
-// See http://www.boost.org/libs/system for documentation.
-
-#ifndef BOOST_PROCESS_STOPWATCHED_HPP
-#define BOOST_PROCESS_STOPWATCHED_HPP
-
-#include <boost/chrono/chrono.hpp>
-#include <boost/chrono/process_clocks.hpp>
-#include <boost/system/error_code.hpp>
-
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
-namespace boost
-{
- namespace chrono
- {
-
-
- class BOOST_CHRONO_DECL process_stopwatches
- // BOOST_CHRONO_DECL is required to quiet compiler warnings even though
- // process_stopwatches has no dynamically linked members, because process_stopwatches is
- // used as a base class for process_stopwatches_reporter, which does have dynamically linked members.
- {
- public:
-
- typedef process_clocks clock;
- typedef process_clocks::duration duration;
- typedef process_clocks::time_point time_point;
-
- explicit process_stopwatches( system::error_code & ec = system::throws )
- {
- start(ec);
- }
-
- ~process_stopwatches() {} // never throws
-
- void start( system::error_code & ec = system::throws )
- {
- process_clocks::now( m_start, ec );
- }
-
- void elapsed( process_clocks::durations & times, system::error_code & ec = system::throws )
- {
- process_clocks::durations end;
- process_clocks::now( end, ec );
- times.real = end.real - m_start.real;
- times.user = end.user - m_start.user;
- times.system = end.system - m_start.system;
- }
-
- protected:
- process_clocks::durations m_start;
- };
-
-
- } // namespace chrono
-} // namespace boost
-
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
-
-#endif // BOOST_PROCESS_TIMES_HPP

Deleted: sandbox/chrono/boost/chrono/TBRprocess_stopwatches_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/TBRprocess_stopwatches_reporter.hpp 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
+++ (empty file)
@@ -1,98 +0,0 @@
-// boost/chrono/process_stopwatches_reporter.hpp -----------------------------------------------------------//
-
-// Copyright Beman Dawes 1994, 2007, 2008
-
-// Distributed under the Boost Software License, Version 1.0.
-// See http://www.boost.org/LICENSE_1_0.txt
-
-// See http://www.boost.org/libs/system for documentation.
-
-#ifndef BOOST_PROCESS_STOPWATCHED_REPORTER_HPP
-#define BOOST_PROCESS_STOPWATCHED_REPORTER_HPP
-
-#include <boost/chrono/chrono.hpp>
-#include <boost/system/error_code.hpp>
-#include <boost/chrono/process_clocks.hpp>
-#include <boost/chrono/process_stopwatches.hpp>
-#include <boost/cstdint.hpp>
-#include <string>
-#include <ostream>
-
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
-namespace boost
-{
- namespace chrono
- {
-
- class BOOST_CHRONO_DECL process_stopwatches_reporter : public process_stopwatches
- {
- // every function making use of inlined functions of class string are not inlined to avoid DLL issues
- public:
-
- // each constructor form has two overloads to avoid a visible default to
- // std::cout, which in turn would require including <iostream>, with its
- // high associated cost, even when the standard streams are not used.
-
- explicit process_stopwatches_reporter( system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os,
- system::error_code & ec = system::throws );
-
- explicit process_stopwatches_reporter( const std::string & format,
- system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
- system::error_code & ec = system::throws );
-
- explicit process_stopwatches_reporter( const std::string & format, int places,
- system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
- int places, system::error_code & ec = system::throws );
-
- explicit process_stopwatches_reporter( int places,
- system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, int places,
- system::error_code & ec = system::throws );
-
- explicit process_stopwatches_reporter( int places, const std::string & format,
- system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, int places, const std::string & format,
- system::error_code & ec = system::throws );
-
- ~process_stopwatches_reporter() // never throws
- {
- system::error_code ec;
- if ( !reported() ) report( ec );
- }
-
- void start( system::error_code & ec = system::throws )
- {
- m_reported = false;
- process_stopwatches::start( ec );
- }
-
- void report( system::error_code & ec = system::throws );
-
- void test_report( duration real_, duration user_, duration system_ );
-
- bool reported() const { return m_reported; }
-
- static int default_places() { return m_default_places; }
-
- private:
- int m_places;
- std::ostream & m_os;
- std::string m_format;
- bool m_reported;
-
- static std::ostream & m_cout();
- static const int m_default_places = 3;
- };
-
- typedef process_stopwatches_reporter run_timer; // backward comppatibility
-
- } // namespace chrono
-} // namespace boost
-
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
-
-#endif // BOOST_PROCESS_TIMES_HPP

Modified: sandbox/chrono/boost/chrono/digital_time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/digital_time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/digital_time_formatter.hpp 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
@@ -12,6 +12,7 @@
 
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/digital_time.hpp>
+#include <boost/current_function.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
@@ -22,6 +23,7 @@
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
+
 namespace boost { namespace chrono {
 
 //--------------------------------------------------------------------------------------//
@@ -30,9 +32,15 @@
 
     class digital_time_formatter {
     public:
- static std::ostream & m_cout();
+ static std::ostream & default_os();
         static const int m_default_places = 3;
- static const char * default_format;
+ static const char* m_default_format;
+ static const char* default_format() { return m_default_format; }
+ static std::string format(const char* s) {
+ std::string res(s);
+ res += " tokes %d day(s) %h:%m:%s.%n\n";
+ return res;
+ }
         static int default_places() { return m_default_places; }
 
         template <class Stopwatch >
@@ -97,13 +105,21 @@
             }
         }
     };
- const char * digital_time_formatter::default_format ="\n%d days(s) %h:%m:%s.%n\n";
+ const char * digital_time_formatter::m_default_format ="%d day(s) %h:%m:%s.%n\n";
 
- std::ostream & digital_time_formatter::m_cout() { return std::cout; }
+ std::ostream & digital_time_formatter::default_os() { return std::cout; }
 
   } // namespace chrono
 } // namespace boost
 
+#define BOOST_CHRONO_DIGITAL_TIME_FORMAT(F) F " tokes %d day(s) %h:%m:%s.%n\n"
+#ifdef __GNUC__
+#define BOOST_CHRONO_DIGITAL_TIME_FUNCTION_FORMAT boost::chrono::digital_time_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_CHRONO_DIGITAL_TIME_FUNCTION_FORMAT BOOST_CHRONO_DIGITAL_TIME_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
+
 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
 
 #endif // BOOST_CHRONO_DIGITAL_TIME_FORMATTER_HPP

Added: sandbox/chrono/boost/chrono/function_stopclock.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/function_stopclock.hpp 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
@@ -0,0 +1,113 @@
+// boost/chrono/stopclock.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_CHRONO_FUNCTION_STOPCLOCK_HPP
+#define BOOST_CHRONO_FUNCTION_STOPCLOCK_HPP
+
+#include <boost/chrono/stopwatch_reporter.hpp>
+#include <boost/chrono/stopwatch.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/chrono/time_formatter.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace chrono {
+
+//--------------------------------------------------------------------------------------//
+//~ provides a everything a Timer provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+
+ //~ * format : The output format
+ //~ * places(precission): the number of decimal placess used.
+
+//~ The default places is given by default_places and is 3. The default format is "\n%ts\n", where
+
+ //~ * %t : the result of elapsed() when the reporting is done.
+
+//~ The time is given using the suffix "s" following the System International d'Unites Std.
+
+/* void f1()
+ * {
+ * stopclock<> _;
+ * // ...
+ * }
+ */
+//--------------------------------------------------------------------------------------//
+
+ template <class Clock=process_cpu_clock, class Stopwatch=stopwatch<Clock>, class Formatter=typename stopwatch_reporter_default_formatter<Stopwatch>::type>
+ class function_stopclock : public stopwatch_reporter<Stopwatch, Formatter> {
+ typedef stopwatch_reporter<Stopwatch, Formatter> base_type;
+ public:
+ explicit function_stopclock( const std::string& func, system::error_code & ec = system::throws )
+ : base_type(ec), func_(func)
+ { begin(); }
+ function_stopclock( const std::string& func, std::ostream & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec), func_(func)
+ { begin(); }
+
+ function_stopclock( const std::string& func, const std::string & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec), func_(func)
+ { begin(); }
+
+ function_stopclock( const std::string& func, int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec), func_(func)
+ { begin(); }
+
+ function_stopclock( const std::string& func, std::ostream & os, const std::string & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec), func_(func)
+ { begin(); }
+
+ function_stopclock( const std::string& func, const std::string & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec), func_(func)
+ { begin(); }
+
+ function_stopclock( const std::string& func, std::ostream & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec), func_(func)
+ { begin(); }
+
+ function_stopclock( const std::string& func, int places, const std::string & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec), func_(func)
+ { begin(); }
+
+ function_stopclock( const std::string& func, std::ostream & os, const std::string & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec), func_(func)
+ { begin(); }
+
+ function_stopclock( const std::string& func, std::ostream & os, int places, const std::string & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec), func_(func)
+ { begin(); }
+
+ ~function_stopclock() {
+ this->m_os << "}}} " << func_ << " : ";
+ }
+ typedef typename base_type::scoped_run scoped_run;
+ typedef typename base_type::scoped_suspend scoped_suspend;
+ typedef typename base_type::scoped_resume scoped_resume;
+ private:
+ void begin() {
+ this->m_os << "{{{ " << func_ << std::endl;
+ }
+ std::string func_;
+
+ };
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_CHRONO_STOPCLOCK_HPP

Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
@@ -12,6 +12,7 @@
 
 #include <boost/chrono/chrono.hpp>
 #include <boost/system/error_code.hpp>
+#include <boost/current_function.hpp>
 #include <boost/accumulators/accumulators.hpp>
 #include <boost/accumulators/statistics.hpp>
 #include <boost/accumulators/framework/accumulator_set.hpp>
@@ -29,6 +30,7 @@
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
+
 namespace boost { namespace chrono {
 
 //--------------------------------------------------------------------------------------//
@@ -37,9 +39,15 @@
 
     class stopwatch_accumulator_formatter {
     public:
- static std::ostream & m_cout();
+ static std::ostream & default_os();
         static const int m_default_places = 3;
- static const char * default_format;
+ static const char* m_default_format;
+ static const char* default_format() { return m_default_format; }
+ static std::string format(const char* s) {
+ std::string res(s);
+ res += " called %c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n";
+ return res;
+ }
         static int default_places() { return m_default_places; }
 
         template <class Stopwatch >
@@ -93,12 +101,20 @@
             }
         }
     };
- const char * stopwatch_accumulator_formatter::default_format ="\n%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n";
- std::ostream & stopwatch_accumulator_formatter::m_cout() { return std::cout; }
+ const char * stopwatch_accumulator_formatter::m_default_format ="%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n";
+ std::ostream & stopwatch_accumulator_formatter::default_os() { return std::cout; }
 
 } // namespace chrono
 } // namespace boost
 
+#define BOOST_CHRONO_ACCUMULATOR_FORMAT(F) F" called %c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n"
+#ifdef __GNUC__
+#define BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT boost::chrono::stopwatch_accumulator_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT BOOST_CHRONO_ACCUMULATOR_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
+
 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
 
 #endif

Modified: sandbox/chrono/boost/chrono/stopwatch_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_formatter.hpp 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
@@ -11,8 +11,8 @@
 #define BOOST_CHRONO_STOPWATCH_FORMATTER_HPP
 
 #include <boost/chrono/chrono.hpp>
-//#include <boost/chrono/stopwatch.hpp>
 #include <boost/system/error_code.hpp>
+#include <boost/current_function.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
 #include <iostream>
@@ -30,9 +30,15 @@
 
     class stopwatch_formatter {
     public:
- static std::ostream & m_cout();
+ static std::ostream & default_os();
         static const int m_default_places = 3;
- static const char * default_format;
+ static const char * m_default_format;
+ static const char* default_format() { return m_default_format; }
+ static std::string format(const char* s) {
+ std::string res(s);
+ res += " tokes %ds\n";
+ return res;
+ }
         static int default_places() { return m_default_places; }
 
         template <class Stopwatch >
@@ -70,13 +76,20 @@
             }
         }
     };
- const char * stopwatch_formatter::default_format ="\n%ds\n";
+ const char * stopwatch_formatter::m_default_format ="%ds\n";
 
- std::ostream & stopwatch_formatter::m_cout() { return std::cout; }
+ std::ostream & stopwatch_formatter::default_os() { return std::cout; }
 
   } // namespace chrono
 } // namespace boost
 
+#define BOOST_CHRONO_STOPWATCH_FORMAT(F) F " tokes %ds\n"
+#ifdef __GNUC__
+#define BOOST_CHRONO_STOPWATCH_FUNCTION_FORMAT boost::chrono::stopwatch_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_CHRONO_STOPWATCH_FUNCTION_FORMAT BOOST_CHRONO_STOPWATCH_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
 
 #endif

Modified: sandbox/chrono/boost/chrono/stopwatch_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_reporter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_reporter.hpp 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
@@ -83,34 +83,34 @@
     class stopwatch_reporter : public Stopwatch {
     public:
         explicit stopwatch_reporter( system::error_code & ec = system::throws )
- : m_places(Formatter::m_default_places), m_os(Formatter::m_cout()), m_format(Formatter::default_format), m_reported(false) { }
+ : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) { }
         explicit stopwatch_reporter( std::ostream & os,
                     system::error_code & ec = system::throws )
- : m_places(Formatter::m_default_places), m_os(os), m_format(Formatter::default_format), m_reported(false) { }
+ : m_places(Formatter::default_places()), m_os(os), m_format(Formatter::default_format()), m_reported(false) { }
 
         explicit stopwatch_reporter( const std::string & format,
                     system::error_code & ec = system::throws )
- : m_places(Formatter::m_default_places), m_os(Formatter::m_cout()), m_format(format), m_reported(false) {}
+ : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(format), m_reported(false) {}
 
         explicit stopwatch_reporter( int places,
                     system::error_code & ec = system::throws )
- : m_places(places), m_os(Formatter::m_cout()), m_format(Formatter::default_format), m_reported(false) { }
+ : m_places(places), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) { }
 
         stopwatch_reporter( std::ostream & os, const std::string & format,
                     system::error_code & ec = system::throws )
- : m_places(Formatter::m_default_places), m_os(os), m_format(format), m_reported(false) { }
+ : m_places(Formatter::default_places()), m_os(os), m_format(format), m_reported(false) { }
 
         stopwatch_reporter( const std::string & format, int places,
                     system::error_code & ec = system::throws )
- : m_places(places), m_os(Formatter::m_cout()), m_format(format), m_reported(false) { }
+ : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) { }
 
         stopwatch_reporter( std::ostream & os, int places,
                     system::error_code & ec = system::throws )
- : m_places(places), m_os(os), m_format(Formatter::default_format), m_reported(false) { }
+ : m_places(places), m_os(os), m_format(Formatter::default_format()), m_reported(false) { }
 
         stopwatch_reporter( int places, const std::string & format,
                     system::error_code & ec = system::throws )
- : m_places(places), m_os(Formatter::m_cout()), m_format(format), m_reported(false) { }
+ : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) { }
 
         stopwatch_reporter( std::ostream & os, const std::string & format, int places,
                     system::error_code & ec = system::throws )
@@ -137,7 +137,7 @@
         typedef stopwatch_suspender<stopwatch_reporter<Stopwatch> > scoped_suspend;
         typedef stopwatch_resumer<stopwatch_reporter<Stopwatch> > scoped_resume;
 
- private:
+ protected:
         int m_places;
         std::ostream & m_os;
         std::string m_format;
@@ -152,7 +152,7 @@
     template <class Stopwatch, class Formatter>
     void stopwatch_reporter<Stopwatch, Formatter>::report( system::error_code & ec ) {
         m_reported = true;
- if ( m_format.empty() ) m_format = Formatter::default_format;
+ if ( m_format.empty() ) m_format = Formatter::default_format();
 
         //typename Stopwatch::duration d = this->elapsed( ec );
         if ( &ec == &system::throws ) {

Modified: sandbox/chrono/boost/chrono/time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/time_formatter.hpp 2010-01-16 12:58:16 EST (Sat, 16 Jan 2010)
@@ -12,6 +12,7 @@
 
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/current_function.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
@@ -22,6 +23,8 @@
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
+
+
 namespace boost { namespace chrono {
 
 //--------------------------------------------------------------------------------------//
@@ -30,9 +33,15 @@
 
     class time_formatter {
     public:
- static std::ostream & m_cout();
+ static std::ostream & default_os();
         static const int m_default_places = 3;
- static const char * default_format;
+ static const char* m_default_format;
+ static const char* default_format() { return m_default_format; }
+ static std::string format(const char* s) {
+ std::string res(s);
+ res += " spent real %rs, cpu %cs (%p%), user %us, system %ss\n";
+ return res;
+ }
         static int default_places() { return m_default_places; }
 
         template <class Stopwatch >
@@ -99,10 +108,9 @@
           }
 
     };
- const char * time_formatter::default_format = "\nreal %rs, cpu %cs (%p%), user %us, system %ss\n";
+ const char * time_formatter::m_default_format = "real %rs, cpu %cs (%p%), user %us, system %ss\n";
 
-
- std::ostream & time_formatter::m_cout() { return std::cout; }
+ std::ostream & time_formatter::default_os() { return std::cout; }
 
     template <>
     struct stopwatch_reporter_default_formatter<stopwatch<process_cpu_clock> > {
@@ -113,6 +121,13 @@
   } // namespace chrono
 } // namespace boost
 
+#define BOOST_CHRONO_TIME_FORMAT(F) F" spent real %rs, cpu %cs (%p%), user %us, system %ss\n"
+#ifdef __GNUC__
+#define BOOST_CHRONO_TIME_FUNCTION_FORMAT boost::chrono::time_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_CHRONO_TIME_FUNCTION_FORMAT BOOST_CHRONO_TIME_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
 
 #endif // BOOST_CHRONO_TIME_FORMATTER_HPP


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