~ubuntu-branches/ubuntu/vivid/eclipse-linuxtools/vivid-proposed

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/GenerateTestValues.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2013, 2014 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
 *   Alexandre Montplaisir - Initial API and implementation
 
11
 ******************************************************************************/
 
12
 
 
13
package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
 
14
 
 
15
import java.io.File;
 
16
import java.io.FileWriter;
 
17
import java.io.PrintWriter;
 
18
import java.util.List;
 
19
 
 
20
import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
 
21
import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
 
22
import org.eclipse.linuxtools.statesystem.core.interval.ITmfStateInterval;
 
23
import org.eclipse.linuxtools.statesystem.core.statevalue.ITmfStateValue;
 
24
import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
 
25
import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 
26
import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
 
27
import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
 
28
 
 
29
/**
 
30
 * Small program to regenerate the values used in "TestValues.java" from the
 
31
 * current LTTng-kernel state provider.
 
32
 *
 
33
 * It will write its output the a file called 'TestValues<something>.java' in your
 
34
 * temporary files directory.
 
35
 *
 
36
 * @author Alexandre Montplaisir
 
37
 */
 
38
public class GenerateTestValues {
 
39
 
 
40
    private static CtfTmfTestTrace testTrace = CtfTmfTestTrace.TRACE2;
 
41
    private static final long targetTimestamp = 18670067372290L + 1331649577946812237L;
 
42
    private static final String INDENT = "    ";
 
43
 
 
44
    /**
 
45
     * Run the program
 
46
     *
 
47
     * @param args
 
48
     *            Command-line arguments, unused.
 
49
     * @throws Exception
 
50
     *             I'm messing with Exception. Come at me bro!
 
51
     */
 
52
    public static void main(String[] args) throws Exception {
 
53
        if (!testTrace.exists()) {
 
54
            System.err.println("Trace files not present.");
 
55
            return;
 
56
        }
 
57
 
 
58
        /* Prepare the files */
 
59
        File logFile = File.createTempFile("TestValues", ".java");
 
60
        try (final CtfTmfTrace trace = testTrace.getTrace();
 
61
                PrintWriter writer = new PrintWriter(new FileWriter(logFile), true);
 
62
                /* Build and query the state system */
 
63
                TmfStateSystemAnalysisModule module = new TmfStateSystemAnalysisModule() {
 
64
                    @Override
 
65
                    protected ITmfStateProvider createStateProvider() {
 
66
                        return new LttngKernelStateProvider(trace);
 
67
                    }
 
68
 
 
69
                    @Override
 
70
                    protected String getSsFileName() {
 
71
                        return "test-values";
 
72
                    }
 
73
                };) {
 
74
            module.setTrace(trace);
 
75
            module.setId("test-values");
 
76
            module.schedule();
 
77
            module.waitForCompletion();
 
78
            ITmfStateSystem ssq = module.getStateSystem();
 
79
            if (ssq == null) {
 
80
                throw new IllegalStateException();
 
81
            }
 
82
 
 
83
            List<ITmfStateInterval> fullState = ssq.queryFullState(targetTimestamp);
 
84
 
 
85
            /* Start printing the java file's contents */
 
86
            writer.println("interface TestValues {");
 
87
            writer.println();
 
88
            writer.println(INDENT + "static final int size = " + fullState.size() + ";");
 
89
            writer.println();
 
90
 
 
91
            /* Print the array contents */
 
92
            writer.println(INDENT + "static final long[] startTimes = {");
 
93
            for (ITmfStateInterval interval : fullState) {
 
94
                writer.println(INDENT + INDENT + String.valueOf(interval.getStartTime()) + "L,");
 
95
            }
 
96
            writer.println(INDENT + "};");
 
97
            writer.println();
 
98
 
 
99
            writer.println(INDENT + "static final long[] endTimes = {");
 
100
            for (ITmfStateInterval interval : fullState) {
 
101
                writer.println(INDENT + INDENT + String.valueOf(interval.getEndTime()) + "L,");
 
102
            }
 
103
            writer.println(INDENT + "};");
 
104
            writer.println();
 
105
 
 
106
            writer.println(INDENT + "static final ITmfStateValue[] values = {");
 
107
            for (ITmfStateInterval interval : fullState) {
 
108
                ITmfStateValue val = interval.getStateValue();
 
109
                writer.print(INDENT + INDENT);
 
110
 
 
111
                switch (val.getType()) {
 
112
                case NULL:
 
113
                    writer.println("TmfStateValue.nullValue(),");
 
114
                    break;
 
115
                case INTEGER:
 
116
                    writer.println("TmfStateValue.newValueInt(" + val.unboxInt() + "),");
 
117
                    break;
 
118
                case LONG:
 
119
                    writer.println("TmfStateValue.newValueLong(" + val.unboxLong() + "),");
 
120
                    break;
 
121
                case DOUBLE:
 
122
                    writer.println("TmfStateValue.newValueDouble(" + val.unboxDouble() + "),");
 
123
                    break;
 
124
                case STRING:
 
125
                    writer.println("TmfStateValue.newValueString(\"" + val.unboxStr() + "\"),");
 
126
                    break;
 
127
                default:
 
128
                    writer.println(val.toString());
 
129
                    break;
 
130
                }
 
131
            }
 
132
            writer.println(INDENT + "};");
 
133
 
 
134
            writer.println("}");
 
135
            writer.println();
 
136
 
 
137
        }
 
138
        System.exit(0);
 
139
    }
 
140
 
 
141
}