a63ca7fba94dc190c580e5d379b93c00f187e2b0
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / tracecompass / lttng2 / kernel / core / tests / analysis / kernel / statesystem / GenerateTestValues.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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.tracecompass.lttng2.kernel.core.tests.analysis.kernel.statesystem;
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.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
21 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
22 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
23 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
24 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
25 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
26 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
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 logFile = File.createTempFile("TestValues", ".java");
59 try (final CtfTmfTrace trace = testTrace.getTrace();
60 PrintWriter writer = new PrintWriter(new FileWriter(logFile), true);) {
61
62 /* Build and query the state system */
63 TmfStateSystemAnalysisModule module = new KernelAnalysisModule() {
64 @Override
65 protected String getSsFileName() {
66 return "test-values";
67 }
68 };
69
70 if (!module.setTrace(trace)) {
71 throw new IllegalStateException();
72 }
73 module.setId("test-values");
74 module.schedule();
75 module.waitForCompletion();
76 ITmfStateSystem ssq = module.getStateSystem();
77 if (ssq == null) {
78 throw new IllegalStateException();
79 }
80
81 List<ITmfStateInterval> fullState = ssq.queryFullState(targetTimestamp);
82
83 /* Start printing the java file's contents */
84 writer.println("interface TestValues {");
85 writer.println();
86 writer.println(INDENT + "int size = " + fullState.size() + ";");
87 writer.println();
88
89 /* Print the array contents */
90 writer.println(INDENT + "long[] startTimes = {");
91 for (ITmfStateInterval interval : fullState) {
92 writer.println(INDENT + INDENT + String.valueOf(interval.getStartTime()) + "L,");
93 }
94 writer.println(INDENT + "};");
95 writer.println();
96
97 writer.println(INDENT + "long[] endTimes = {");
98 for (ITmfStateInterval interval : fullState) {
99 writer.println(INDENT + INDENT + String.valueOf(interval.getEndTime()) + "L,");
100 }
101 writer.println(INDENT + "};");
102 writer.println();
103
104 writer.println(INDENT + "ITmfStateValue[] values = {");
105 for (ITmfStateInterval interval : fullState) {
106 ITmfStateValue val = interval.getStateValue();
107 writer.print(INDENT + INDENT);
108
109 switch (val.getType()) {
110 case NULL:
111 writer.println("TmfStateValue.nullValue(),");
112 break;
113 case INTEGER:
114 writer.println("TmfStateValue.newValueInt(" + val.unboxInt() + "),");
115 break;
116 case LONG:
117 writer.println("TmfStateValue.newValueLong(" + val.unboxLong() + "),");
118 break;
119 case DOUBLE:
120 writer.println("TmfStateValue.newValueDouble(" + val.unboxDouble() + "),");
121 break;
122 case STRING:
123 writer.println("TmfStateValue.newValueString(\"" + val.unboxStr() + "\"),");
124 break;
125 default:
126 writer.println(val.toString());
127 break;
128 }
129 }
130 writer.println(INDENT + "};");
131
132 writer.println("}");
133 writer.println();
134
135 module.dispose();
136 }
137 System.exit(0);
138 }
139
140 }
This page took 0.04944 seconds and 4 git commands to generate.