xref: /trunk/main/automation/source/server/profiler.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 
30 #define AVER( pFirst, pSecond, Membername ) (( pFirst->Membername + pSecond->Membername ) / 2 )
31 #define DIFF( pFirst, pSecond, Membername ) ( pSecond->Membername - pFirst->Membername )
32 #define S_SAFEDIV( a,b ) ((b)==0?CUniString("#DIV"):UniString::CreateFromInt32( (ULONG) ((a)/(b))))
33 #define S_SAFEDIV_DEC( a,b ) ((b)==0?CUniString("#DIV"):Dec((ULONG) ((a)/(b))))
34 
35 #include <tools/time.hxx>
36 #include <tools/string.hxx>
37 #include <vcl/timer.hxx>
38 
39 #define PROFILE_START   0x01
40 #define PROFILE_END     0x02
41 
42 
43 struct SysdepProfileSnapshot;
44 struct SysdepStaticData;    // Nicht wirklich statisch, sondern statisch �ber mehrere Snapshots
45 
46 struct ProfileSnapshot
47 {
48     Time aTime;
49     SysdepProfileSnapshot *pSysdepProfileSnapshot;
50     sal_uLong nProcessTicks;
51     sal_uLong nSystemTicks;
52 };
53 
54 
55 class TTProfiler : private Timer
56 {
57 public:
58     TTProfiler();
59     ~TTProfiler();
60 
61     String GetProfileHeader();  // Titelzeile f�r Logdatei
62     void StartProfileInterval( sal_Bool bReadAnyway = sal_False );  // Zustand merken
63     void EndProfileInterval();  // Informationszeile zusammenbauen
64     String GetProfileLine( String &aPrefix );
65 
66 
67     void StartProfilingPerCommand();    // Jeden Befehl mitschneiden
68     void StopProfilingPerCommand();
69     sal_Bool IsProfilingPerCommand() { return bIsProfilingPerCommand; }
70 
71     void StartPartitioning();
72     void StopPartitioning();
73     sal_Bool IsPartitioning() { return bIsPartitioning; }
74     sal_uLong GetPartitioningTime();
75 
76     void StartAutoProfiling( sal_uLong nMSec ); // Automatisch alle nMSec Milisekunden sampeln
77     String GetAutoProfiling();  // Aktuelle `Sammlung` abholen
78     void StopAutoProfiling();   // Sampeln beenden
79     sal_Bool IsAutoProfiling() { return bIsAutoProfiling; }
80 
81 private:
82 
83     void GetProfileSnapshot( ProfileSnapshot *pProfileSnapshot );
84 
85     // Informationszeile zusammenbauen
86     String GetProfileLine( ProfileSnapshot *pStart, ProfileSnapshot *pStop );
87 
88 
89     ProfileSnapshot *mpStart;
90     ProfileSnapshot *mpEnd;
91     sal_Bool bIsProfileIntervalStarted;
92 
93 
94 
95 //
96     sal_Bool bIsProfilingPerCommand;
97     sal_Bool bIsPartitioning;
98 
99 
100 //  F�r das Automatische Profiling in festen Intervallen
101 
102     ProfileSnapshot *pAutoStart;
103     ProfileSnapshot *pAutoEnd;
104     sal_Bool bIsAutoProfiling;
105     String aAutoProfileBuffer;
106 
107     virtual void Timeout();
108 
109 
110 // Einige Hilfsfunktionen
111 
112 //  String Hex( sal_uLong nNr );
113     String Dec( sal_uLong nNr );    // Ergebnis = nNr / 100 mit 2 Dezimalen
114     String Pad( const String aS, xub_StrLen nLen );     // F�gt blanks links an den String an
115 
116 /*  Ab hier werden die Methoden Systemabh�ngig in den entsprechenden cxx implementiert
117     Sie werden von den oberen Methoden gerufen.
118 */
119 
120     SysdepStaticData *pSysDepStatic;
121 
122     void InitSysdepProfiler();
123     void DeinitSysdepProfiler();
124 
125     SysdepProfileSnapshot *NewSysdepSnapshotData();
126     void DeleteSysdepSnapshotData( SysdepProfileSnapshot *pSysdepProfileSnapshot );
127 
128     // Titelzeile f�r Logdatei
129     String GetSysdepProfileHeader();
130 
131     // Zustand merken
132     void GetSysdepProfileSnapshot( SysdepProfileSnapshot *pSysdepProfileSnapshot, sal_uInt16 nMode = PROFILE_START | PROFILE_END );
133 
134     // Informationszeile zusammenbauen
135     String GetSysdepProfileLine( SysdepProfileSnapshot *pStart, SysdepProfileSnapshot *pStop );
136 };
137 
138