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 | ||
6d16f5a9 | 20 | import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule; |
e894a508 AM |
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; | |
2bdf0193 | 24 | import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule; |
2bdf0193 | 25 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
9722e5d7 | 26 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
b33f7554 AM |
27 | |
28 | /** | |
29 | * Small program to regenerate the values used in "TestValues.java" from the | |
30 | * current LTTng-kernel state provider. | |
31 | * | |
01e6a579 | 32 | * It will write its output the a file called 'TestValues<something>.java' in your |
b33f7554 AM |
33 | * temporary files directory. |
34 | * | |
35 | * @author Alexandre Montplaisir | |
36 | */ | |
b33f7554 AM |
37 | public class GenerateTestValues { |
38 | ||
9ac63b5b | 39 | private static CtfTmfTestTrace testTrace = CtfTmfTestTrace.TRACE2; |
b33f7554 | 40 | private static final long targetTimestamp = 18670067372290L + 1331649577946812237L; |
01e6a579 | 41 | private static final String INDENT = " "; |
b33f7554 AM |
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 { | |
9ac63b5b | 52 | if (!testTrace.exists()) { |
b33f7554 AM |
53 | System.err.println("Trace files not present."); |
54 | return; | |
55 | } | |
56 | ||
57 | /* Prepare the files */ | |
01e6a579 | 58 | File logFile = File.createTempFile("TestValues", ".java"); |
0ff9e595 | 59 | try (PrintWriter writer = new PrintWriter(new FileWriter(logFile), true);) { |
03f0b0b1 AM |
60 | |
61 | /* Build and query the state system */ | |
0ff9e595 | 62 | final CtfTmfTrace trace = testTrace.getTrace(); |
6d16f5a9 | 63 | TmfStateSystemAnalysisModule module = new KernelAnalysisModule() { |
03f0b0b1 AM |
64 | @Override |
65 | protected String getSsFileName() { | |
66 | return "test-values"; | |
67 | } | |
68 | }; | |
69 | ||
f479550c GB |
70 | if (!module.setTrace(trace)) { |
71 | throw new IllegalStateException(); | |
72 | } | |
e9504bf6 AM |
73 | module.setId("test-values"); |
74 | module.schedule(); | |
75 | module.waitForCompletion(); | |
76 | ITmfStateSystem ssq = module.getStateSystem(); | |
c1831960 AM |
77 | if (ssq == null) { |
78 | throw new IllegalStateException(); | |
79 | } | |
e9504bf6 | 80 | |
e0838ca1 AM |
81 | List<ITmfStateInterval> fullState = ssq.queryFullState(targetTimestamp); |
82 | ||
83 | /* Start printing the java file's contents */ | |
84 | writer.println("interface TestValues {"); | |
85 | writer.println(); | |
8356c9fe | 86 | writer.println(INDENT + "int size = " + fullState.size() + ";"); |
e0838ca1 AM |
87 | writer.println(); |
88 | ||
89 | /* Print the array contents */ | |
8356c9fe | 90 | writer.println(INDENT + "long[] startTimes = {"); |
e0838ca1 AM |
91 | for (ITmfStateInterval interval : fullState) { |
92 | writer.println(INDENT + INDENT + String.valueOf(interval.getStartTime()) + "L,"); | |
93 | } | |
94 | writer.println(INDENT + "};"); | |
95 | writer.println(); | |
b33f7554 | 96 | |
8356c9fe | 97 | writer.println(INDENT + "long[] endTimes = {"); |
e0838ca1 AM |
98 | for (ITmfStateInterval interval : fullState) { |
99 | writer.println(INDENT + INDENT + String.valueOf(interval.getEndTime()) + "L,"); | |
b33f7554 | 100 | } |
e0838ca1 AM |
101 | writer.println(INDENT + "};"); |
102 | writer.println(); | |
103 | ||
8356c9fe | 104 | writer.println(INDENT + "ITmfStateValue[] values = {"); |
e0838ca1 AM |
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 + "};"); | |
01e6a579 | 131 | |
e0838ca1 AM |
132 | writer.println("}"); |
133 | writer.println(); | |
b33f7554 | 134 | |
03f0b0b1 | 135 | module.dispose(); |
0ff9e595 | 136 | trace.dispose(); |
e0838ca1 | 137 | } |
b33f7554 AM |
138 | System.exit(0); |
139 | } | |
140 | ||
141 | } |