[chrono][stopwatches] Request for interest in NEW stopwatch/timer reporting facilities

Hi, I has been reconsidering the reporting facilities of proposed Boost.Stopwatches. I have started to make some examples that make use Boost.Format to make the reports. Default reporting stopclock<> sw; prints the duration 29308.350 µs You can make a boost::format and pass it to the stopclock. void f1(long j) { boost::format fmt("%1%[%2%] f1(%3%) - Elapsed time: %4%"); fmt % __FILE__ % __LINE__ % j; stopclock< > sw(fmt); // burn some time } ../example/scoped_stopwatch_example.cpp[42] f1(1000000) - Elapsed time: 29834.769 µs ../example/scoped_stopwatch_example.cpp[51] void f2(long int) - Elapsed time: 0.979 µs You can change the precision, the output stream, the units and the unit text using a specific formatter. For example typedef elapsed_formatter<milli > formatter; formatter fmt("Elapsed time: %1%", std::cerr); fmt.set_duration_style(text); fmt.set_precision(6); stopclock<high_resolution_clock, formatter> sw(fmt); could print Elapsed time: 87.829801 milliseconds This formatter could be shared between several stopclocks (thread unsafe however). Even if the reporting facilities will not be completly 'localizable', I think that this interface goes one step towards in this direction. Before continuing the adaptation of the whole library I would like to hear some comments from you. Do you think this is an acceptable interface? What are the parameters that do you want to manage? procession, unit, short/long units, ... Best, Vicente

I like the ideas you put forth here. Though, I wonder if it could be taken a few steps further ... A boost formatting library 81 typedef boost::format::context_adapter< 82 struct timeval, 83 boost::format::context_spec< 84 boost::format::context_element<'d', ... > 85 > > timeval_context_t; 86 87 boost::format::basic_formatter<timeval_context_t> fmt; 88 89 struct timeval tv; 90 gettimeofday(&tv, NULL); 91 92 // Standard usage 93 std::cout << fmt("%d:%d",tv.tv_sec, tv.tv_usec) << std::endl; 94 95 // Output the first, then the second context elements 96 std::cout << fmt("%{1}:%{2}",tv) << std::endl; I like where the idea is taking me and I'm working on the implementation details now On Tue, Sep 13, 2011 at 6:11 PM, Vicente J. Botet Escriba < vicente.botet@wanadoo.fr> wrote:

Le 15/09/11 15:03, Steven Maitlall a écrit :
I like the ideas you put forth here. Thanks. Though, I wonder if it could be taken a few steps further ... A boost formatting library
81 typedef boost::format::context_adapter< 82 struct timeval, 83 boost::format::context_spec< 84 boost::format::context_element<'d', ...> 85> > timeval_context_t; 86 87 boost::format::basic_formatter<timeval_context_t> fmt; 88 89 struct timeval tv; 90 gettimeofday(&tv, NULL); 91 92 // Standard usage 93 std::cout<< fmt("%d:%d",tv.tv_sec, tv.tv_usec)<< std::endl; 94 95 // Output the first, then the second context elements 96 std::cout<< fmt("%{1}:%{2}",tv)<< std::endl;
I like where the idea is taking me and I'm working on the implementation details now
IUC what you want to achieve is to format a UDT using its parts. I think that seen the UDT as a tuple could help. What about using the {i,j} to refer to the j-th part of the i-th parameter? In this way you could mix several parameter with the same format. std::cout<< fmt("{1,1}:{1,2} = {2}") % tv % i; I think I start to see how such a library could help to make easier the Stopwatch reporting. I would be greatfull if you could explain how this can be applied in my context. Thanks, Vicente

On Thu, Sep 15, 2011 at 2:52 PM, Vicente J. Botet Escriba < vicente.botet@wanadoo.fr> wrote:
I think I start to see how such a library could help to make easier the Stopwatch reporting. I would be greatfull if you could explain how this can be applied in my context.
I've attached a description of the API I have in mind. First, does it make sense ? How does that fit with what you had in mind for reporting? Is the API flexible enough to let you do what you want? I expect that Boost.Format will define context types for other boost types in different libraries, so default contexts can be available. So there could be a default context for a Boost.Stopwatch type.

Le 16/09/11 18:11, Steven Maitlall a écrit :
On Thu, Sep 15, 2011 at 2:52 PM, Vicente J. Botet Escriba< vicente.botet@wanadoo.fr> wrote:
I think I start to see how such a library could help to make easier the Stopwatch reporting. I would be greatfull if you could explain how this can be applied in my context.
I've attached a description of the API I have in mind. First, does it make sense ? How does that fit with what you had in mind for reporting? Is the API flexible enough to let you do what you want?
I expect that Boost.Format will define context types for other boost types in different libraries, so default contexts can be available. So there could be a default context for a Boost.Stopwatch type. Not easy to say with the provided information. I will wait until you have something working.
Best, Vicente
participants (2)
-
Steven Maitlall
-
Vicente J. Botet Escriba