8c2806ba9f7805c7736df0e69f94f9c7909e4a7b
[platform/upstream/libzypp.git] / zypp / base / Measure.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/base/Measure.h
10  *
11 */
12 #ifndef ZYPP_BASE_MEASURE_H
13 #define ZYPP_BASE_MEASURE_H
14
15 #include <iosfwd>
16 #include <string>
17
18 #include "zypp/base/PtrTypes.h"
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23   ///////////////////////////////////////////////////////////////////
24   namespace debug
25   { /////////////////////////////////////////////////////////////////
26
27     ///////////////////////////////////////////////////////////////////
28     //
29     //  CLASS NAME : Measure
30     //
31     /** Tool to measure elapsed real and process times.
32      *
33      * Timer is started by either passing a string to the ctor,
34      * or callign \ref start. The string passed is printed on
35      * all messages to help identifying the timer.
36      *
37      * Elapsed time is printed on calling \ref elapsed (timer
38      * keeps running) or \ref stop.
39      *
40      * Calling \ref stop, stops the timer. The same, if the timer
41      * goes out of scope.
42      *
43      * Elapsed time is printed as:
44      * \code
45      * 'REAL TIME' (u 'USER TIME' s 'SYSTEM TIME' c 'TIME OF CHILDREN')
46      * \endcode
47      * In brackets the time elapsed since a previous call to \ref elapsed.
48      * All units are seconds.
49      *
50      * \code
51      * Measure m( "Parse" );
52      * ...
53      * m.elapsed();
54      * ...
55      * m.elapsed();
56      * ...
57      * m.elapsed();
58      * ...
59      * m.stop();
60      *
61      * // START MEASURE(Parse)
62      * // ELAPSED(Parse)  0 (u 0.13 s 0.00 c 0.00)
63      * // ELAPSED(Parse)  0 (u 0.15 s 0.02 c 0.00) [ 0 (u 0.02 s 0.02 c 0.00)]
64      * // ELAPSED(Parse)  0 (u 0.17 s 0.02 c 0.00) [ 0 (u 0.02 s 0.00 c 0.00)]
65      * // MEASURE(Parse)  0 (u 0.17 s 0.02 c 0.00) [ 0 (u 0.00 s 0.00 c 0.00)]
66      * \endcode
67     */
68     class Measure
69     {
70     public:
71       /** Default Ctor does nothing. */
72       Measure();
73
74       /** Ctor taking \a ident_r string and auto starts timer. */
75       explicit
76       Measure( const std::string & ident_r );
77
78       /** Dtor. */
79       ~Measure();
80
81       /** Start timer for \a ident_r string.
82        * Implies stoping a running timer.
83       */
84       void start( const std::string & ident_r = std::string() );
85
86       /** re start the timer without reset-ing it. */
87       void restart();
88       
89       /** Print elapsed time for a running timer.
90        * Timer keeps on running.
91       */
92       void elapsed() const;
93
94       /** Stop a running timer. */
95       void stop();
96
97     private:
98       /** Implementation. */
99       class Impl;
100       /** Pointer to implementation. */
101       RW_pointer<Impl> _pimpl;
102     };
103     ///////////////////////////////////////////////////////////////////
104
105     /////////////////////////////////////////////////////////////////
106   } // namespace debug
107   ///////////////////////////////////////////////////////////////////
108   /////////////////////////////////////////////////////////////////
109 } // namespace zypp
110 ///////////////////////////////////////////////////////////////////
111 #endif // ZYPP_BASE_MEASURE_H