1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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
.tracecompass
.lttng2
.kernel
.core
.tests
.analysis
.kernel
.statesystem
;
16 import java
.io
.FileWriter
;
17 import java
.io
.PrintWriter
;
18 import java
.util
.List
;
20 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.KernelAnalysisModule
;
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
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
25 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
29 * Small program to regenerate the values used in "TestValues.java" from the
30 * current LTTng-kernel state provider.
32 * It will write its output the a file called 'TestValues<something>.java' in your
33 * temporary files directory.
35 * @author Alexandre Montplaisir
37 public class GenerateTestValues
{
39 private static CtfTmfTestTrace testTrace
= CtfTmfTestTrace
.TRACE2
;
40 private static final long targetTimestamp
= 18670067372290L + 1331649577946812237L;
41 private static final String INDENT
= " ";
47 * Command-line arguments, unused.
49 * I'm messing with Exception. Come at me bro!
51 public static void main(String
[] args
) throws Exception
{
52 if (!testTrace
.exists()) {
53 System
.err
.println("Trace files not present.");
57 /* Prepare the files */
58 File logFile
= File
.createTempFile("TestValues", ".java");
59 try (final CtfTmfTrace trace
= testTrace
.getTrace();
60 PrintWriter writer
= new PrintWriter(new FileWriter(logFile
), true);) {
62 /* Build and query the state system */
63 TmfStateSystemAnalysisModule module
= new KernelAnalysisModule() {
65 protected String
getSsFileName() {
70 if (!module
.setTrace(trace
)) {
71 throw new IllegalStateException();
73 module
.setId("test-values");
75 module
.waitForCompletion();
76 ITmfStateSystem ssq
= module
.getStateSystem();
78 throw new IllegalStateException();
81 List
<ITmfStateInterval
> fullState
= ssq
.queryFullState(targetTimestamp
);
83 /* Start printing the java file's contents */
84 writer
.println("interface TestValues {");
86 writer
.println(INDENT
+ "int size = " + fullState
.size() + ";");
89 /* Print the array contents */
90 writer
.println(INDENT
+ "long[] startTimes = {");
91 for (ITmfStateInterval interval
: fullState
) {
92 writer
.println(INDENT
+ INDENT
+ String
.valueOf(interval
.getStartTime()) + "L,");
94 writer
.println(INDENT
+ "};");
97 writer
.println(INDENT
+ "long[] endTimes = {");
98 for (ITmfStateInterval interval
: fullState
) {
99 writer
.println(INDENT
+ INDENT
+ String
.valueOf(interval
.getEndTime()) + "L,");
101 writer
.println(INDENT
+ "};");
104 writer
.println(INDENT
+ "ITmfStateValue[] values = {");
105 for (ITmfStateInterval interval
: fullState
) {
106 ITmfStateValue val
= interval
.getStateValue();
107 writer
.print(INDENT
+ INDENT
);
109 switch (val
.getType()) {
111 writer
.println("TmfStateValue.nullValue(),");
114 writer
.println("TmfStateValue.newValueInt(" + val
.unboxInt() + "),");
117 writer
.println("TmfStateValue.newValueLong(" + val
.unboxLong() + "),");
120 writer
.println("TmfStateValue.newValueDouble(" + val
.unboxDouble() + "),");
123 writer
.println("TmfStateValue.newValueString(\"" + val
.unboxStr() + "\"),");
126 writer
.println(val
.toString());
130 writer
.println(INDENT
+ "};");