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