1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.ctfadaptor
.headless
;
14 import java
.io
.FileNotFoundException
;
15 import java
.io
.IOException
;
16 import java
.text
.DateFormat
;
17 import java
.text
.SimpleDateFormat
;
18 import java
.util
.Date
;
19 import java
.util
.Vector
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfIterator
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
25 public class Benchmark
{
30 @SuppressWarnings("nls")
31 public static void main(String
[] args
) {
32 final String TRACE_PATH
= "../org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m1";
33 final int NUM_LOOPS
= 100;
35 // Change this to enable text output
36 final boolean USE_TEXT
= false;
40 } catch (IOException e1
) {
45 Vector
<Double
> benchs
= new Vector
<Double
>();
46 CtfTmfTrace trace
= null;
48 for (int loops
= 0; loops
< NUM_LOOPS
; loops
++) {
50 trace
= new CtfTmfTrace();
52 trace
.initTrace("Test", TRACE_PATH
, CtfTmfEvent
.class);
53 } catch (FileNotFoundException e
) {
58 start
= System
.nanoTime();
60 CtfIterator traceReader
= (CtfIterator
) trace
.seekEvent(0);
62 start
= System
.nanoTime();
63 CtfTmfEvent current
= traceReader
.getCurrentEvent();
64 while (current
!= null) {
67 String output
= formatDate(current
.getTimestampValue());
68 System
.out
.println("Event " + traceReader
.getRank() + " Time "
69 + output
+ " type " + current
.getSource()
70 + " on CPU " + current
.getCPU());
72 traceReader
.advance();
73 current
= traceReader
.getCurrentEvent();
76 stop
= System
.nanoTime();
77 System
.out
.print('.');
78 double time
= (stop
- start
) / (double) nbEvent
;
81 System
.out
.println("");
83 for (Double val
: benchs
) {
87 System
.out
.println("Time to read = " + avg
+ " events/ns");
88 for (Double val
: benchs
) {
89 System
.out
.print(val
);
90 System
.out
.print(", ");
97 * the timestamp in UTC to convert to nanoseconds.
98 * @return formatted string.
100 private static String
formatDate(long timestamp
) {
101 Date d
= new Date(timestamp
/ 1000000);
102 DateFormat df
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$
103 String output
= df
.format(d
) + (timestamp
% 1000000000);
This page took 0.033594 seconds and 6 git commands to generate.