update dev300-m58
[ooovba.git] / framework / inc / macros / debug / timemeasure.hxx
blobe9561cb62675f4762751d6040786e05c93631fe7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: timemeasure.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_MACROS_DEBUG_TIMEMEASURE_HXX_
32 #define __FRAMEWORK_MACROS_DEBUG_TIMEMEASURE_HXX_
34 //*************************************************************************************************************
35 // special macros for time measures
36 // 1) LOGFILE_TIMEMEASURE used it to define log file for this operations (default will be set automaticly)
37 // 2) START_TIMEMEASURE start new measure by using given variable names
38 // 3) START_TIMEMEASURE stop current measure by using given variable names and return time
39 // 4) LOG_TIMEMEASURE write measured time to logfile
40 //*************************************************************************************************************
42 #ifdef ENABLE_TIMEMEASURE
44 //_________________________________________________________________________________________________________________
45 // includes
46 //_________________________________________________________________________________________________________________
48 #ifndef _RTL_STRBUF_HXX_
49 #include <rtl/strbuf.hxx>
50 #endif
52 #ifndef _OSL_TIME_H_
53 #include <osl/time.h>
54 #endif
56 /*_____________________________________________________________________________________________________________
57 LOGFILE_TIMEMEASURE
59 For follow macros we need a special log file. If user forget to specify anyone, we must do it for him!
60 _____________________________________________________________________________________________________________*/
62 #ifndef LOGFILE_TIMEMEASURE
63 #define LOGFILE_TIMEMEASURE "timemeasure.log"
64 #endif
66 /*_____________________________________________________________________________________________________________
67 class TimeMeasure
69 We need this inline class as global timer to make it possible measure times over different objects!
70 zB. Use it as baseclass to start timer at ctor (must be first called baseclass!!!) and stop it by calling stop method.
71 _____________________________________________________________________________________________________________*/
73 class DBGTimeMeasureBase
75 public:
76 inline DBGTimeMeasureBase()
78 m_nEnd = 0 ;
79 m_nStart = osl_getGlobalTimer();
82 inline sal_Int32 stopAndGet()
84 m_nEnd = osl_getGlobalTimer();
85 return( m_nEnd-m_nStart );
88 private:
89 sal_Int32 m_nStart ;
90 sal_Int32 m_nEnd ;
93 /*_____________________________________________________________________________________________________________
94 START_TIMEMEASURE( NSTART, NEND )
95 STOP_TIMEMEASURE( NSTART, NEND, NTIME )
97 If you doesn't need a time measure above different classes ... you can try this macros!
98 They initialize your given members with start end end time ... You can calculate differenz by himself.
99 _____________________________________________________________________________________________________________*/
101 #define START_TIMEMEASURE( NSTART, NEND ) \
102 sal_Int32 NSTART = 0; \
103 sal_Int32 NEND = 0; \
104 NSTART = osl_getGlobalTimer();
106 #define STOP_TIMEMEASURE( NSTART, NEND, NTIME ) \
107 NEND = osl_getGlobalTimer(); \
108 sal_Int32 NTIME = NEND-NSTART;
110 /*_____________________________________________________________________________________________________________
111 LOG_TIMEMEASURE( SOPERATION, NSTART )
113 Write measured time to logfile.
114 _____________________________________________________________________________________________________________*/
116 #define LOG_TIMEMEASURE( SOPERATION, NTIME ) \
118 ::rtl::OStringBuffer _sBuffer( 256 ); \
119 _sBuffer.append( SOPERATION ); \
120 _sBuffer.append( "\t=\t" ); \
121 _sBuffer.append( (sal_Int32)(NTIME) ); \
122 _sBuffer.append( " ms\n" ); \
123 WRITE_LOGFILE( LOGFILE_TIMEMEASURE, _sBuffer.makeStringAndClear().getStr() ) \
126 #else // #ifdef ENABLE_TIMEMEASURE
128 /*_____________________________________________________________________________________________________________
129 If right testmode is'nt set - implements these macros empty!
130 _____________________________________________________________________________________________________________*/
132 #undef LOGFILE_TIMEMEASURE
133 #define START_TIMEMEASURE( NSTART, NEND )
134 #define STOP_TIMEMEASURE( NSTART, NEND, NTIME )
135 #define LOG_TIMEMEASURE( SOPERATION, NTIME )
137 #endif // #ifdef ENABLE_TIMEMEASURE
139 //*****************************************************************************************************************
140 // end of file
141 //*****************************************************************************************************************
143 #endif // #ifndef __FRAMEWORK_MACROS_DEBUG_TIMEMEASURE_HXX_