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