KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.test.internal.performance.PerformanceMonitor;
16
17 /**
18  * The PerformanceMonitor for Windows.
19  */

20 class PerformanceMonitorWindows extends PerformanceMonitor {
21             
22     
23     private boolean fgNativeGetPerformanceInfoNotAvailable;
24
25     protected void collectOperatingSystemCounters(Map JavaDoc scalars) {
26         synchronized(this) {
27             if (org.eclipse.perfmsr.core.PerformanceMonitor.isLoaded()) {
28                 long[] counters= new long[14];
29                 if (org.eclipse.perfmsr.core.PerformanceMonitor.nativeGetPerformanceCounters(counters)) {
30                     addScalar(scalars, InternalDimensions.WORKING_SET, counters[0]);
31                     addScalar(scalars, InternalDimensions.WORKING_SET_PEAK, counters[1]);
32                     addScalar(scalars, InternalDimensions.ELAPSED_PROCESS, counters[2]);
33                     //addScalar(scalars, InternalDimensions.USER_TIME, counters[3]);
34
addScalar(scalars, InternalDimensions.KERNEL_TIME, counters[4]);
35                     addScalar(scalars, InternalDimensions.CPU_TIME, counters[3] + counters[4]);
36                     addScalar(scalars, InternalDimensions.PAGE_FAULTS, counters[5]);
37                     if (counters[6] != -1)
38                         addScalar(scalars, InternalDimensions.COMITTED, counters[6]);
39                     addScalar(scalars, InternalDimensions.GDI_OBJECTS, counters[7]);
40                     //addScalar(scalars, Dimensions.USER_OBJECTS, counters[8]);
41
//if (counters[9] != -1)
42
// addScalar(scalars, InternalDimensions.OPEN_HANDLES, counters[9]);
43
//addScalar(scalars, InternalDimensions.READ_COUNT, counters[10]);
44
//addScalar(scalars, InternalDimensions.WRITE_COUNT, counters[11]);
45
//addScalar(scalars, InternalDimensions.BYTES_READ, counters[12]);
46
//addScalar(scalars, InternalDimensions.BYTES_WRITTEN, counters[13]);
47
}
48             }
49             super.collectOperatingSystemCounters(scalars);
50         }
51     }
52
53     /**
54      * Collect global performance info. This includes things like the total
55      * committed memory for the entire system.
56      *
57      * This function depends on the GetPerformanceInfo() function being available in
58      * the Windows ivjperf.dll. This is available in XP but is usually not available
59      * in Win2000. If it is not available then this function throws an UnsupportedOperationException.
60      * @param scalars
61      */

62     protected void collectGlobalPerformanceInfo(Map JavaDoc scalars) {
63         synchronized(this) {
64             if (!fgNativeGetPerformanceInfoNotAvailable && org.eclipse.perfmsr.core.PerformanceMonitor.isLoaded()) {
65                 long[] counters= new long[13];
66                 try {
67                     org.eclipse.perfmsr.core.PerformanceMonitor.nativeGetPerformanceInfo(counters);
68                     long pageSize= counters[9];
69                     addScalar(scalars, InternalDimensions.COMMIT_TOTAL, counters[0]*pageSize);
70                     addScalar(scalars, InternalDimensions.COMMIT_LIMIT, counters[1]*pageSize);
71                     addScalar(scalars, InternalDimensions.COMMIT_PEAK, counters[2]*pageSize);
72                     addScalar(scalars, InternalDimensions.PHYSICAL_TOTAL, counters[3]*pageSize);
73                     addScalar(scalars, InternalDimensions.PHYSICAL_AVAIL, counters[4]*pageSize);
74                     addScalar(scalars, InternalDimensions.SYSTEM_CACHE, counters[5]*pageSize);
75                     addScalar(scalars, InternalDimensions.KERNEL_TOTAL, counters[6]*pageSize);
76                     addScalar(scalars, InternalDimensions.KERNEL_PAGED, counters[7]*pageSize);
77                     addScalar(scalars, InternalDimensions.KERNEL_NONPAGED, counters[8]*pageSize);
78                     addScalar(scalars, InternalDimensions.PAGE_SIZE, counters[9]);
79                     addScalar(scalars, InternalDimensions.HANDLE_COUNT, counters[10]);
80                     addScalar(scalars, InternalDimensions.PROCESS_COUNT, counters[11]);
81                     addScalar(scalars, InternalDimensions.THREAD_COUNT, counters[12]);
82                 } catch (Exception JavaDoc e) {
83                     PerformanceTestPlugin.logWarning("native function GetPerformanceInfo() not available on this version of Windows"); //$NON-NLS-1$
84
fgNativeGetPerformanceInfoNotAvailable= true;
85                 }
86             }
87             super.collectGlobalPerformanceInfo(scalars);
88         }
89     }
90     
91 // protected String getUUID() {
92
// if (org.eclipse.perfmsr.core.PerformanceMonitor.isLoaded()) {
93
// try {
94
// return org.eclipse.perfmsr.core.PerformanceMonitor.nativeGetUUID();
95
// } catch (Exception e) {
96
// }
97
// }
98
// return super.getUUID();
99
// }
100
}
101
Popular Tags