update dev300-m58
[ooovba.git] / automation / source / server / prof_usl.cxx
blob7127e903d970661205d161778429aa7783419ac3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: prof_usl.cxx,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_automation.hxx"
35 #include <procfs.h>
36 #include <tools/stream.hxx>
37 #include "profiler.hxx"
40 struct SysdepProfileSnapshot
42 pstatus mpstatus;
43 psinfo mpsinfo;
44 prusage mprusage;
48 struct SysdepStaticData
50 // Hier steht alles, was während des Profiles ständig gebraucht wird
54 void TTProfiler::InitSysdepProfiler()
56 if ( !pSysDepStatic ) // Sollte immer so sein!!
57 pSysDepStatic = new SysdepStaticData;
58 // Hier initialisieren
62 void TTProfiler::DeinitSysdepProfiler()
64 if ( pSysDepStatic ) // Sollte immer so sein!!
66 // Hier aufräumen und eventuell Speicher freigeben
68 delete pSysDepStatic;
72 SysdepProfileSnapshot *TTProfiler::NewSysdepSnapshotData()
74 return new SysdepProfileSnapshot;
77 void TTProfiler::DeleteSysdepSnapshotData( SysdepProfileSnapshot *pSysdepProfileSnapshot )
79 delete pSysdepProfileSnapshot;
83 // Titelzeile für Logdatei
84 String TTProfiler::GetSysdepProfileHeader()
86 return String::CreateFromAscii(" Size(Kb) ResidentSZ rtime ktime utime total");
90 // Zustand merken
91 void TTProfiler::GetSysdepProfileSnapshot( SysdepProfileSnapshot *pSysdepProfileSnapshot, USHORT )
93 SvFileStream aStream( String::CreateFromAscii("/proc/self/psinfo"), STREAM_READ ); // Das ist ein expliziter Pfad für UNXSOL!
94 if ( aStream.IsOpen() )
96 aStream.Read( &(pSysdepProfileSnapshot->mpsinfo), sizeof( psinfo ) );
97 aStream.Close();
99 SvFileStream anotherStream( String::CreateFromAscii("/proc/self/status"), STREAM_READ ); // Das ist ein expliziter Pfad für UNXSOL!
100 if ( anotherStream.IsOpen() )
102 anotherStream.Read( &(pSysdepProfileSnapshot->mpstatus), sizeof( pstatus ) );
103 anotherStream.Close();
105 SvFileStream YetAnotherStream( String::CreateFromAscii("/proc/self/usage"), STREAM_READ ); // Das ist ein expliziter Pfad für UNXSOL!
106 if ( YetAnotherStream.IsOpen() )
108 YetAnotherStream.Read( &(pSysdepProfileSnapshot->mprusage), sizeof( prusage ) );
109 YetAnotherStream.Close();
113 #define DIFF2( aFirst, aSecond, Membername ) ( aSecond.Membername - aFirst.Membername )
114 #define CALC_MS( nSec, nNSec ) ( nSec * 1000 + (nNSec+500000) / 1000000 )
115 #define DIFF_MS( pStart, pEnd, Member ) ( CALC_MS( pEnd->Member.tv_sec, pEnd->Member.tv_nsec ) - CALC_MS( pStart->Member.tv_sec, pStart->Member.tv_nsec ) )
116 // Informationszeile zusammenbauen
117 String TTProfiler::GetSysdepProfileLine( SysdepProfileSnapshot *pStart, SysdepProfileSnapshot *pStop )
119 String aProfile;
121 aProfile += Pad( String::CreateFromInt64(pStop->mpsinfo.pr_size), 9);
122 aProfile += Pad( String::CreateFromInt64(pStop->mpsinfo.pr_rssize), 11);
125 aProfile += Pad( String::CreateFromInt64(DIFF_MS( pStart, pStop, mprusage.pr_rtime ) / AVER( pStart, pStop, mprusage.pr_count )), 7 );
128 ULONG d_utime = DIFF_MS( pStart, pStop, mpstatus.pr_utime ) + DIFF_MS( pStart, pStop, mpstatus.pr_cutime );
129 ULONG d_stime = DIFF_MS( pStart, pStop, mpstatus.pr_stime ) + DIFF_MS( pStart, pStop, mpstatus.pr_cstime );
131 aProfile += Pad( String::CreateFromInt64(d_utime), 7 );
132 aProfile += Pad( String::CreateFromInt64(d_stime), 7 );
133 aProfile += Pad( String::CreateFromInt64(d_utime + d_stime), 7 );
135 return aProfile;