aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Denis2012-05-17 11:53:22 (EDT)
committerAlexandre Montplaisir2012-06-05 17:59:34 (EDT)
commit8b4fadfdd27f749aaec6072ff6e1c1044b33118d (patch)
tree569eded1c4cc9336dd449fd75982da8ea5db3d75
parentfefd52b84a933cc709d06566f3e93364f5828d34 (diff)
downloadorg.eclipse.linuxtools-8b4fadfdd27f749aaec6072ff6e1c1044b33118d.zip
org.eclipse.linuxtools-8b4fadfdd27f749aaec6072ff6e1c1044b33118d.tar.gz
org.eclipse.linuxtools-8b4fadfdd27f749aaec6072ff6e1c1044b33118d.tar.bz2
Add a simple example of how to use the state system with a CTF kernel trace
Signed-off-by: Mathieu Denis <mathieu.denis@polymtl.ca> Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/headless/BasicStateSystemExample.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/headless/BasicStateSystemExample.java b/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/headless/BasicStateSystemExample.java
new file mode 100644
index 0000000..b03b884
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/headless/BasicStateSystemExample.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.lttng2.kernel.core.tests.headless;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
+import org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider.CtfTestFiles;
+import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput;
+import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
+import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager;
+
+/**
+ * Simple example of how to use the state system using a CTF kernel trace.
+ *
+ * @author Mathieu Denis
+ */
+public class BasicStateSystemExample {
+
+ public static void main(String[] args) {
+ /* Read a trace and build the state system */
+ try {
+ File newStateFile = new File("/tmp/helloworldctf.ht"); //$NON-NLS-1$
+ IStateChangeInput input = new CtfKernelStateInput(CtfTestFiles.getTestTrace());
+ IStateSystemQuerier ss = StateSystemManager.loadStateHistory(newStateFile, input, true);
+
+ requestExample(ss);
+ } catch (TmfTraceException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * From a state system tree previously built with a CTF kernel trace, print
+ * to the console the interval of each state and the ID of the current
+ * thread running on each CPU.
+ *
+ * @param ssb
+ * the State System Builder through which make request
+ */
+ private static void requestExample(final IStateSystemQuerier ssb) {
+ try {
+ /* Request the current thread executing on each CPU */
+ List<Integer> currentThreadByCPUS;
+ List<ITmfStateInterval> stateIntervals;
+ StringBuilder output = new StringBuilder();
+
+ currentThreadByCPUS = ssb.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$
+
+ for (Integer currentThread : currentThreadByCPUS) {
+ stateIntervals = ssb.queryHistoryRange(currentThread.intValue(), ssb.getStartTime(),
+ ssb.getCurrentEndTime());
+
+ /* Output formatting */
+ output.append("Value of attribute : "); //$NON-NLS-1$
+ output.append(ssb.getFullAttributePath(currentThread.intValue()));
+ output.append("\n------------------------------------------------\n"); //$NON-NLS-1$
+ for (ITmfStateInterval stateInterval : stateIntervals) {
+ /* Print the interval */
+ output.append('[');
+ output.append(String.valueOf(stateInterval.getStartTime()));
+ output.append(", "); //$NON-NLS-1$
+ output.append(String.valueOf(stateInterval.getEndTime()));
+ output.append(']');
+ /* Print the attribute value */
+ output.append(" = "); //$NON-NLS-1$
+ output.append(stateInterval.getStateValue().unboxInt());
+ output.append('\n');
+ }
+ }
+ System.out.println(output.toString());
+ } catch (TimeRangeException e) {
+ e.printStackTrace();
+ } catch (AttributeNotFoundException e) {
+ e.printStackTrace();
+ } catch (StateValueTypeException e) {
+ e.printStackTrace();
+ }
+ }
+}