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 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #define AVER( pFirst, pSecond, Membername ) (( pFirst->Membername + pSecond->Membername ) / 2 ) 31*cdf0e10cSrcweir #define DIFF( pFirst, pSecond, Membername ) ( pSecond->Membername - pFirst->Membername ) 32*cdf0e10cSrcweir #define S_SAFEDIV( a,b ) ((b)==0?CUniString("#DIV"):UniString::CreateFromInt32( (ULONG) ((a)/(b)))) 33*cdf0e10cSrcweir #define S_SAFEDIV_DEC( a,b ) ((b)==0?CUniString("#DIV"):Dec((ULONG) ((a)/(b)))) 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <tools/time.hxx> 36*cdf0e10cSrcweir #include <tools/string.hxx> 37*cdf0e10cSrcweir #include <vcl/timer.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #define PROFILE_START 0x01 40*cdf0e10cSrcweir #define PROFILE_END 0x02 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir struct SysdepProfileSnapshot; 44*cdf0e10cSrcweir struct SysdepStaticData; // Nicht wirklich statisch, sondern statisch �ber mehrere Snapshots 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir struct ProfileSnapshot 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir Time aTime; 49*cdf0e10cSrcweir SysdepProfileSnapshot *pSysdepProfileSnapshot; 50*cdf0e10cSrcweir sal_uLong nProcessTicks; 51*cdf0e10cSrcweir sal_uLong nSystemTicks; 52*cdf0e10cSrcweir }; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir class TTProfiler : private Timer 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir public: 58*cdf0e10cSrcweir TTProfiler(); 59*cdf0e10cSrcweir ~TTProfiler(); 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir String GetProfileHeader(); // Titelzeile f�r Logdatei 62*cdf0e10cSrcweir void StartProfileInterval( sal_Bool bReadAnyway = sal_False ); // Zustand merken 63*cdf0e10cSrcweir void EndProfileInterval(); // Informationszeile zusammenbauen 64*cdf0e10cSrcweir String GetProfileLine( String &aPrefix ); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir void StartProfilingPerCommand(); // Jeden Befehl mitschneiden 68*cdf0e10cSrcweir void StopProfilingPerCommand(); 69*cdf0e10cSrcweir sal_Bool IsProfilingPerCommand() { return bIsProfilingPerCommand; } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir void StartPartitioning(); 72*cdf0e10cSrcweir void StopPartitioning(); 73*cdf0e10cSrcweir sal_Bool IsPartitioning() { return bIsPartitioning; } 74*cdf0e10cSrcweir sal_uLong GetPartitioningTime(); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir void StartAutoProfiling( sal_uLong nMSec ); // Automatisch alle nMSec Milisekunden sampeln 77*cdf0e10cSrcweir String GetAutoProfiling(); // Aktuelle `Sammlung` abholen 78*cdf0e10cSrcweir void StopAutoProfiling(); // Sampeln beenden 79*cdf0e10cSrcweir sal_Bool IsAutoProfiling() { return bIsAutoProfiling; } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir private: 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir void GetProfileSnapshot( ProfileSnapshot *pProfileSnapshot ); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir // Informationszeile zusammenbauen 86*cdf0e10cSrcweir String GetProfileLine( ProfileSnapshot *pStart, ProfileSnapshot *pStop ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir ProfileSnapshot *mpStart; 90*cdf0e10cSrcweir ProfileSnapshot *mpEnd; 91*cdf0e10cSrcweir sal_Bool bIsProfileIntervalStarted; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // 96*cdf0e10cSrcweir sal_Bool bIsProfilingPerCommand; 97*cdf0e10cSrcweir sal_Bool bIsPartitioning; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // F�r das Automatische Profiling in festen Intervallen 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir ProfileSnapshot *pAutoStart; 103*cdf0e10cSrcweir ProfileSnapshot *pAutoEnd; 104*cdf0e10cSrcweir sal_Bool bIsAutoProfiling; 105*cdf0e10cSrcweir String aAutoProfileBuffer; 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir virtual void Timeout(); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // Einige Hilfsfunktionen 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // String Hex( sal_uLong nNr ); 113*cdf0e10cSrcweir String Dec( sal_uLong nNr ); // Ergebnis = nNr / 100 mit 2 Dezimalen 114*cdf0e10cSrcweir String Pad( const String aS, xub_StrLen nLen ); // F�gt blanks links an den String an 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir /* Ab hier werden die Methoden Systemabh�ngig in den entsprechenden cxx implementiert 117*cdf0e10cSrcweir Sie werden von den oberen Methoden gerufen. 118*cdf0e10cSrcweir */ 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir SysdepStaticData *pSysDepStatic; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir void InitSysdepProfiler(); 123*cdf0e10cSrcweir void DeinitSysdepProfiler(); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir SysdepProfileSnapshot *NewSysdepSnapshotData(); 126*cdf0e10cSrcweir void DeleteSysdepSnapshotData( SysdepProfileSnapshot *pSysdepProfileSnapshot ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // Titelzeile f�r Logdatei 129*cdf0e10cSrcweir String GetSysdepProfileHeader(); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // Zustand merken 132*cdf0e10cSrcweir void GetSysdepProfileSnapshot( SysdepProfileSnapshot *pSysdepProfileSnapshot, sal_uInt16 nMode = PROFILE_START | PROFILE_END ); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // Informationszeile zusammenbauen 135*cdf0e10cSrcweir String GetSysdepProfileLine( SysdepProfileSnapshot *pStart, SysdepProfileSnapshot *pStop ); 136*cdf0e10cSrcweir }; 137*cdf0e10cSrcweir 138