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