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
.text
.DateFormat
;
15 import java
.text
.SimpleDateFormat
;
16 import java
.util
.Date
;
17 import java
.util
.Vector
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfIterator
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
24 public class Benchmark
{
29 @SuppressWarnings("nls")
30 public static void main(final String
[] args
) {
31 final String TRACE_PATH
= "testfiles/kernel";
32 final int NUM_LOOPS
= 100;
34 // Change this to enable text output
35 final boolean USE_TEXT
= true;
39 // } catch (final IOException e1) {
40 // e1.printStackTrace();
44 final Vector
<Double
> benchs
= new Vector
<Double
>();
45 CtfTmfTrace trace
= null;
47 for (int loops
= 0; loops
< NUM_LOOPS
; loops
++) {
49 trace
= new CtfTmfTrace();
51 trace
.initTrace(null, TRACE_PATH
, CtfTmfEvent
.class);
52 } catch (final TmfTraceException e
) {
57 start
= System
.nanoTime();
59 final CtfIterator traceReader
= (CtfIterator
) trace
.seekEvent(0);
61 start
= System
.nanoTime();
62 CtfTmfEvent current
= traceReader
.getCurrentEvent();
63 while (current
!= null) {
67 System
.out
.println("Event " + traceReader
.getRank() + " Time "
68 + current
.getTimestamp().toString() + " type " + current
.getEventName()
69 + " on CPU " + current
.getSource() + " " + current
.getContent().toString()) ;
71 traceReader
.advance();
72 current
= traceReader
.getCurrentEvent();
75 stop
= System
.nanoTime();
76 System
.out
.print('.');
77 final double time
= (stop
- start
) / (double) nbEvent
;
80 System
.out
.println("");
82 for (final Double val
: benchs
) {
86 System
.out
.println("Time to read = " + avg
+ " events/ns");
87 for (final Double val
: benchs
) {
88 System
.out
.print(val
);
89 System
.out
.print(", ");
96 * the timestamp in UTC to convert to nanoseconds.
97 * @return formatted string.
99 private static String
formatDate(final long timestamp
) {
100 final Date d
= new Date(timestamp
/ 1000000);
101 final DateFormat df
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$
102 final String output
= df
.format(d
) + (timestamp
% 1000000000);
This page took 0.031891 seconds and 5 git commands to generate.