1 /*******************************************************************************
2 * Copyright (c) 2013 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
.headless
;
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
.tmf
.core
.interval
.ITmfStateInterval
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateProvider
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.TmfStateSystemFactory
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.ITmfStateValue
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
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 stateFile
= File
.createTempFile("test-values", ".ht");
59 stateFile
.deleteOnExit();
60 File logFile
= File
.createTempFile("TestValues", ".java");
61 try (PrintWriter writer
= new PrintWriter(new FileWriter(logFile
), true);) {
63 /* Build and query the state system */
64 ITmfStateProvider input
= new LttngKernelStateProvider(testTrace
.getTrace());
65 ITmfStateSystem ssq
= TmfStateSystemFactory
.newFullHistory(stateFile
, input
, true);
66 List
<ITmfStateInterval
> fullState
= ssq
.queryFullState(targetTimestamp
);
68 /* Start printing the java file's contents */
69 writer
.println("interface TestValues {");
71 writer
.println(INDENT
+ "static final int size = " + fullState
.size() + ";");
74 /* Print the array contents */
75 writer
.println(INDENT
+ "static final long[] startTimes = {");
76 for (ITmfStateInterval interval
: fullState
) {
77 writer
.println(INDENT
+ INDENT
+ String
.valueOf(interval
.getStartTime()) + "L,");
79 writer
.println(INDENT
+ "};");
82 writer
.println(INDENT
+ "static final long[] endTimes = {");
83 for (ITmfStateInterval interval
: fullState
) {
84 writer
.println(INDENT
+ INDENT
+ String
.valueOf(interval
.getEndTime()) + "L,");
86 writer
.println(INDENT
+ "};");
89 writer
.println(INDENT
+ "static final ITmfStateValue[] values = {");
90 for (ITmfStateInterval interval
: fullState
) {
91 ITmfStateValue val
= interval
.getStateValue();
92 writer
.print(INDENT
+ INDENT
);
94 switch (val
.getType()) {
96 writer
.println("TmfStateValue.nullValue(),");
99 writer
.println("TmfStateValue.newValueInt(" + val
.unboxInt() + "),");
102 writer
.println("TmfStateValue.newValueLong(" + val
.unboxLong() + "),");
105 writer
.println("TmfStateValue.newValueDouble(" + val
.unboxDouble() + "),");
108 writer
.println("TmfStateValue.newValueString(\"" + val
.unboxStr() + "\"),");
111 writer
.println(val
.toString());
115 writer
.println(INDENT
+ "};");