Commit | Line | Data |
---|---|---|
b33f7554 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 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.linuxtools.lttng2.kernel.core.tests.headless; | |
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; |
b33f7554 | 21 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; |
0fe46f2a | 22 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; |
b33f7554 | 23 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
3f436e7c | 24 | import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory; |
b33f7554 | 25 | import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; |
9ac63b5b | 26 | import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace; |
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 */ | |
58 | File stateFile = File.createTempFile("test-values", ".ht"); | |
59 | stateFile.deleteOnExit(); | |
01e6a579 | 60 | File logFile = File.createTempFile("TestValues", ".java"); |
b33f7554 AM |
61 | PrintWriter writer = new PrintWriter(new FileWriter(logFile), true); |
62 | ||
63 | /* Build and query the state system */ | |
9ac63b5b | 64 | ITmfStateProvider input = new LttngKernelStateProvider(testTrace.getTrace()); |
3f436e7c | 65 | ITmfStateSystem ssq = TmfStateSystemFactory.newFullHistory(stateFile, input, true); |
b33f7554 AM |
66 | List<ITmfStateInterval> fullState = ssq.queryFullState(targetTimestamp); |
67 | ||
01e6a579 AM |
68 | /* Start printing the java file's contents */ |
69 | writer.println("interface TestValues {"); | |
70 | writer.println(); | |
71 | writer.println(INDENT + "static final int size = " + fullState.size() +";"); | |
72 | writer.println(); | |
73 | ||
74 | /* Print the array contents */ | |
75 | writer.println(INDENT + "static final long[] startTimes = {"); | |
b33f7554 | 76 | for (ITmfStateInterval interval : fullState) { |
01e6a579 | 77 | writer.println(INDENT + INDENT + String.valueOf(interval.getStartTime()) + "L,"); |
b33f7554 | 78 | } |
01e6a579 | 79 | writer.println(INDENT + "};"); |
b33f7554 AM |
80 | writer.println(); |
81 | ||
01e6a579 | 82 | writer.println(INDENT + "static final long[] endTimes = {"); |
b33f7554 | 83 | for (ITmfStateInterval interval : fullState) { |
01e6a579 | 84 | writer.println(INDENT + INDENT + String.valueOf(interval.getEndTime())+ "L,"); |
b33f7554 | 85 | } |
01e6a579 | 86 | writer.println(INDENT + "};"); |
b33f7554 AM |
87 | writer.println(); |
88 | ||
01e6a579 | 89 | writer.println(INDENT + "static final ITmfStateValue[] values = {"); |
b33f7554 AM |
90 | for (ITmfStateInterval interval : fullState) { |
91 | ITmfStateValue val = interval.getStateValue(); | |
01e6a579 | 92 | writer.print(INDENT + INDENT); |
8fab2e91 | 93 | |
b33f7554 AM |
94 | switch (val.getType()) { |
95 | case NULL: | |
96 | writer.println("TmfStateValue.nullValue(),"); | |
97 | break; | |
b33f7554 AM |
98 | case INTEGER: |
99 | writer.println("TmfStateValue.newValueInt(" + val.unboxInt() + "),"); | |
100 | break; | |
8fab2e91 AM |
101 | case LONG: |
102 | writer.println("TmfStateValue.newValueLong(" + val.unboxLong() +"),"); | |
103 | break; | |
b33f7554 AM |
104 | case STRING: |
105 | writer.println("TmfStateValue.newValueString(\"" + val.unboxStr() + "\"),"); | |
106 | break; | |
b33f7554 AM |
107 | default: |
108 | writer.println(val.toString()); | |
109 | break; | |
110 | } | |
111 | } | |
01e6a579 AM |
112 | writer.println(INDENT + "};"); |
113 | ||
114 | writer.println("}"); | |
115 | writer.println(); | |
b33f7554 AM |
116 | |
117 | writer.close(); | |
118 | System.exit(0); | |
119 | } | |
120 | ||
121 | } |