KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > internal > performance > PerformanceMonitorMac


1 /*******************************************************************************
2  * Copyright (c) 2003, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.test.internal.performance;
12
13 import java.util.Map JavaDoc;
14
15 /**
16  * The Mac OS X version of the performance monitor.
17  * (Uses default implementation for now).
18  */

19 class PerformanceMonitorMac extends PerformanceMonitor {
20
21     private static boolean fgHasElapsedTime= true;
22     private static long fgStartupTime;
23
24     /**
25      * name of the library that implements the native methods.
26      */

27     private static final String JavaDoc NATIVE_LIBRARY_NAME= "perf_3_1_0"; //$NON-NLS-1$
28

29     /**
30      * Is the native library loaded? 0-don't know, 1-no, 2-yes
31      */

32     private static int fgIsLoaded= 0;
33     
34     /**
35      * Answer true if the native library for this class has been successfully
36      * loaded. If the load has not been attempted yet, try to load it.
37      * @return returns true if native library has been successfullz loaded
38      */

39     public static boolean isLoaded() {
40         if (fgIsLoaded == 0) {
41             try {
42                 System.loadLibrary(NATIVE_LIBRARY_NAME);
43                 fgIsLoaded= 2;
44             } catch (Throwable JavaDoc e) {
45                 //e.printStackTrace();
46
//PerformanceTestPlugin.log(e);
47
fgIsLoaded= 1;
48             }
49         }
50         return fgIsLoaded == 2;
51     }
52     
53     
54     /**
55      * Write out operating system counters for Mac OS X.
56      * @param scalars where to collect the data
57      */

58     protected void collectOperatingSystemCounters(Map JavaDoc scalars) {
59         synchronized(this) {
60             if (isLoaded()) {
61                 int[] counters= new int[18];
62                 if (getrusage(0, counters) == 0) {
63                     
64                     int user_time= counters[0]*1000 + counters[1]/1000;
65                     int kernel_time= counters[2]*1000 + counters[3]/1000;
66                     
67                     addScalar(scalars, InternalDimensions.KERNEL_TIME, kernel_time);
68                     addScalar(scalars, InternalDimensions.CPU_TIME, user_time + kernel_time);
69                 }
70             }
71             
72             long currentTime= System.currentTimeMillis();
73             if (!PerformanceTestPlugin.isOldDB())
74                 addScalar(scalars, InternalDimensions.SYSTEM_TIME, currentTime);
75             
76             if (fgHasElapsedTime) {
77                 if (fgStartupTime == 0) {
78                     String JavaDoc t= System.getProperty("eclipse.startTime"); //$NON-NLS-1$
79
if (t != null) {
80                         try {
81                             fgStartupTime= Long.parseLong(t);
82                         } catch (NumberFormatException JavaDoc e) {
83                             fgHasElapsedTime= false;
84                         }
85                     } else
86                         fgHasElapsedTime= false;
87                 }
88                 if (fgHasElapsedTime)
89                     addScalar(scalars, InternalDimensions.ELAPSED_PROCESS, currentTime-fgStartupTime);
90             }
91             
92             super.collectOperatingSystemCounters(scalars);
93         }
94     }
95
96 // struct rusage {
97
// 0,1 struct timeval ru_utime; /* user time used */
98
// 2,3 struct timeval ru_stime; /* system time used */
99
// 4 long ru_maxrss; /* integral max resident set size */
100
// 5 long ru_ixrss; /* integral shared text memory size */
101
// 6 long ru_idrss; /* integral unshared data size */
102
// 7 long ru_isrss; /* integral unshared stack size */
103
// 8 long ru_minflt; /* page reclaims */
104
// 9 long ru_majflt; /* page faults */
105
// 10 long ru_nswap; /* swaps */
106
// 11 long ru_inblock; /* block input operations */
107
// 12 long ru_oublock; /* block output operations */
108
// 13 long ru_msgsnd; /* messages sent */
109
// 14 long ru_msgrcv; /* messages received */
110
// 15 long ru_nsignals; /* signals received */
111
// 16 long ru_nvcsw; /* voluntary context switches */
112
// 17 long ru_nivcsw; /* involuntary context switches */
113
// };
114
private static native int getrusage(int who, int[] counters);
115 }
116
Popular Tags