KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
12 package org.eclipse.test.internal.performance;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.List JavaDoc;
17 import org.eclipse.test.internal.performance.data.DataPoint;
18 import org.eclipse.test.internal.performance.data.Sample;
19
20
21 /**
22  * Performance meter that makes its measurements with OS functionality.
23  */

24 public class OSPerformanceMeter extends InternalPerformanceMeter {
25
26     private PerformanceMonitor fPerformanceMonitor;
27     private long fStartTime;
28     private List JavaDoc fDataPoints= new ArrayList JavaDoc();
29     
30     /**
31      * @param scenarioId the scenario id
32      */

33     public OSPerformanceMeter(String JavaDoc scenarioId) {
34         super(scenarioId);
35         fPerformanceMonitor= PerformanceMonitor.getPerformanceMonitor();
36         fStartTime= System.currentTimeMillis();
37     }
38     
39     /*
40      * @see org.eclipse.test.performance.PerformanceMeter#dispose()
41      */

42     public void dispose() {
43         fPerformanceMonitor= null;
44         fDataPoints= null;
45         super.dispose();
46     }
47
48     /*
49      * @see org.eclipse.test.performance.PerformanceMeter#start()
50      */

51     public void start() {
52         snapshot(BEFORE);
53     }
54     
55     /*
56      * @see org.eclipse.test.performance.PerformanceMeter#stop()
57      */

58     public void stop() {
59         snapshot(AFTER);
60     }
61     
62     /*
63      * @see org.eclipse.test.internal.performance.InternalPerformanceMeter#getSample()
64      */

65     public Sample getSample() {
66         if (fDataPoints != null) {
67             HashMap JavaDoc runProperties= new HashMap JavaDoc();
68             collectRunInfo(runProperties);
69             return new Sample(getScenarioName(), fStartTime, runProperties, (DataPoint[]) fDataPoints.toArray(new DataPoint[fDataPoints.size()]));
70         }
71         return null;
72     }
73     
74     //---- private stuff ------
75

76     private void snapshot(int step) {
77         HashMap JavaDoc map= new HashMap JavaDoc();
78         fPerformanceMonitor.collectOperatingSystemCounters(map);
79         fDataPoints.add(new DataPoint(step, map));
80     }
81
82     /**
83      * Write out the run element if it hasn't been written out yet.
84      * @param runProperties
85      */

86     private void collectRunInfo(HashMap JavaDoc runProperties) {
87         fPerformanceMonitor.collectGlobalPerformanceInfo(runProperties);
88     }
89 }
90
Popular Tags