KickJava   Java API By Example, From Geeks To Geeks.

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


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.data.Dim;
16 import org.eclipse.test.internal.performance.data.Scalar;
17
18
19 class PerformanceMonitor {
20     
21     private static PerformanceMonitor fgPerformanceMonitor;
22
23     public static PerformanceMonitor getPerformanceMonitor() {
24         if (fgPerformanceMonitor == null) {
25             String JavaDoc os= System.getProperty("os.name"); //$NON-NLS-1$
26
if (os.startsWith("Windows")) //$NON-NLS-1$
27
fgPerformanceMonitor= new PerformanceMonitorWindows();
28             else if (os.startsWith("Mac OS X")) //$NON-NLS-1$
29
fgPerformanceMonitor= new PerformanceMonitorMac();
30             else
31                 fgPerformanceMonitor= new PerformanceMonitorLinux();
32         }
33         return fgPerformanceMonitor;
34     }
35
36     protected void collectOperatingSystemCounters(Map JavaDoc scalars) {
37         if (PerformanceTestPlugin.isOldDB()) {
38             addScalar(scalars, InternalDimensions.SYSTEM_TIME, System.currentTimeMillis());
39         } else {
40             Runtime JavaDoc runtime= Runtime.getRuntime();
41             //runtime.gc();
42
addScalar(scalars, InternalDimensions.USED_JAVA_HEAP, runtime.totalMemory() - runtime.freeMemory());
43         }
44     }
45
46     protected void collectGlobalPerformanceInfo(Map JavaDoc scalars) {
47         // no default implementation
48
}
49     
50     void addScalar(Map JavaDoc scalars, Dim dimension, long value) {
51         scalars.put(dimension, new Scalar(dimension, value));
52     }
53 }
54
Popular Tags