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

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/headless/LttngTraceTest.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
package org.eclipse.linuxtools.lttng.core.tests.headless;
 
2
/*******************************************************************************
 
3
 * Copyright (c) 2009 Ericsson
 
4
 * 
 
5
 * All rights reserved. This program and the accompanying materials are
 
6
 * made available under the terms of the Eclipse Public License v1.0 which
 
7
 * accompanies this distribution, and is available at
 
8
 * http://www.eclipse.org/legal/epl-v10.html
 
9
 * 
 
10
 * Contributors:
 
11
 *   William Bourque (wbourque@gmail.com) - Initial API and implementation
 
12
 *******************************************************************************/
 
13
 
 
14
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
 
15
import org.eclipse.linuxtools.internal.lttng.core.event.LttngLocation;
 
16
import org.eclipse.linuxtools.internal.lttng.core.event.LttngTimestamp;
 
17
import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTextTrace;
 
18
import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTrace;
 
19
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 
20
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
 
21
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
 
22
 
 
23
 
 
24
@SuppressWarnings("nls")
 
25
public class LttngTraceTest {
 
26
 
 
27
    /**
 
28
     * @param args
 
29
     */
 
30
    public static void main(final String[] args) {
 
31
 
 
32
        // Path of the trace
 
33
        final String TRACE_PATH = "/home/francois/Desktop/Workspaces/LTTngTraces/trace_2GB";
 
34
        // *** Change to true to use the "fake" LttngTextTrace instead of LTTngTrace
 
35
        // To use this, you need a ".txt" trace.
 
36
        // You can get it using LTTv with the command "lttv -m textDump -t /tmp/sometrace > mytrace.txt"
 
37
        final boolean USE_TEXT_TRACE = false;
 
38
 
 
39
        // *** Change this to run several time over the same trace
 
40
        final int NB_OF_PASS = 1;
 
41
 
 
42
        // *** Change this to true to parse all the events in the trace
 
43
        //      Otherwise, events are just read
 
44
        final boolean PARSE_EVENTS = true;
 
45
 
 
46
 
 
47
        // Work variables
 
48
        TmfTrace<LttngEvent> tmptrace = null;
 
49
        LttngEvent tmpevent = null;
 
50
        ITmfContext tmpContext = null;
 
51
        Long nbEvent = 0L;
 
52
 
 
53
        try {
 
54
            // ** Use TextTrace (slow!) if it was asked
 
55
            if ( USE_TEXT_TRACE )
 
56
                tmptrace = new LTTngTextTrace(null, TRACE_PATH, true);
 
57
            else
 
58
                tmptrace = new LTTngTrace(null, TRACE_PATH, null, true, true);
 
59
 
 
60
            final LttngTimestamp tmpTime = new LttngTimestamp(0L);
 
61
            tmpContext = new TmfContext(new LttngLocation(0L), 0);
 
62
 
 
63
 
 
64
            final long startTime = System.nanoTime();
 
65
            System.out.println("Start: " + startTime);
 
66
            for ( int nb=0; nb<NB_OF_PASS; nb++) {
 
67
 
 
68
                // Seek to the beginning of the trace
 
69
                tmpContext = tmptrace.seekEvent( tmpTime  );
 
70
                tmpevent = (LttngEvent)tmptrace.getNext(tmpContext);
 
71
 
 
72
                while ( tmpevent != null ) {
 
73
                    tmpevent = (LttngEvent)tmptrace.getNext(tmpContext);
 
74
 
 
75
                    // Parse the events if it was asked
 
76
                    if ( (tmpevent != null) && (PARSE_EVENTS) )
 
77
                        tmpevent.getContent().getFields();
 
78
 
 
79
                    nbEvent++;
 
80
                }
 
81
            }
 
82
 
 
83
            System.out.println("NB events : " + nbEvent);
 
84
 
 
85
            final long endTime = System.nanoTime();
 
86
            final long elapsed = endTime - startTime;
 
87
            System.out.println("End: " + endTime);
 
88
            System.out.println("Elapsed: " + elapsed + ", Average: " + (elapsed/nbEvent) + "ns/evt");
 
89
 
 
90
        }
 
91
        catch (final Exception e) {
 
92
            e.printStackTrace();
 
93
        }
 
94
 
 
95
    }
 
96
 
 
97
}