1
/*******************************************************************************
2
* Copyright (c) 2013, 2014 Ericsson
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
10
* Alexandre Montplaisir - Initial API and implementation
11
******************************************************************************/
13
package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
16
import java.io.FileWriter;
17
import java.io.PrintWriter;
18
import java.util.List;
20
import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
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;
24
import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
25
import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
26
import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
27
import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
30
* Small program to regenerate the values used in "TestValues.java" from the
31
* current LTTng-kernel state provider.
33
* It will write its output the a file called 'TestValues<something>.java' in your
34
* temporary files directory.
36
* @author Alexandre Montplaisir
38
public class GenerateTestValues {
40
private static CtfTmfTestTrace testTrace = CtfTmfTestTrace.TRACE2;
41
private static final long targetTimestamp = 18670067372290L + 1331649577946812237L;
42
private static final String INDENT = " ";
48
* Command-line arguments, unused.
50
* I'm messing with Exception. Come at me bro!
52
public static void main(String[] args) throws Exception {
53
if (!testTrace.exists()) {
54
System.err.println("Trace files not present.");
58
/* Prepare the files */
59
File logFile = File.createTempFile("TestValues", ".java");
60
try (final CtfTmfTrace trace = testTrace.getTrace();
61
PrintWriter writer = new PrintWriter(new FileWriter(logFile), true);
62
/* Build and query the state system */
63
TmfStateSystemAnalysisModule module = new TmfStateSystemAnalysisModule() {
65
protected ITmfStateProvider createStateProvider() {
66
return new LttngKernelStateProvider(trace);
70
protected String getSsFileName() {
74
module.setTrace(trace);
75
module.setId("test-values");
77
module.waitForCompletion();
78
ITmfStateSystem ssq = module.getStateSystem();
80
throw new IllegalStateException();
83
List<ITmfStateInterval> fullState = ssq.queryFullState(targetTimestamp);
85
/* Start printing the java file's contents */
86
writer.println("interface TestValues {");
88
writer.println(INDENT + "static final int size = " + fullState.size() + ";");
91
/* Print the array contents */
92
writer.println(INDENT + "static final long[] startTimes = {");
93
for (ITmfStateInterval interval : fullState) {
94
writer.println(INDENT + INDENT + String.valueOf(interval.getStartTime()) + "L,");
96
writer.println(INDENT + "};");
99
writer.println(INDENT + "static final long[] endTimes = {");
100
for (ITmfStateInterval interval : fullState) {
101
writer.println(INDENT + INDENT + String.valueOf(interval.getEndTime()) + "L,");
103
writer.println(INDENT + "};");
106
writer.println(INDENT + "static final ITmfStateValue[] values = {");
107
for (ITmfStateInterval interval : fullState) {
108
ITmfStateValue val = interval.getStateValue();
109
writer.print(INDENT + INDENT);
111
switch (val.getType()) {
113
writer.println("TmfStateValue.nullValue(),");
116
writer.println("TmfStateValue.newValueInt(" + val.unboxInt() + "),");
119
writer.println("TmfStateValue.newValueLong(" + val.unboxLong() + "),");
122
writer.println("TmfStateValue.newValueDouble(" + val.unboxDouble() + "),");
125
writer.println("TmfStateValue.newValueString(\"" + val.unboxStr() + "\"),");
128
writer.println(val.toString());
132
writer.println(INDENT + "};");