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
.jdt
.annotation
.NonNull
;
21 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.KernelAnalysisModule
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
25 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
27 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
28 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
31 * Small program to regenerate the values used in "TestValues.java" from the
32 * current LTTng-kernel state provider.
34 * It will write its output the a file called 'TestValues<something>.java' in your
35 * temporary files directory.
37 * @author Alexandre Montplaisir
39 public class GenerateTestValues
{
41 private static @NonNull CtfTestTrace testTrace
= CtfTestTrace
.TRACE2
;
42 private static final long targetTimestamp
= 18670067372290L + 1331649577946812237L;
43 private static final String INDENT
= " ";
49 * Command-line arguments, unused.
51 * I'm messing with Exception. Come at me bro!
53 public static void main(String
[] args
) throws Exception
{
54 /* Prepare the files */
55 File logFile
= File
.createTempFile("TestValues", ".java");
56 try (PrintWriter writer
= new PrintWriter(new FileWriter(logFile
), true);) {
58 /* Build and query the state system */
59 final CtfTmfTrace trace
= CtfTmfTestTraceUtils
.getTrace(testTrace
);
60 TmfStateSystemAnalysisModule module
= new KernelAnalysisModule() {
62 protected String
getSsFileName() {
67 if (!module
.setTrace(trace
)) {
68 throw new IllegalStateException();
70 module
.setId("test-values");
72 module
.waitForCompletion();
73 ITmfStateSystem ssq
= module
.getStateSystem();
75 throw new IllegalStateException();
78 List
<ITmfStateInterval
> fullState
= ssq
.queryFullState(targetTimestamp
);
80 /* Start printing the java file's contents */
81 writer
.println("interface TestValues {");
83 writer
.println(INDENT
+ "int size = " + fullState
.size() + ";");
86 /* Print the array contents */
87 writer
.println(INDENT
+ "long[] startTimes = {");
88 for (ITmfStateInterval interval
: fullState
) {
89 writer
.println(INDENT
+ INDENT
+ String
.valueOf(interval
.getStartTime()) + "L,");
91 writer
.println(INDENT
+ "};");
94 writer
.println(INDENT
+ "long[] endTimes = {");
95 for (ITmfStateInterval interval
: fullState
) {
96 writer
.println(INDENT
+ INDENT
+ String
.valueOf(interval
.getEndTime()) + "L,");
98 writer
.println(INDENT
+ "};");
101 writer
.println(INDENT
+ "ITmfStateValue[] values = {");
102 for (ITmfStateInterval interval
: fullState
) {
103 ITmfStateValue val
= interval
.getStateValue();
104 writer
.print(INDENT
+ INDENT
);
106 switch (val
.getType()) {
108 writer
.println("TmfStateValue.nullValue(),");
111 writer
.println("TmfStateValue.newValueInt(" + val
.unboxInt() + "),");
114 writer
.println("TmfStateValue.newValueLong(" + val
.unboxLong() + "),");
117 writer
.println("TmfStateValue.newValueDouble(" + val
.unboxDouble() + "),");
120 writer
.println("TmfStateValue.newValueString(\"" + val
.unboxStr() + "\"),");
123 writer
.println(val
.toString());
127 writer
.println(INDENT
+ "};");