Boost logo

Boost :

Subject: Re: [boost] [chrono] v0.3.1 Support for wide characters
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-01-20 17:52:40


Hi Joel,
----- Original Message -----
From: "joel falcou" <joel.falcou_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, January 20, 2010 11:05 PM
Subject: Re: [boost] [chrono] v0.3.1 Support for wide characters

>
> I kinda missed the last shot of comments but I have a question.
> You speak about:
>> * stopwatch_accumulator, capturing cummulated elapsed Clock times.
> Do they use boost::accumulators and if yes, can we give them special
> stats to compute in addition to
> min,max,mean ?

Yes, it uses boost::accumulators so you can give it the Accumulator you want and of course define the associated formatter. I have not included an example on the documentation, but you can have an idea by looking on how stopwatch_accumulator is done and how the default accumulators is given. Here follow an example not yet compiled:

#include <boost/chrono/stopwatches.hpp>
#include <cmath>

using namespace boost::chrono;
using namespace boost::accumulators;

typedef stopwatch_accumulator<process_real_cpu_clock,
            accumulator_set<process_real_cpu_clock::rep,
                features<
                        tag::count,
                        tag::sum,
                        tag::min,
                        tag::max,
                        tag::mean
>
>,
            my_stopwatch_accumulator_formatter
>::reporter my_stopwatch_accumulator_reporter;

// where my_stopwatch_accumulator_formatter will follow the same schema that stopwatch_accumulator_formatter.hpp

int f1(long j)
{
  static my_stopwatch_accumulator_reporter acc(BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT);
  my_stopwatch_accumulator_reporter::scoped_run _(acc);

  for ( long i = 0; i < j; ++i )
    std::sqrt( 123.456L ); // burn some time

  return 0;
}
int main()
{

  f1(100000);
  f1(200000);
  f1(300000);
  return 0;
}

> Other questions: is there plan for a cycle counter absed watch using the
> various compiler/os specific stuff like rdtsc et al ?

I'm sorry, but I suspect that I'm not competent in this domain. A clock don't require too much things. Thus for some one with a good knowledge of what is "a cycle counter absed watch using the various compiler/os specific stuff like rdtsc et al" it should be quite easy to implement a clock based on this counting. Here follows an extract from the documentation:

A clock represents a bundle consisting of a native duration, a native time_point, and a function now() to get the current time_point. A clock must meet the requirements in the following Table.

In this table C1 and C2 denote clock types. t1 and t2 are values returned from C1::now() where the call returning t1 happens before the call returning t2 and both of these calls happen before C1::time_point::max().

Table 1. Clock Requirements
expression return type operational semantics
C1::rep An arithmetic type or class emulating an arithmetic type. The representation type of the native duration and time_point.
C1::period ratio The tick period of the clock in seconds.
C1::duration chrono::duration<C1::rep, C1::period> The native duration type of the clock.
C1::time_point chrono::time_point<C1> or chrono::time_point<C2, C1::duration> The native time_point type of the clock. Different clocks are permitted to share a time_point definition if it is valid to compare their time_points by comparing their respective durations. C1 and C2 must refer to the same epoch.
C1::is_monotonic const bool true if t1 <= t2 is always true, else false. Note: A clock that can be adjusted backwards is not monotonic
C1::now() C1::time_point Returns a time_point representing the current point in time.

You could find a better formmating on the documentation.

As you can see, you need just to implement a static function returning this counter. The rest is pure formalism.

Hoping this answer your questions.
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk