1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 25 26 #define AVER( pFirst, pSecond, Membername ) (( pFirst->Membername + pSecond->Membername ) / 2 ) 27 #define DIFF( pFirst, pSecond, Membername ) ( pSecond->Membername - pFirst->Membername ) 28 #define S_SAFEDIV( a,b ) ((b)==0?CUniString("#DIV"):UniString::CreateFromInt32( (ULONG) ((a)/(b)))) 29 #define S_SAFEDIV_DEC( a,b ) ((b)==0?CUniString("#DIV"):Dec((ULONG) ((a)/(b)))) 30 31 #include <tools/time.hxx> 32 #include <tools/string.hxx> 33 #include <vcl/timer.hxx> 34 35 #define PROFILE_START 0x01 36 #define PROFILE_END 0x02 37 38 39 struct SysdepProfileSnapshot; 40 struct SysdepStaticData; // Nicht wirklich statisch, sondern statisch �ber mehrere Snapshots 41 42 struct ProfileSnapshot 43 { 44 Time aTime; 45 SysdepProfileSnapshot *pSysdepProfileSnapshot; 46 sal_uLong nProcessTicks; 47 sal_uLong nSystemTicks; 48 }; 49 50 51 class TTProfiler : private Timer 52 { 53 public: 54 TTProfiler(); 55 ~TTProfiler(); 56 57 String GetProfileHeader(); // Titelzeile f�r Logdatei 58 void StartProfileInterval( sal_Bool bReadAnyway = sal_False ); // Zustand merken 59 void EndProfileInterval(); // Informationszeile zusammenbauen 60 String GetProfileLine( String &aPrefix ); 61 62 63 void StartProfilingPerCommand(); // Jeden Befehl mitschneiden 64 void StopProfilingPerCommand(); IsProfilingPerCommand()65 sal_Bool IsProfilingPerCommand() { return bIsProfilingPerCommand; } 66 67 void StartPartitioning(); 68 void StopPartitioning(); IsPartitioning()69 sal_Bool IsPartitioning() { return bIsPartitioning; } 70 sal_uLong GetPartitioningTime(); 71 72 void StartAutoProfiling( sal_uLong nMSec ); // Automatisch alle nMSec Milisekunden sampeln 73 String GetAutoProfiling(); // Aktuelle `Sammlung` abholen 74 void StopAutoProfiling(); // Sampeln beenden IsAutoProfiling()75 sal_Bool IsAutoProfiling() { return bIsAutoProfiling; } 76 77 private: 78 79 void GetProfileSnapshot( ProfileSnapshot *pProfileSnapshot ); 80 81 // Informationszeile zusammenbauen 82 String GetProfileLine( ProfileSnapshot *pStart, ProfileSnapshot *pStop ); 83 84 85 ProfileSnapshot *mpStart; 86 ProfileSnapshot *mpEnd; 87 sal_Bool bIsProfileIntervalStarted; 88 89 90 91 // 92 sal_Bool bIsProfilingPerCommand; 93 sal_Bool bIsPartitioning; 94 95 96 // F�r das Automatische Profiling in festen Intervallen 97 98 ProfileSnapshot *pAutoStart; 99 ProfileSnapshot *pAutoEnd; 100 sal_Bool bIsAutoProfiling; 101 String aAutoProfileBuffer; 102 103 virtual void Timeout(); 104 105 106 // Einige Hilfsfunktionen 107 108 // String Hex( sal_uLong nNr ); 109 String Dec( sal_uLong nNr ); // Ergebnis = nNr / 100 mit 2 Dezimalen 110 String Pad( const String aS, xub_StrLen nLen ); // F�gt blanks links an den String an 111 112 /* Ab hier werden die Methoden Systemabh�ngig in den entsprechenden cxx implementiert 113 Sie werden von den oberen Methoden gerufen. 114 */ 115 116 SysdepStaticData *pSysDepStatic; 117 118 void InitSysdepProfiler(); 119 void DeinitSysdepProfiler(); 120 121 SysdepProfileSnapshot *NewSysdepSnapshotData(); 122 void DeleteSysdepSnapshotData( SysdepProfileSnapshot *pSysdepProfileSnapshot ); 123 124 // Titelzeile f�r Logdatei 125 String GetSysdepProfileHeader(); 126 127 // Zustand merken 128 void GetSysdepProfileSnapshot( SysdepProfileSnapshot *pSysdepProfileSnapshot, sal_uInt16 nMode = PROFILE_START | PROFILE_END ); 129 130 // Informationszeile zusammenbauen 131 String GetSysdepProfileLine( SysdepProfileSnapshot *pStart, SysdepProfileSnapshot *pStop ); 132 }; 133 134