tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.jni / src / org / eclipse / linuxtools / lttng / jni / JniMarker.java
CommitLineData
0152140d
ASL
1package org.eclipse.linuxtools.lttng.jni;
2/*******************************************************************************
3 * Copyright (c) 2009 Ericsson
84b2b1f0 4 *
0152140d
ASL
5 * All rights reserved. This program and the accompanying materials are
6 * made available under the terms of the Eclipse Public License v1.0 which
7 * accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
84b2b1f0 9 *
0152140d
ASL
10 * Contributors:
11 * William Bourque (wbourque@gmail.com) - Initial API and implementation
12 *******************************************************************************/
13
14import java.util.ArrayList;
15import java.util.HashMap;
16
ce38c104
FC
17import org.eclipse.linuxtools.internal.lttng.jni.common.Jni_C_Pointer_And_Library_Id;
18import org.eclipse.linuxtools.internal.lttng.jni.exception.JniException;
19import org.eclipse.linuxtools.internal.lttng.jni.exception.JniMarkerException;
0152140d
ASL
20
21/**
0152140d
ASL
22 * A JniMarker contain information how to interpret the unparsed content (payload) of an event.<br>
23 * Each JniMarker contains several MarkerFields for each fields in the event's payload.
84b2b1f0
AM
24 *
25 * Provides access to the marker_info C structure (from LTT) in java.
26 *
0152140d
ASL
27 * Most important fields in the JniMarker are :
28 * <ul>
29 * <li> the name of the marker in String
30 * <li> an overview of the marker format (in C style printf format)
31 * <li> a reference to an ArrayList that contains MarkerFields object of this JniMarker
32 * </ul>
84b2b1f0 33 *
3b7509b0
WB
34 * <b>NOTE</b><p>
35 * This class is ABSTRACT, you need to extends it to support your specific LTTng version.<br>
36 * Please look at the abstract functions to override at the bottom of this file.<p>
84b2b1f0 37 *
d37aaa7f
FC
38 * @version 0.1
39 * @author William Bourque
0152140d
ASL
40 */
41public abstract class JniMarker extends Jni_C_Common
42{
43 // Internal C pointer of the JniEvent used in LTT
c85e8cb2 44 private Jni_C_Pointer_And_Library_Id thisMarkerPtr = new Jni_C_Pointer_And_Library_Id();
0152140d 45
9c4eb5f7
FC
46 private String name = ""; //$NON-NLS-1$
47 private String formatOverview = ""; //$NON-NLS-1$
84b2b1f0 48
0152140d
ASL
49 // These two contains hold references to the same MarkerField object
50 // The ArrayList can be used to efficiently find a field by its position
51 // The HashMap can be used to find a field by its name
52 private HashMap<String, JniMarkerField> markerFieldsHashMap = null;
53 private ArrayList<JniMarkerField> markerFieldsArrayList = null;
54
55 // Native access method
84b2b1f0 56 protected native String ltt_getName(int libId, long markerPtr);
c85e8cb2
WB
57 protected native String ltt_getFormatOverview(int libId, long markerPtr);
58 protected native long ltt_getSize(int libId, long markerPtr);
59 protected native short ltt_getLargestAlign(int libId, long markerPtr);
60 protected native short ltt_getIntSize(int libId, long markerPtr);
61 protected native short ltt_getLongSize(int libId, long markerPtr);
62 protected native short ltt_getPointerSize(int libId, long markerPtr);
63 protected native short ltt_getSize_tSize(int libId, long markerPtr);
64 protected native void ltt_getAllMarkerFields(int libId, long tracePtr);
65 protected native short ltt_getAlignement(int libId, long markerPtr);
66 protected native long ltt_getNextMarkerPtr(int libId, long markerPtr);
0152140d
ASL
67
68 // Debug native function, ask LTT to print marker structure
c85e8cb2 69 protected native void ltt_printMarker(int libId, long markerPtr);
a9fcdd8d 70
0152140d
ASL
71 /*
72 * Default constructor is forbidden
73 */
74 protected JniMarker() {
75 }
84b2b1f0 76
0152140d
ASL
77 /**
78 * Copy constructor.<p>
84b2b1f0
AM
79 *
80 * @param oldMarker Reference to the JniMarker you want to copy.
0152140d
ASL
81 */
82 public JniMarker(JniMarker oldMarker) {
83 thisMarkerPtr = oldMarker.thisMarkerPtr;
84 name = oldMarker.name;
85 formatOverview = oldMarker.formatOverview;
86 markerFieldsHashMap = oldMarker.markerFieldsHashMap;
87 markerFieldsArrayList = oldMarker.markerFieldsArrayList;
88
89 }
90
91 /**
84b2b1f0
AM
92 * Constructor, using pointer.
93 * <p>
94 *
95 * @param newMarkerPtr
96 * Pointer to a C marker_info structure
0152140d 97 * @exception JniException
84b2b1f0 98 * If the JNI call fails
0152140d 99 */
c85e8cb2 100 public JniMarker(Jni_C_Pointer_And_Library_Id newMarkerPtr) throws JniException {
0152140d
ASL
101 thisMarkerPtr = newMarkerPtr;
102 markerFieldsArrayList = new ArrayList<JniMarkerField>();
103 markerFieldsHashMap = new HashMap<String, JniMarkerField>();
104
105 // Populate the marker
106 populateMarkerInformation();
107 }
108
84b2b1f0
AM
109
110 /**
0152140d 111 * This function populates the marker data with data from LTT
0152140d
ASL
112 */
113 private void populateMarkerInformation() throws JniException {
114 if (thisMarkerPtr.getPointer() == NULL) {
9c4eb5f7 115 throw new JniMarkerException("Pointer is NULL, trace closed? (populateMarkerInformatOverviewion)"); //$NON-NLS-1$
0152140d 116 }
84b2b1f0
AM
117 name = ltt_getName(thisMarkerPtr.getLibraryId(), thisMarkerPtr.getPointer());
118 formatOverview = ltt_getFormatOverview(thisMarkerPtr.getLibraryId(), thisMarkerPtr.getPointer());
119 // To fill the markerFieldArray is a bit different
120 ltt_getAllMarkerFields(thisMarkerPtr.getLibraryId(), thisMarkerPtr.getPointer());
0152140d
ASL
121 }
122
84b2b1f0 123 /**
0152140d 124 * Fills a map of all the JniMarkerField associated with this JniMarker.
84b2b1f0 125 *
0152140d
ASL
126 * Note: This function is called from C and there is no way to propagate
127 * exception back to the caller without crashing JNI. Therefore, it MUST
128 * catch all exceptions.
84b2b1f0 129 *
0152140d
ASL
130 * @param markerName Name of the parent marker
131 * @param markerFieldPtr C Pointer (converted in long) to marker_field C Structure
132 */
687cc7e7 133 private void addMarkerFieldFromC(String markerFieldName, long markerFieldPtr) {
34eff969 134 // Create a new Jni_markerField object and insert it in the map
0152140d
ASL
135 // the maker field fill itself with LTT data while being constructed
136 try {
c85e8cb2 137 JniMarkerField newMarkerField = allocateNewJniMarkerField( new Jni_C_Pointer_And_Library_Id(thisMarkerPtr.getLibraryId(), markerFieldPtr));
0152140d
ASL
138 markerFieldsArrayList.add(newMarkerField);
139 markerFieldsHashMap.put(markerFieldName, newMarkerField);
84b2b1f0 140
0152140d 141 } catch (JniException e) {
9c4eb5f7 142 printlnC(thisMarkerPtr.getLibraryId(), "Failed to add marker field " + markerFieldName + " to marker fields list!(addMarkerFieldFromC)\n\tException raised : " + e.toString() ); //$NON-NLS-1$ //$NON-NLS-2$
0152140d
ASL
143 }
144 }
145
84b2b1f0
AM
146 // Access to class variables. Most of them doesn't have setters
147
148 /**
149 * Get the name of this marker
150 *
151 * @return The name
152 */
0152140d
ASL
153 public String getName() {
154 return name;
155 }
156
84b2b1f0
AM
157 /**
158 * Get the format overview
159 *
160 * @return The format overview, as one string
161 */
0152140d
ASL
162 public String getFormatOverview() {
163 return formatOverview;
164 }
165
84b2b1f0
AM
166 /**
167 * Get the marker fields as a hashmap
168 *
169 * @return The map of fields
170 */
0152140d
ASL
171 public HashMap<String,JniMarkerField> getMarkerFieldsHashMap() {
172 return markerFieldsHashMap;
173 }
84b2b1f0
AM
174
175 /**
176 * Get the marker fields as an array list
177 *
178 * @return The array list of fields
179 */
0152140d
ASL
180 public ArrayList<JniMarkerField> getMarkerFieldsArrayList() {
181 return markerFieldsArrayList;
182 }
84b2b1f0 183
0152140d
ASL
184 /**
185 * Pointer to the marker_info C structure.<p>
84b2b1f0 186 *
0152140d
ASL
187 * The pointer should only be used <u>INTERNALY</u>, do not use unless you
188 * know what you are doing.<p>
84b2b1f0 189 *
0152140d 190 * @return The actual (long converted) pointer or NULL
84b2b1f0 191 *
ce38c104 192 * @see org.eclipse.linuxtools.internal.lttng.jni.common.Jni_C_Pointer_And_Library_Id
0152140d 193 */
c85e8cb2 194 public Jni_C_Pointer_And_Library_Id getMarkerPtr() {
0152140d
ASL
195 return thisMarkerPtr;
196 }
84b2b1f0
AM
197
198
0152140d 199 /**
84b2b1f0 200 * Print information for this JniMarker.
0152140d 201 * <u>Intended to debug</u><br>
84b2b1f0
AM
202 *
203 * This function will call Ltt to print, so information printed will be the one from
0152140d 204 * the C structure, not the one populated in java.<p>
84b2b1f0 205 *
0152140d
ASL
206 * This function will not throw but will complain loudly if pointer is NULL
207 */
208 public void printMarkerInformation() {
c85e8cb2 209 ltt_printMarker(thisMarkerPtr.getLibraryId(), thisMarkerPtr.getPointer());
0152140d 210 }
84b2b1f0 211
0152140d 212 /**
84b2b1f0 213 * Print information for ALL marker fields for this marker.
0152140d 214 * <u>Intended to debug</u><br>
84b2b1f0
AM
215 *
216 * This function will call Ltt to print, so information printed will be the one from
0152140d
ASL
217 * the C structure, not the one populated in java.
218 */
219 public void printAllMarkerFieldsInformation() {
220 Object[] allMarkersField = markerFieldsArrayList.toArray();
221
222 for (int pos = 0; pos < allMarkersField.length; pos++) {
c85e8cb2 223 printlnC(thisMarkerPtr.getLibraryId(), allMarkersField[pos].toString());
0152140d
ASL
224 }
225 }
84b2b1f0 226
0152140d 227 /**
84b2b1f0 228 * toString() method.
0152140d 229 * <u>Intended to debug</u><br>
84b2b1f0 230 *
0152140d
ASL
231 * @return Attributes of the object concatenated in String
232 */
233 @Override
3b38ea61 234 @SuppressWarnings("nls")
0152140d
ASL
235 public String toString() {
236 String returnData = "";
237
238 returnData += "name : " + name + "\n";
239 returnData += "formatOverview : " + formatOverview + "\n";
e0ea56dd 240 returnData += "markerFieldArrayList : " + markerFieldsArrayList.hashCode() + " (size : " + markerFieldsArrayList.size() + " )" + "\n";
84b2b1f0 241
0152140d
ASL
242 return returnData;
243 }
84b2b1f0
AM
244
245
c357e4b6
WB
246 // ****************************
247 // **** ABSTRACT FUNCTIONS ****
248 // You MUST override those in your version specific implementation
84b2b1f0
AM
249
250
c357e4b6
WB
251 /**
252 * Function place holder to allocate a new JniMarkerField.<p>
253 * <br>
254 * JniMarkerField constructor is non overridable so we need another overridable function to return the correct version of JniMarkerField.<br>
255 * Effect of this function should be the same (allocate a fresh new JniMarkerField).<br>
256 * <br>
257 * <b>!! Override this with you version specific implementation.</b><br>
84b2b1f0 258 *
c85e8cb2 259 * @param newMarkerFieldPtr The pointer and library id of an already opened marker_field C Structure
84b2b1f0 260 *
c357e4b6 261 * @return The newly allocated JniMarkerField of the correct version
84b2b1f0 262 *
c357e4b6 263 * @throws JniException The construction (allocation) failed.
84b2b1f0 264 *
ce38c104 265 * @see org.eclipse.linuxtools.internal.lttng.jni.common.Jni_C_Pointer_And_Library_Id
c357e4b6
WB
266 * @see org.eclipse.linuxtools.lttng.jni.JniMarkerField
267 */
c85e8cb2 268 public abstract JniMarkerField allocateNewJniMarkerField(Jni_C_Pointer_And_Library_Id newMarkerFieldPtr) throws JniException;
84b2b1f0 269
0152140d 270}
This page took 0.047139 seconds and 5 git commands to generate.