Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / lttng / state / evProcessor / state / AbsStateProcessing.java
1 /**
2 *
3 */
4 package org.eclipse.linuxtools.lttng.state.evProcessor.state;
5
6 import org.eclipse.linuxtools.lttng.TraceDebug;
7 import org.eclipse.linuxtools.lttng.event.LttngEvent;
8 import org.eclipse.linuxtools.lttng.event.LttngEventContent;
9 import org.eclipse.linuxtools.lttng.event.LttngEventField;
10 import org.eclipse.linuxtools.lttng.state.StateStrings.Fields;
11 import org.eclipse.linuxtools.lttng.state.model.LttngProcessState;
12 import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
13 import org.eclipse.linuxtools.tmf.event.TmfEventField;
14
15 /**
16 * Common utility methods for all state processing handlers, not intended to be
17 * instantiated on its own
18 *
19 * @author alvaro
20 *
21 */
22 public abstract class AbsStateProcessing {
23
24 /**
25 * protected method used when a Field is requested among several available
26 * fields and the expected type is Long
27 *
28 * @param trcEvent
29 * @param traceSt
30 * @param expectedNumFields
31 * @return
32 */
33 protected Long getAFieldLong(LttngEvent trcEvent, LttngTraceState traceSt, Fields expectedField) {
34 Long fieldVal = 0L;
35
36 String fieldname = expectedField.getInName();
37 LttngEventField field = (LttngEventField) ((LttngEventContent) trcEvent.getContent()).getField(fieldname);
38
39 if ( field == null ) {
40 TraceDebug.debug("***************** CONTENT : " + ((LttngEventContent) trcEvent.getContent()).toString()); //$NON-NLS-1$
41 }
42 else {
43 Object fieldObj = field.getValue();
44 if ( (fieldObj instanceof Long) || (fieldObj instanceof Integer) ) {
45 // Expected numeric value found
46 fieldVal = (Long) field.getValue();
47 }
48 else {
49 if (TraceDebug.isDEBUG()) {
50 TraceDebug.debug("Unexpected field Type. Expected: Long, Received: "+ fieldObj.getClass().getSimpleName()); //$NON-NLS-1$
51 }
52 }
53 }
54
55 /*
56 // TmfEventField[] fields = trcEvent.getContent().getFields();
57 TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent())
58 .getFields(trcEvent);
59
60 // At least one field expected
61 if (fields.length == 0) {
62 TraceDebug.debug("Unexpected number of fields received: "
63 + fields.length);
64 return null;
65 }
66
67 LttngEventField field;
68 String fieldname;
69 String expectedFieldName = expectedField.getInName();
70 for (int i = 0; i < fields.length; i++) {
71 field = (LttngEventField) fields[i];
72 fieldname = field.getName();
73 if (fieldname.equals(expectedFieldName)) {
74 Object fieldObj = field.getValue();
75 if (fieldObj instanceof Long) {
76 // Expected value found
77 fieldVal = (Long) field.getValue();
78 // if (expectedField == Fields.LTT_FIELD_TYPE) {
79 // TraceDebug.debug("Field Type value is: " + fieldVal);
80 // }
81 break;
82 } else {
83 if (TraceDebug.isDEBUG()) {
84 TraceDebug
85 .debug("Unexpected field Type. Expected: Long, Received: "
86 + fieldObj.getClass().getSimpleName());
87 }
88 return null;
89 }
90 }
91 }
92 */
93
94 // if (fieldVal == null) {
95 // if (TraceDebug.isDEBUG()) {
96 // sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname);
97 // }
98 // }
99 return fieldVal;
100 }
101
102 /**
103 * protected method used when a Field is requested among several available
104 * fields and the expected type is String
105 *
106 * @param trcEvent
107 * @param traceSt
108 * @param expectedNumFields
109 * @return
110 */
111 protected String getAFieldString(LttngEvent trcEvent,
112 LttngTraceState traceSt, Fields expectedField) {
113 String fieldVal = ""; //$NON-NLS-1$
114
115 String fieldname = expectedField.getInName();
116 LttngEventField field = (LttngEventField) ((LttngEventContent) trcEvent.getContent()).getField(fieldname);
117
118 if ( field == null ) {
119 TraceDebug.debug("***************** CONTENT : " + ((LttngEventContent) trcEvent.getContent()).toString()); //$NON-NLS-1$
120 }
121 else {
122 Object fieldObj = field.getValue();
123 if (fieldObj instanceof String) {
124 // Expected numeric value found
125 fieldVal = (String) field.getValue();
126 }
127 else {
128 if (TraceDebug.isDEBUG()) {
129 TraceDebug.debug("Unexpected field Type. Expected: String, Received: "+ fieldObj.getClass().getSimpleName()); //$NON-NLS-1$
130 }
131 }
132 }
133
134 /*
135 // TmfEventField[] fields = trcEvent.getContent().getFields();
136 TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent())
137 .getFields(trcEvent);
138
139 // Only one field expected
140 if (fields.length == 0) {
141 TraceDebug.debug("Unexpected number of fields received: "
142 + fields.length);
143 return null;
144 }
145
146 LttngEventField field;
147 String fieldname;
148 String expectedFieldName = expectedField.getInName();
149 for (int i = 0; i < fields.length; i++) {
150 field = (LttngEventField) fields[i];
151 fieldname = field.getName();
152 if (fieldname.equals(expectedFieldName)) {
153 Object fieldObj = field.getValue();
154 if (fieldObj instanceof String) {
155 // Expected value found
156 fieldVal = (String) field.getValue();
157 break;
158 } else {
159 if (TraceDebug.isDEBUG()) {
160 TraceDebug
161 .debug("Unexpected field Type. Expected: String, Received: "
162 + fieldObj.getClass().getSimpleName());
163 }
164 return null;
165 }
166 }
167 }
168 */
169
170 // if (fieldVal == null) {
171 // if (TraceDebug.isDEBUG()) {
172 // sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname);
173 // }
174 // }
175 return fieldVal;
176 }
177
178 /**
179 * Find the process matching the given pid and cpu
180 *
181 * If cpu is 0, the cpu value is not matched and the selection is based on
182 * pid value only
183 *
184 * @param traceState
185 * @param cpu
186 * @param pid
187 * @return
188 */
189 protected LttngProcessState lttv_state_find_process(
190 LttngTraceState traceState, Long cpu, Long pid) {
191
192 return traceState.findProcessState(pid, cpu, traceState.getTraceId());
193 }
194
195 @SuppressWarnings("nls")
196 protected void sendNoFieldFoundMsg(TmfEventField[] fields,
197 String expectedFieldName) {
198 LttngEventField field;
199 StringBuilder sb = new StringBuilder("Field not found, requested: "
200 + expectedFieldName);
201 sb.append(" number of fields: " + fields.length + "Fields: ");
202 for (int i = 0; i < fields.length; i++) {
203 field = (LttngEventField) fields[i];
204 sb.append(field.getId() + " ");
205 }
206
207 TraceDebug.debug(sb.toString(), 5);
208 }
209
210 }
This page took 0.04295 seconds and 5 git commands to generate.