1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: profiler.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #define AVER( pFirst, pSecond, Membername ) (( pFirst->Membername + pSecond->Membername ) / 2 )
34 #define DIFF( pFirst, pSecond, Membername ) ( pSecond->Membername - pFirst->Membername )
35 #define S_SAFEDIV( a,b ) ((b)==0?CUniString("#DIV"):UniString::CreateFromInt32( (ULONG) ((a)/(b))))
36 #define S_SAFEDIV_DEC( a,b ) ((b)==0?CUniString("#DIV"):Dec((ULONG) ((a)/(b))))
38 #include <tools/time.hxx>
39 #include <tools/string.hxx>
40 #include <vcl/timer.hxx>
42 #define PROFILE_START 0x01
43 #define PROFILE_END 0x02
46 struct SysdepProfileSnapshot
;
47 struct SysdepStaticData
; // Nicht wirklich statisch, sondern statisch über mehrere Snapshots
49 struct ProfileSnapshot
52 SysdepProfileSnapshot
*pSysdepProfileSnapshot
;
58 class TTProfiler
: private Timer
64 String
GetProfileHeader(); // Titelzeile für Logdatei
65 void StartProfileInterval( BOOL bReadAnyway
= FALSE
); // Zustand merken
66 void EndProfileInterval(); // Informationszeile zusammenbauen
67 String
GetProfileLine( String
&aPrefix
);
70 void StartProfilingPerCommand(); // Jeden Befehl mitschneiden
71 void StopProfilingPerCommand();
72 BOOL
IsProfilingPerCommand() { return bIsProfilingPerCommand
; }
74 void StartPartitioning();
75 void StopPartitioning();
76 BOOL
IsPartitioning() { return bIsPartitioning
; }
77 ULONG
GetPartitioningTime();
79 void StartAutoProfiling( ULONG nMSec
); // Automatisch alle nMSec Milisekunden sampeln
80 String
GetAutoProfiling(); // Aktuelle `Sammlung` abholen
81 void StopAutoProfiling(); // Sampeln beenden
82 BOOL
IsAutoProfiling() { return bIsAutoProfiling
; }
86 void GetProfileSnapshot( ProfileSnapshot
*pProfileSnapshot
);
88 // Informationszeile zusammenbauen
89 String
GetProfileLine( ProfileSnapshot
*pStart
, ProfileSnapshot
*pStop
);
92 ProfileSnapshot
*mpStart
;
93 ProfileSnapshot
*mpEnd
;
94 BOOL bIsProfileIntervalStarted
;
99 BOOL bIsProfilingPerCommand
;
100 BOOL bIsPartitioning
;
103 // Für das Automatische Profiling in festen Intervallen
105 ProfileSnapshot
*pAutoStart
;
106 ProfileSnapshot
*pAutoEnd
;
107 BOOL bIsAutoProfiling
;
108 String aAutoProfileBuffer
;
110 virtual void Timeout();
113 // Einige Hilfsfunktionen
115 // String Hex( ULONG nNr );
116 String
Dec( ULONG nNr
); // Ergebnis = nNr / 100 mit 2 Dezimalen
117 String
Pad( const String aS
, xub_StrLen nLen
); // Fügt blanks links an den String an
119 /* Ab hier werden die Methoden Systemabhängig in den entsprechenden cxx implementiert
120 Sie werden von den oberen Methoden gerufen.
123 SysdepStaticData
*pSysDepStatic
;
125 void InitSysdepProfiler();
126 void DeinitSysdepProfiler();
128 SysdepProfileSnapshot
*NewSysdepSnapshotData();
129 void DeleteSysdepSnapshotData( SysdepProfileSnapshot
*pSysdepProfileSnapshot
);
131 // Titelzeile für Logdatei
132 String
GetSysdepProfileHeader();
135 void GetSysdepProfileSnapshot( SysdepProfileSnapshot
*pSysdepProfileSnapshot
, USHORT nMode
= PROFILE_START
| PROFILE_END
);
137 // Informationszeile zusammenbauen
138 String
GetSysdepProfileLine( SysdepProfileSnapshot
*pStart
, SysdepProfileSnapshot
*pStop
);