1f8e07b45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f8e07b45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f8e07b45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f8e07b45SAndrew Rist * distributed with this work for additional information 6f8e07b45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f8e07b45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f8e07b45SAndrew Rist * "License"); you may not use this file except in compliance 9f8e07b45SAndrew Rist * with the License. You may obtain a copy of the License at 10f8e07b45SAndrew Rist * 11f8e07b45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12f8e07b45SAndrew Rist * 13f8e07b45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f8e07b45SAndrew Rist * software distributed under the License is distributed on an 15f8e07b45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f8e07b45SAndrew Rist * KIND, either express or implied. See the License for the 17f8e07b45SAndrew Rist * specific language governing permissions and limitations 18f8e07b45SAndrew Rist * under the License. 19f8e07b45SAndrew Rist * 20f8e07b45SAndrew Rist *************************************************************/ 21f8e07b45SAndrew Rist 22f8e07b45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef __FRAMEWORK_MACROS_DEBUG_MEMORYMEASURE_HXX_ 25cdf0e10cSrcweir #define __FRAMEWORK_MACROS_DEBUG_MEMORYMEASURE_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir //************************************************************************************************************* 28cdf0e10cSrcweir // special macros for time measures 29*07a3d7f1SPedro Giffuni // 1) LOGFILE_MEMORYMEASURE used it to define log file for this operations (default will be set automatically) 30cdf0e10cSrcweir // 2) MAKE_MEMORY_SNAPSHOT make snapshot of currently set memory informations of OS 31cdf0e10cSrcweir // 3) LOG_MEMORYMEASURE write measured time to logfile 32cdf0e10cSrcweir //************************************************************************************************************* 33cdf0e10cSrcweir 34cdf0e10cSrcweir #ifdef ENABLE_MEMORYMEASURE 35cdf0e10cSrcweir 36cdf0e10cSrcweir #if !defined( WNT ) 37cdf0e10cSrcweir #error "Macros to measure memory access not available under platforms different from windows!" 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir 40cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 41cdf0e10cSrcweir // includes 42cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 43cdf0e10cSrcweir 44cdf0e10cSrcweir #ifndef _RTL_STRBUF_HXX_ 45cdf0e10cSrcweir #include <rtl/strbuf.hxx> 46cdf0e10cSrcweir #endif 47cdf0e10cSrcweir 48cdf0e10cSrcweir #ifndef __SGI_STL_VECTOR 49cdf0e10cSrcweir #include <vector> 50cdf0e10cSrcweir #endif 51cdf0e10cSrcweir 52cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 53cdf0e10cSrcweir LOGFILE_MEMORYMEASURE 54cdf0e10cSrcweir 55cdf0e10cSrcweir For follow macros we need a special log file. If user forget to specify anyone, we must do it for him! 56cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 57cdf0e10cSrcweir 58cdf0e10cSrcweir #ifndef LOGFILE_MEMORYMEASURE 59cdf0e10cSrcweir #define LOGFILE_MEMORYMEASURE "memorymeasure.log" 60cdf0e10cSrcweir #endif 61cdf0e10cSrcweir 62cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 63cdf0e10cSrcweir class MemoryMeasure 64cdf0e10cSrcweir 65cdf0e10cSrcweir We use this baseclass to collect all snapshots in one object and analyze this information at one point. 66cdf0e10cSrcweir Macros of this file are used to enable using of this class by special compile-parameter only! 67cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 68cdf0e10cSrcweir 69cdf0e10cSrcweir class _DBGMemoryMeasure 70cdf0e10cSrcweir { 71cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 72cdf0e10cSrcweir private: 73cdf0e10cSrcweir struct _MemoryInfo 74cdf0e10cSrcweir { 75cdf0e10cSrcweir MEMORYSTATUS aStatus ; 76cdf0e10cSrcweir ::rtl::OString sComment ; 77cdf0e10cSrcweir }; 78cdf0e10cSrcweir 79cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 80cdf0e10cSrcweir public: 81cdf0e10cSrcweir //_____________________________________________________________________________________________________ _DBGMemoryMeasure()82cdf0e10cSrcweir inline _DBGMemoryMeasure() 83cdf0e10cSrcweir { 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir //_____________________________________________________________________________________________________ 87cdf0e10cSrcweir // clear used container! ~_DBGMemoryMeasure()88cdf0e10cSrcweir inline ~_DBGMemoryMeasure() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir ::std::vector< _MemoryInfo >().swap( m_lSnapshots ); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir //_____________________________________________________________________________________________________ makeSnapshot(const::rtl::OString & sComment)94cdf0e10cSrcweir inline void makeSnapshot( const ::rtl::OString& sComment ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir _MemoryInfo aInfo; 97cdf0e10cSrcweir aInfo.sComment = sComment; 98cdf0e10cSrcweir GlobalMemoryStatus ( &(aInfo.aStatus) ); 99cdf0e10cSrcweir m_lSnapshots.push_back( aInfo ); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir //_____________________________________________________________________________________________________ getLog()103cdf0e10cSrcweir inline ::rtl::OString getLog() 104cdf0e10cSrcweir { 105cdf0e10cSrcweir ::rtl::OStringBuffer sBuffer( 10000 ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir if( !m_lSnapshots.empty() ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir // Write informations to return buffer 110cdf0e10cSrcweir ::std::vector< _MemoryInfo >::const_iterator pItem1; 111cdf0e10cSrcweir ::std::vector< _MemoryInfo >::const_iterator pItem2; 112cdf0e10cSrcweir 113cdf0e10cSrcweir pItem1 = m_lSnapshots.begin(); 114cdf0e10cSrcweir pItem2 = pItem1; 115cdf0e10cSrcweir ++pItem2; 116cdf0e10cSrcweir 117cdf0e10cSrcweir while( pItem1!=m_lSnapshots.end() ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir sBuffer.append( "snap [ " ); 120cdf0e10cSrcweir sBuffer.append( pItem1->sComment ); 121cdf0e10cSrcweir sBuffer.append( " ]\n\tavail phys\t=\t" ); 122cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPhys ); 123cdf0e10cSrcweir sBuffer.append( "\n\tavail page\t=\t" ); 124cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPageFile ); 125cdf0e10cSrcweir sBuffer.append( "\n\tavail virt\t=\t" ); 126cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailVirtual ); 127cdf0e10cSrcweir sBuffer.append( "\n\tdifference\t=\t[ " ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir if( pItem1 == m_lSnapshots.begin() ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPhys ); 132cdf0e10cSrcweir sBuffer.append( ", " ); 133cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailPageFile ); 134cdf0e10cSrcweir sBuffer.append( ", " ); 135cdf0e10cSrcweir sBuffer.append( (sal_Int32)pItem1->aStatus.dwAvailVirtual ); 136cdf0e10cSrcweir sBuffer.append( " ]\n\n" ); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir else if( pItem2 != m_lSnapshots.end() ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir sBuffer.append( (sal_Int32)(pItem2->aStatus.dwAvailPhys - pItem1->aStatus.dwAvailPhys ) ); 141cdf0e10cSrcweir sBuffer.append( ", " ); 142cdf0e10cSrcweir sBuffer.append( (sal_Int32)(pItem2->aStatus.dwAvailPageFile - pItem1->aStatus.dwAvailPageFile ) ); 143cdf0e10cSrcweir sBuffer.append( ", " ); 144cdf0e10cSrcweir sBuffer.append( (sal_Int32)(pItem2->aStatus.dwAvailVirtual - pItem1->aStatus.dwAvailVirtual ) ); 145cdf0e10cSrcweir sBuffer.append( " ]\n\n" ); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir else 148cdf0e10cSrcweir { 149cdf0e10cSrcweir sBuffer.append( "0, 0, 0 ]\n\n" ); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir if( pItem1!=m_lSnapshots.end() ) ++pItem1; 152cdf0e10cSrcweir if( pItem2!=m_lSnapshots.end() ) ++pItem2; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir // clear current list ... make it empty for further snapshots! 155cdf0e10cSrcweir ::std::vector< _MemoryInfo >().swap( m_lSnapshots ); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir return sBuffer.makeStringAndClear(); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 162cdf0e10cSrcweir private: 163cdf0e10cSrcweir ::std::vector< _MemoryInfo > m_lSnapshots; 164cdf0e10cSrcweir }; 165cdf0e10cSrcweir 166cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 167cdf0e10cSrcweir START_MEMORY_MEASURE 168cdf0e10cSrcweir 169cdf0e10cSrcweir Create new object to measure memory access. 170cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 171cdf0e10cSrcweir 172cdf0e10cSrcweir #define START_MEMORYMEASURE( AOBJECT ) \ 173cdf0e10cSrcweir _DBGMemoryMeasure AOBJECT; 174cdf0e10cSrcweir 175cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 176cdf0e10cSrcweir MAKE_MEMORY_SNAPSHOT 177cdf0e10cSrcweir 178cdf0e10cSrcweir Make snapshot of currently set memory informations of OS. 179cdf0e10cSrcweir see _DBGMemoryMeasure for further informations 180cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 181cdf0e10cSrcweir 182cdf0e10cSrcweir #define MAKE_MEMORY_SNAPSHOT( AOBJECT, SCOMMENT ) \ 183cdf0e10cSrcweir AOBJECT.makeSnapshot( SCOMMENT ); 184cdf0e10cSrcweir 185cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 186cdf0e10cSrcweir LOG_MEMORYMEASURE( SOPERATION, SCOMMENT, AOBJECT ) 187cdf0e10cSrcweir 188cdf0e10cSrcweir Write measured values to logfile. 189cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 190cdf0e10cSrcweir 191cdf0e10cSrcweir #define LOG_MEMORYMEASURE( SOPERATION, SCOMMENT, AOBJECT ) \ 192cdf0e10cSrcweir { \ 193cdf0e10cSrcweir ::rtl::OStringBuffer _sBuffer( 256 ); \ 194cdf0e10cSrcweir _sBuffer.append( SOPERATION ); \ 195cdf0e10cSrcweir _sBuffer.append( "\n" ); \ 196cdf0e10cSrcweir _sBuffer.append( SCOMMENT ); \ 197cdf0e10cSrcweir _sBuffer.append( "\n\n" ); \ 198cdf0e10cSrcweir _sBuffer.append( AOBJECT.getLog() ); \ 199cdf0e10cSrcweir WRITE_LOGFILE( LOGFILE_MEMORYMEASURE, _sBuffer.makeStringAndClear() ) \ 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir #else // #ifdef ENABLE_MEMORYMEASURE 203cdf0e10cSrcweir 204cdf0e10cSrcweir /*_____________________________________________________________________________________________________________ 205cdf0e10cSrcweir If right testmode is'nt set - implements these macros empty! 206cdf0e10cSrcweir _____________________________________________________________________________________________________________*/ 207cdf0e10cSrcweir 208cdf0e10cSrcweir #undef LOGFILE_MEMORYMEASURE 209cdf0e10cSrcweir #define START_MEMORYMEASURE( AOBJECT ) 210cdf0e10cSrcweir #define MAKE_MEMORY_SNAPSHOT( AOBJECT, SCOMMENT ) 211cdf0e10cSrcweir #define LOG_MEMORYMEASURE( SOPERATION, SCOMMENT, AOBJECT ) 212cdf0e10cSrcweir 213cdf0e10cSrcweir #endif // #ifdef ENABLE_MEMORYMEASURE 214cdf0e10cSrcweir 215cdf0e10cSrcweir //***************************************************************************************************************** 216cdf0e10cSrcweir // end of file 217cdf0e10cSrcweir //***************************************************************************************************************** 218cdf0e10cSrcweir 219cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_MACROS_DEBUG_MEMORYMEASURE_HXX_ 220