| author | Matthew Khouzam | 2012-04-10 15:54:44 (EDT) |
|---|---|---|
| committer | Francois Chouinard | 2012-04-16 14:20:03 (EDT) |
| commit | f61e1b03d280a1f7b634db545c315b655d955a12 (patch) (side-by-side diff) | |
| tree | 2112485fb954aa67719e27c6387de16778396515 | |
| parent | 200ad02b0211ee13abbca3a2e28c965233625a17 (diff) | |
| download | org.eclipse.linuxtools-f61e1b03d280a1f7b634db545c315b655d955a12.zip org.eclipse.linuxtools-f61e1b03d280a1f7b634db545c315b655d955a12.tar.gz org.eclipse.linuxtools-f61e1b03d280a1f7b634db545c315b655d955a12.tar.bz2 | |
Change output of ctf toStrings to be more human readable.
4 files changed, 219 insertions, 0 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java new file mode 100644 index 0000000..7ebfd0b --- a/dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2009 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * William Bourque (wbourque@gmail.com) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless; + +import java.util.Vector; + +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; +import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; +import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; + +@SuppressWarnings("nls") +public class RequestBenchmark extends TmfEventRequest<CtfTmfEvent> { + + @SuppressWarnings("unchecked") + public RequestBenchmark(Class<? extends ITmfEvent> dataType, + TmfTimeRange range, int nbRequested) { + super((Class<CtfTmfEvent>) dataType, range, nbRequested, 1); + } + + // Path of the trace + public static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m1"; + + // *** Change this to run several time over the same trace + public static final int NB_OF_PASS = 100; + + // *** Change this to true to parse all the events in the trace + // Otherwise, events are just read + public final boolean PARSE_EVENTS = true; + + // Work variables + public static int nbEvent = 0; + public static int nbPassDone = 0; + public static TmfExperiment<CtfTmfEvent> fExperiment = null; + public static Vector<Double> benchs = new Vector<Double>(); + + public static void main(String[] args) { + + try { + // OUr experiment will contains ONE trace + @SuppressWarnings("unchecked") + ITmfTrace<CtfTmfEvent>[] traces = new ITmfTrace[1]; + traces[0] = new CtfTmfTrace(); + traces[0].initTrace("CtfTrace", TRACE_PATH, CtfTmfEvent.class); + // Create our new experiment + fExperiment = new TmfExperiment<CtfTmfEvent>(CtfTmfEvent.class, + "Headless", traces); + + // Create a new time range from -infinity to +infinity + // That way, we will get "everything" in the trace + CtfTmfTimestamp ts1 = new CtfTmfTimestamp(Long.MIN_VALUE, + (CtfTmfTrace) traces[0]); + CtfTmfTimestamp ts2 = new CtfTmfTimestamp(Long.MAX_VALUE, + (CtfTmfTrace) traces[0]); + TmfTimeRange tmpRange = new TmfTimeRange(ts1, ts2); + + // We will issue a request for each "pass". + // TMF will then process them synchonously + RequestBenchmark request = null; + for (int x = 0; x < NB_OF_PASS; x++) { + request = new RequestBenchmark(CtfTmfEvent.class, tmpRange, + Integer.MAX_VALUE); + fExperiment.sendRequest(request); + nbPassDone++; + } + prev = System.nanoTime(); + } catch (NullPointerException e) { + // Silently dismiss Null pointer exception + // The only way to "finish" the threads in TMF is by crashing them + // with null + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Override + public void handleData(CtfTmfEvent event) { + super.handleData(event); + nbEvent++; + + } + + static long prev; + static long done = 0; + @Override + public void handleCompleted() { + long next = System.nanoTime(); + double val = next - prev; + int nbEvent2 = nbEvent; + val /= nbEvent2; + + nbEvent = 0; + prev = next; + benchs.add(val); + if (benchs.size() == NB_OF_PASS) { + try { + System.out.println("Nb events : " + nbEvent2); + + for (double value : benchs) { + System.out.print(value + ", "); + } + fExperiment.sendRequest(null); + + } catch (Exception e) { + } + } + } + + @Override + public void handleSuccess() { + } + + @Override + public void handleFailure() { + } + + @Override + public void handleCancel() { + } + +} diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContent.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContent.java new file mode 100644 index 0000000..0053197 --- a/dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContent.java @@ -0,0 +1,29 @@ +package org.eclipse.linuxtools.tmf.core.ctfadaptor; + +import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; +import org.eclipse.linuxtools.tmf.core.event.TmfEventField; + +public class CtfTmfContent extends TmfEventField { + + public CtfTmfContent(String name, ITmfEventField[] fields) { + super(name, fields); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder retVal = new StringBuilder(); + for( ITmfEventField field : getFields()) { + retVal.append(field.getName()); + retVal.append(':'); + retVal.append(field.getValue()); + retVal.append(' '); + retVal.append('\t'); + } + return retVal.toString(); + } +} diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventType.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventType.java new file mode 100644 index 0000000..612abc0 --- a/dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventType.java @@ -0,0 +1,18 @@ +package org.eclipse.linuxtools.tmf.core.ctfadaptor; + +import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; +import org.eclipse.linuxtools.tmf.core.event.TmfEventType; + +public class CtfTmfEventType extends TmfEventType { + + public CtfTmfEventType(String contextId, String eventName, + ITmfEventField content) { + super(contextId, eventName, content); + } + + @Override + public String toString() + { + return this.getName(); + } +} diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java new file mode 100644 index 0000000..276d99d --- a/dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java @@ -0,0 +1,37 @@ +package org.eclipse.linuxtools.tmf.core.ctfadaptor; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; + +public class CtfTmfTimestamp extends TmfTimestamp implements ITmfTimestamp { + + final private CtfTmfTrace fTrace; + + public CtfTmfTimestamp(long timestamp, CtfTmfTrace trace) { + fTrace = trace; + fValue = timestamp; + fScale = (byte) -9; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + final long timestamp = fValue; + final Date d = new Date(timestamp / 1000000); + final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$ + final long nanos = (timestamp % 1000000000); + StringBuilder output = new StringBuilder(); + output.append(df.format(d)); + output.append(String.format("%09d", nanos)); //$NON-NLS-1$ + return output.toString(); + } + +} |

