lttng: Move to Java 7 and fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / headless / GenerateTestValues.java
1 /*******************************************************************************
2 * Copyright (c) 2013 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.headless;
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.tmf.core.interval.ITmfStateInterval;
22 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
23 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
24 import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory;
25 import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
26 import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
27
28 /**
29 * Small program to regenerate the values used in "TestValues.java" from the
30 * current LTTng-kernel state provider.
31 *
32 * It will write its output the a file called 'TestValues<something>.java' in your
33 * temporary files directory.
34 *
35 * @author Alexandre Montplaisir
36 */
37 public class GenerateTestValues {
38
39 private static CtfTmfTestTrace testTrace = CtfTmfTestTrace.TRACE2;
40 private static final long targetTimestamp = 18670067372290L + 1331649577946812237L;
41 private static final String INDENT = " ";
42
43 /**
44 * Run the program
45 *
46 * @param args
47 * Command-line arguments, unused.
48 * @throws Exception
49 * I'm messing with Exception. Come at me bro!
50 */
51 public static void main(String[] args) throws Exception {
52 if (!testTrace.exists()) {
53 System.err.println("Trace files not present.");
54 return;
55 }
56
57 /* Prepare the files */
58 File stateFile = File.createTempFile("test-values", ".ht");
59 stateFile.deleteOnExit();
60 File logFile = File.createTempFile("TestValues", ".java");
61 try (PrintWriter writer = new PrintWriter(new FileWriter(logFile), true);) {
62
63 /* Build and query the state system */
64 ITmfStateProvider input = new LttngKernelStateProvider(testTrace.getTrace());
65 ITmfStateSystem ssq = TmfStateSystemFactory.newFullHistory(stateFile, input, true);
66 List<ITmfStateInterval> fullState = ssq.queryFullState(targetTimestamp);
67
68 /* Start printing the java file's contents */
69 writer.println("interface TestValues {");
70 writer.println();
71 writer.println(INDENT + "static final int size = " + fullState.size() + ";");
72 writer.println();
73
74 /* Print the array contents */
75 writer.println(INDENT + "static final long[] startTimes = {");
76 for (ITmfStateInterval interval : fullState) {
77 writer.println(INDENT + INDENT + String.valueOf(interval.getStartTime()) + "L,");
78 }
79 writer.println(INDENT + "};");
80 writer.println();
81
82 writer.println(INDENT + "static final long[] endTimes = {");
83 for (ITmfStateInterval interval : fullState) {
84 writer.println(INDENT + INDENT + String.valueOf(interval.getEndTime()) + "L,");
85 }
86 writer.println(INDENT + "};");
87 writer.println();
88
89 writer.println(INDENT + "static final ITmfStateValue[] values = {");
90 for (ITmfStateInterval interval : fullState) {
91 ITmfStateValue val = interval.getStateValue();
92 writer.print(INDENT + INDENT);
93
94 switch (val.getType()) {
95 case NULL:
96 writer.println("TmfStateValue.nullValue(),");
97 break;
98 case INTEGER:
99 writer.println("TmfStateValue.newValueInt(" + val.unboxInt() + "),");
100 break;
101 case LONG:
102 writer.println("TmfStateValue.newValueLong(" + val.unboxLong() + "),");
103 break;
104 case DOUBLE:
105 writer.println("TmfStateValue.newValueDouble(" + val.unboxDouble() + "),");
106 break;
107 case STRING:
108 writer.println("TmfStateValue.newValueString(\"" + val.unboxStr() + "\"),");
109 break;
110 default:
111 writer.println(val.toString());
112 break;
113 }
114 }
115 writer.println(INDENT + "};");
116
117 writer.println("}");
118 writer.println();
119
120 }
121 System.exit(0);
122 }
123
124 }
This page took 0.034716 seconds and 5 git commands to generate.