1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef __FRAMEWORK_MACROS_DEBUG_MEMORYMEASURE_HXX_ 29*cdf0e10cSrcweir #define __FRAMEWORK_MACROS_DEBUG_MEMORYMEASURE_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //************************************************************************************************************* 32*cdf0e10cSrcweir // special macros for time measures 33*cdf0e10cSrcweir // 1) LOGFILE_MEMORYMEASURE used it to define log file for this operations (default will be set automaticly) 34*cdf0e10cSrcweir // 2) MAKE_MEMORY_SNAPSHOT make snapshot of currently set memory informations of OS 35*cdf0e10cSrcweir // 3) LOG_MEMORYMEASURE write measured time to logfile 36*cdf0e10cSrcweir //************************************************************************************************************* 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #ifdef ENABLE_MEMORYMEASURE 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #if !defined( WNT ) 41*cdf0e10cSrcweir #error "Macros to measure memory access not available under platforms different from windows!" 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 45*cdf0e10cSrcweir // includes 46*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #ifndef _RTL_STRBUF_HXX_ 49*cdf0e10cSrcweir #include <rtl/strbuf.hxx> 50*cdf0e10cSrcweir #endif 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #ifndef __SGI_STL_VECTOR 53*cdf0e10cSrcweir #include <vector> 54*cdf0e10cSrcweir #endif 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 57*cdf0e10cSrcweir LOGFILE_MEMORYMEASURE 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir For follow macros we need a special log file. If user forget to specify anyone, we must do it for him! 60*cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #ifndef LOGFILE_MEMORYMEASURE 63*cdf0e10cSrcweir #define LOGFILE_MEMORYMEASURE "memorymeasure.log" 64*cdf0e10cSrcweir #endif 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 67*cdf0e10cSrcweir class MemoryMeasure 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir We use this baseclass to collect all snapshots in one object and analyze this information at one point. 70*cdf0e10cSrcweir Macros of this file are used to enable using of this class by special compile-parameter only! 71*cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir class _DBGMemoryMeasure 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 76*cdf0e10cSrcweir private: 77*cdf0e10cSrcweir struct _MemoryInfo 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir MEMORYSTATUS aStatus ; 80*cdf0e10cSrcweir ::rtl::OString sComment ; 81*cdf0e10cSrcweir }; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 84*cdf0e10cSrcweir public: 85*cdf0e10cSrcweir //_____________________________________________________________________________________________________ 86*cdf0e10cSrcweir inline _DBGMemoryMeasure() 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir //_____________________________________________________________________________________________________ 91*cdf0e10cSrcweir // clear used container! 92*cdf0e10cSrcweir inline ~_DBGMemoryMeasure() 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir ::std::vector< _MemoryInfo >().swap( m_lSnapshots ); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //_____________________________________________________________________________________________________ 98*cdf0e10cSrcweir inline void makeSnapshot( const ::rtl::OString& sComment ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir _MemoryInfo aInfo; 101*cdf0e10cSrcweir aInfo.sComment = sComment; 102*cdf0e10cSrcweir GlobalMemoryStatus ( &(aInfo.aStatus) ); 103*cdf0e10cSrcweir m_lSnapshots.push_back( aInfo ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //_____________________________________________________________________________________________________ 107*cdf0e10cSrcweir inline ::rtl::OString getLog() 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir ::rtl::OStringBuffer sBuffer( 10000 ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir if( !m_lSnapshots.empty() ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir // Write informations to return buffer 114*cdf0e10cSrcweir ::std::vector< _MemoryInfo >::const_iterator pItem1; 115*cdf0e10cSrcweir ::std::vector< _MemoryInfo >::const_iterator pItem2; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir pItem1 = m_lSnapshots.begin(); 118*cdf0e10cSrcweir pItem2 = pItem1; 119*cdf0e10cSrcweir ++pItem2; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir while( pItem1!=m_lSnapshots.end() ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir sBuffer.append( "snap [ " ); 124*cdf0e10cSrcweir sBuffer.append( pItem1->sComment ); 125*cdf0e10cSrcweir sBuffer.append( " ]\n\tavail phys\t=\t" ); 126*cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPhys ); 127*cdf0e10cSrcweir sBuffer.append( "\n\tavail page\t=\t" ); 128*cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPageFile ); 129*cdf0e10cSrcweir sBuffer.append( "\n\tavail virt\t=\t" ); 130*cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailVirtual ); 131*cdf0e10cSrcweir sBuffer.append( "\n\tdifference\t=\t[ " ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir if( pItem1 == m_lSnapshots.begin() ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPhys ); 136*cdf0e10cSrcweir sBuffer.append( ", " ); 137*cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPageFile ); 138*cdf0e10cSrcweir sBuffer.append( ", " ); 139*cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailVirtual ); 140*cdf0e10cSrcweir sBuffer.append( " ]\n\n" ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir else if( pItem2 != m_lSnapshots.end() ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir sBuffer.append( (sal_Int32)(pItem2->aStatus.dwAvailPhys - pItem1->aStatus.dwAvailPhys ) ); 145*cdf0e10cSrcweir sBuffer.append( ", " ); 146*cdf0e10cSrcweir sBuffer.append( (sal_Int32)(pItem2->aStatus.dwAvailPageFile - pItem1->aStatus.dwAvailPageFile ) ); 147*cdf0e10cSrcweir sBuffer.append( ", " ); 148*cdf0e10cSrcweir sBuffer.append( (sal_Int32)(pItem2->aStatus.dwAvailVirtual - pItem1->aStatus.dwAvailVirtual ) ); 149*cdf0e10cSrcweir sBuffer.append( " ]\n\n" ); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir else 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir sBuffer.append( "0, 0, 0 ]\n\n" ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir if( pItem1!=m_lSnapshots.end() ) ++pItem1; 156*cdf0e10cSrcweir if( pItem2!=m_lSnapshots.end() ) ++pItem2; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir // clear current list ... make it empty for further snapshots! 159*cdf0e10cSrcweir ::std::vector< _MemoryInfo >().swap( m_lSnapshots ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir return sBuffer.makeStringAndClear(); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 166*cdf0e10cSrcweir private: 167*cdf0e10cSrcweir ::std::vector< _MemoryInfo > m_lSnapshots; 168*cdf0e10cSrcweir }; 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 171*cdf0e10cSrcweir START_MEMORY_MEASURE 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir Create new object to measure memory access. 174*cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir #define START_MEMORYMEASURE( AOBJECT ) \ 177*cdf0e10cSrcweir _DBGMemoryMeasure AOBJECT; 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 180*cdf0e10cSrcweir MAKE_MEMORY_SNAPSHOT 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir Make snapshot of currently set memory informations of OS. 183*cdf0e10cSrcweir see _DBGMemoryMeasure for further informations 184*cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir #define MAKE_MEMORY_SNAPSHOT( AOBJECT, SCOMMENT ) \ 187*cdf0e10cSrcweir AOBJECT.makeSnapshot( SCOMMENT ); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 190*cdf0e10cSrcweir LOG_MEMORYMEASURE( SOPERATION, SCOMMENT, AOBJECT ) 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir Write measured values to logfile. 193*cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir #define LOG_MEMORYMEASURE( SOPERATION, SCOMMENT, AOBJECT ) \ 196*cdf0e10cSrcweir { \ 197*cdf0e10cSrcweir ::rtl::OStringBuffer _sBuffer( 256 ); \ 198*cdf0e10cSrcweir _sBuffer.append( SOPERATION ); \ 199*cdf0e10cSrcweir _sBuffer.append( "\n" ); \ 200*cdf0e10cSrcweir _sBuffer.append( SCOMMENT ); \ 201*cdf0e10cSrcweir _sBuffer.append( "\n\n" ); \ 202*cdf0e10cSrcweir _sBuffer.append( AOBJECT.getLog() ); \ 203*cdf0e10cSrcweir WRITE_LOGFILE( LOGFILE_MEMORYMEASURE, _sBuffer.makeStringAndClear() ) \ 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir #else // #ifdef ENABLE_MEMORYMEASURE 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 209*cdf0e10cSrcweir If right testmode is'nt set - implements these macros empty! 210*cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir #undef LOGFILE_MEMORYMEASURE 213*cdf0e10cSrcweir #define START_MEMORYMEASURE( AOBJECT ) 214*cdf0e10cSrcweir #define MAKE_MEMORY_SNAPSHOT( AOBJECT, SCOMMENT ) 215*cdf0e10cSrcweir #define LOG_MEMORYMEASURE( SOPERATION, SCOMMENT, AOBJECT ) 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir #endif // #ifdef ENABLE_MEMORYMEASURE 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir //***************************************************************************************************************** 220*cdf0e10cSrcweir // end of file 221*cdf0e10cSrcweir //***************************************************************************************************************** 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_MACROS_DEBUG_MEMORYMEASURE_HXX_ 224