merge the formfield patch from ooo-build
[ooovba.git] / configmgr / workben / memory / memorymeasure.hxx
blob963af50468192829204fedf56271682e334eb374
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: memorymeasure.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_MEMORYMEASURE_HXX_
32 #define __FRAMEWORK_MACROS_DEBUG_MEMORYMEASURE_HXX_
34 // *************************************************************************************************************
35 // special macros for time measures
36 // 1) LOGFILE_MEMORYMEASURE used it to define log file for this operations (default will be set automaticly)
37 // 2) MAKE_MEMORY_SNAPSHOT make snapshot of currently set memory informations of OS
38 // 3) LOG_MEMORYMEASURE write measured time to logfile
39 // *************************************************************************************************************
41 #ifdef ENABLE_MEMORYMEASURE
43 #if !defined( WIN ) && !defined( WNT )
44 #error "Macros to measure memory access not available under platforms different from windows!"
45 #endif
47 //_________________________________________________________________________________________________________________
48 // includes
49 //_________________________________________________________________________________________________________________
51 #include <rtl/strbuf.hxx>
53 #ifndef __SGI_STL_VECTOR
54 #include <vector>
55 #endif
57 /*_____________________________________________________________________________________________________________
58 LOGFILE_MEMORYMEASURE
60 For follow macros we need a special log file. If user forget to specify anyone, we must do it for him!
61 _____________________________________________________________________________________________________________*/
63 #ifndef LOGFILE_MEMORYMEASURE
64 #define LOGFILE_MEMORYMEASURE "memorymeasure.log"
65 #endif
67 /*_____________________________________________________________________________________________________________
68 class MemoryMeasure
70 We use this baseclass to collect all snapshots in one object and analyze this information at one point.
71 Macros of this file are used to enable using of this class by special compile-parameter only!
72 _____________________________________________________________________________________________________________*/
74 class _DBGMemoryMeasure
76 //---------------------------------------------------------------------------------------------------------
77 private:
78 struct _MemoryInfo
80 MEMORYSTATUS aStatus ;
81 ::rtl::OString sComment ;
84 //---------------------------------------------------------------------------------------------------------
85 public:
86 //_____________________________________________________________________________________________________
87 inline _DBGMemoryMeasure()
89 makeSnapshot("Initializing Data");
91 //_____________________________________________________________________________________________________
92 inline _DBGMemoryMeasure(const ::rtl::OString& sComment)
94 makeSnapshot(sComment);
97 //_____________________________________________________________________________________________________
98 // clear used container!
99 inline ~_DBGMemoryMeasure()
101 ::std::vector< _MemoryInfo >().swap( m_lSnapshots );
104 //_____________________________________________________________________________________________________
105 inline void makeSnapshot( const ::rtl::OString& sComment )
107 _MemoryInfo aInfo;
108 aInfo.sComment = sComment;
109 GlobalMemoryStatus ( &(aInfo.aStatus) );
110 m_lSnapshots.push_back( aInfo );
113 //_____________________________________________________________________________________________________
114 inline ::rtl::OString getLog()
116 ::rtl::OStringBuffer sBuffer( 10000 );
118 if( m_lSnapshots.size() > 0 )
120 // Write informations to return buffer
121 ::std::vector< _MemoryInfo >::const_iterator pItem1;
122 ::std::vector< _MemoryInfo >::const_iterator pItem2;
124 pItem1 = m_lSnapshots.begin();
125 pItem2 = pItem1;
126 ++pItem2;
128 while( pItem1!=m_lSnapshots.end() )
130 sBuffer.append( "snap [ " );
131 sBuffer.append( pItem1->sComment );
132 sBuffer.append( " ]\n\tavail phys\t=\t" );
133 sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPhys );
134 sBuffer.append( "\n\tavail page\t=\t" );
135 sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPageFile );
136 sBuffer.append( "\n\tavail virt\t=\t" );
137 sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailVirtual );
139 if( pItem1 == m_lSnapshots.begin() )
141 sBuffer.append( "\n\t[initial values]\n\n" );
143 else if( pItem2 != m_lSnapshots.end() )
145 sBuffer.append( "\n\tdifference\t=\t[ " );
146 sBuffer.append( (sal_Int32)(pItem2->aStatus.dwAvailPhys - pItem1->aStatus.dwAvailPhys ) );
147 sBuffer.append( ", " );
148 sBuffer.append( (sal_Int32)(pItem2->aStatus.dwAvailPageFile - pItem1->aStatus.dwAvailPageFile ) );
149 sBuffer.append( ", " );
150 sBuffer.append( (sal_Int32)(pItem2->aStatus.dwAvailVirtual - pItem1->aStatus.dwAvailVirtual ) );
151 sBuffer.append( " ]\n\n" );
153 else
155 sBuffer.append( "\n\t[final values]\n\n" );
157 if( pItem1!=m_lSnapshots.end() ) ++pItem1;
158 if( pItem2!=m_lSnapshots.end() ) ++pItem2;
160 // clear current list ... make it empty for further snapshots!
161 ::std::vector< _MemoryInfo >().swap( m_lSnapshots );
164 return sBuffer.makeStringAndClear();
167 //---------------------------------------------------------------------------------------------------------
168 private:
169 ::std::vector< _MemoryInfo > m_lSnapshots;
172 /*_____________________________________________________________________________________________________________
173 START_MEMORY_MEASURE
175 Create new object to measure memory access.
176 _____________________________________________________________________________________________________________*/
178 #define START_MEMORYMEASURE( AOBJECT ) \
179 _DBGMemoryMeasure AOBJECT;
181 #define START_MEMORYMEASURE_FOR( AOBJECT, SCOMMENT ) \
182 _DBGMemoryMeasure AOBJECT( SCOMMENT );
184 /*_____________________________________________________________________________________________________________
185 MAKE_MEMORY_SNAPSHOT
187 Make snapshot of currently set memory informations of OS.
188 see _DBGMemoryMeasure for further informations
189 _____________________________________________________________________________________________________________*/
191 #define MAKE_MEMORY_SNAPSHOT( AOBJECT, SCOMMENT ) \
192 AOBJECT.makeSnapshot( SCOMMENT );
194 /*_____________________________________________________________________________________________________________
195 LOG_MEMORYMEASURE( SOPERATION, SCOMMENT, AOBJECT )
197 Write measured values to logfile.
198 _____________________________________________________________________________________________________________*/
200 #define LOG_MEMORYMEASURE( SOPERATION, SCOMMENT, AOBJECT ) \
202 ::rtl::OStringBuffer _sBuffer( 256 ); \
203 _sBuffer.append( SOPERATION ); \
204 _sBuffer.append( "\n" ); \
205 _sBuffer.append( SCOMMENT ); \
206 _sBuffer.append( "\n\n" ); \
207 _sBuffer.append( AOBJECT.getLog() ); \
208 WRITE_LOGFILE( LOGFILE_MEMORYMEASURE, _sBuffer.makeStringAndClear() ) \
211 #else // #ifdef ENABLE_MEMORYMEASURE
213 /*_____________________________________________________________________________________________________________
214 If right testmode is'nt set - implements these macros empty!
215 _____________________________________________________________________________________________________________*/
217 #undef LOGFILE_MEMORYMEASURE
218 #define START_MEMORYMEASURE( AOBJECT )
219 #define MAKE_MEMORY_SNAPSHOT( AOBJECT, SCOMMENT )
220 #define LOG_MEMORYMEASURE( SOPERATION, SCOMMENT, AOBJECT )
222 #endif // #ifdef ENABLE_MEMORYMEASURE
224 //*****************************************************************************************************************
225 // end of file
226 //*****************************************************************************************************************
228 #endif // #ifndef __FRAMEWORK_MACROS_DEBUG_MEMORYMEASURE_HXX_