Imported Upstream version 17.25.4
[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       /** \overload log to custom ostream */
78       Measure( const std::string & ident_r, std::ostream & out_r );
79
80       /** Dtor. */
81       ~Measure();
82
83       /** Start timer for \a ident_r string.
84        * Implies stoping a running timer.
85       */
86       void start( const std::string & ident_r = std::string() );
87
88       /** re start the timer without reset-ing it. */
89       void restart();
90       
91       /** Print elapsed time for a running timer.
92        * Timer keeps on running.
93       */
94       void elapsed() const;
95       /** \overload Tagging the time with some text
96        * \code
97        * elapsed( "after action foo..." );
98        * \endcode
99        */
100       void elapsed( const std::string & tag_r ) const;
101       /** \overload Tagging the time with e.g. a line number
102        * \code
103        * elapsed( __LINE__ );
104        * \endcode
105        */
106       void elapsed( long tag_r ) const;
107
108       /** Stop a running timer. */
109       void stop();
110
111     private:
112       /** Implementation. */
113       class Impl;
114       /** Pointer to implementation. */
115       RW_pointer<Impl> _pimpl;
116     };
117     ///////////////////////////////////////////////////////////////////
118
119     /////////////////////////////////////////////////////////////////
120   } // namespace debug
121   ///////////////////////////////////////////////////////////////////
122   /////////////////////////////////////////////////////////////////
123 } // namespace zypp
124 ///////////////////////////////////////////////////////////////////
125 #endif // ZYPP_BASE_MEASURE_H