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