~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2012 Ericsson
 
3
 *
 
4
 * All rights reserved. This program and the accompanying materials are
 
5
 * made available under the terms of the Eclipse Public License v1.0 which
 
6
 * accompanies this distribution, and is available at
 
7
 * http://www.eclipse.org/legal/epl-v10.html
 
8
 *
 
9
 * Contributors:
 
10
 *   Matthew Khouzam - Initial API and implementation
 
11
 *******************************************************************************/
 
12
package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless;
 
13
 
 
14
import java.util.Vector;
 
15
 
 
16
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
 
17
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
 
18
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
 
19
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 
20
 
 
21
public class Benchmark {
 
22
 
 
23
    /**
 
24
     * @param args
 
25
     */
 
26
    @SuppressWarnings("nls")
 
27
    public static void main(final String[] args) {
 
28
        final String TRACE_PATH = "testfiles/kernel";
 
29
        final int NUM_LOOPS = 100;
 
30
 
 
31
        // Change this to enable text output
 
32
        final boolean USE_TEXT = true;
 
33
 
 
34
//        try {
 
35
//            System.in.read();
 
36
//        } catch (final IOException e1) {
 
37
//            e1.printStackTrace();
 
38
//        }
 
39
        // Work variables
 
40
        Long nbEvent = 0L;
 
41
        final Vector<Double> benchs = new Vector<Double>();
 
42
        CtfTmfTrace trace = null;
 
43
        long start, stop;
 
44
        for (int loops = 0; loops < NUM_LOOPS; loops++) {
 
45
            nbEvent = 0L;
 
46
            trace = new CtfTmfTrace();
 
47
            try {
 
48
                trace.initTrace(null, TRACE_PATH, CtfTmfEvent.class);
 
49
            } catch (final TmfTraceException e) {
 
50
                loops = NUM_LOOPS +1;
 
51
                break;
 
52
            }
 
53
 
 
54
            start = System.nanoTime();
 
55
            if (nbEvent != -1) {
 
56
                final CtfIterator traceReader = (CtfIterator) trace.seekEvent(0);
 
57
 
 
58
                start = System.nanoTime();
 
59
                CtfTmfEvent current = traceReader.getCurrentEvent();
 
60
                while (current != null) {
 
61
                    nbEvent++;
 
62
                    if (USE_TEXT) {
 
63
 
 
64
                        System.out.println("Event " + traceReader.getRank() + " Time "
 
65
                                + current.getTimestamp().toString() + " type " + current.getEventName()
 
66
                                + " on CPU " + current.getSource() + " " + current.getContent().toString()) ;
 
67
                    }
 
68
                    traceReader.advance();
 
69
                    current = traceReader.getCurrentEvent();
 
70
                }
 
71
            }
 
72
            stop = System.nanoTime();
 
73
            System.out.print('.');
 
74
            final double time = (stop - start) / (double) nbEvent;
 
75
            benchs.add(time);
 
76
        }
 
77
        System.out.println("");
 
78
        double avg = 0;
 
79
        for (final Double val : benchs) {
 
80
            avg += val;
 
81
        }
 
82
        avg /= benchs.size();
 
83
        System.out.println("Time to read = " + avg + " events/ns");
 
84
        for (final Double val : benchs) {
 
85
            System.out.print(val);
 
86
            System.out.print(", ");
 
87
        }
 
88
 
 
89
    }
 
90
 
 
91
//    /**
 
92
//     * @param timestamp
 
93
//     *            the timestamp in UTC to convert to nanoseconds.
 
94
//     * @return formatted string.
 
95
//     */
 
96
//    private static String formatDate(final long timestamp) {
 
97
//        final Date d = new Date(timestamp / 1000000);
 
98
//        final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$
 
99
//        final String output = df.format(d) + (timestamp % 1000000000);
 
100
//        return output;
 
101
//    }
 
102
 
 
103
}