KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > internal > performance > tests > TestPerformanceMeter


1 /*******************************************************************************
2  * Copyright (c) 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.tests;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.eclipse.test.internal.performance.InternalPerformanceMeter;
20 import org.eclipse.test.internal.performance.data.DataPoint;
21 import org.eclipse.test.internal.performance.data.Dim;
22 import org.eclipse.test.internal.performance.data.Sample;
23 import org.eclipse.test.internal.performance.data.Scalar;
24
25
26 /**
27  * Mock performance meter that generates deterministic values for two dimensions.
28  */

29 class TestPerformanceMeter extends InternalPerformanceMeter {
30         
31     private long fStartTime;
32     private List JavaDoc fDataPoints= new ArrayList JavaDoc();
33     private Map JavaDoc fStart= new HashMap JavaDoc();
34     private Map JavaDoc fStop= new HashMap JavaDoc();
35     
36     /**
37      * @param scenarioId the scenario id
38      */

39     TestPerformanceMeter(String JavaDoc scenarioId) {
40         super(scenarioId);
41         fStartTime= System.currentTimeMillis();
42     }
43         
44     void addPair(Dim dimension, long start, long end) {
45         fStart.put(dimension, new Scalar(dimension, start));
46         fStop.put(dimension, new Scalar(dimension, end));
47     }
48     
49     /*
50      * @see org.eclipse.test.performance.PerformanceMeter#dispose()
51      */

52     public void dispose() {
53         fDataPoints= null;
54         super.dispose();
55     }
56
57     /*
58      * @see org.eclipse.test.internal.performance.InternalPerformanceMeter#getSample()
59      */

60     public Sample getSample() {
61         if (fDataPoints != null)
62             return new Sample(getScenarioName(), fStartTime, new HashMap JavaDoc(), (DataPoint[]) fDataPoints.toArray(new DataPoint[fDataPoints.size()]));
63         return null;
64     }
65     
66     /*
67      * @see org.eclipse.test.performance.PerformanceMeter#start()
68      */

69     public void start() {
70         fDataPoints.add(new DataPoint(BEFORE, fStart));
71     }
72         
73     /*
74      * @see org.eclipse.test.performance.PerformanceMeter#stop()
75      */

76     public void stop() {
77         fDataPoints.add(new DataPoint(AFTER, fStop));
78     }
79 }
80
Popular Tags