4 package org
.eclipse
.linuxtools
.lttng
.core
.state
.evProcessor
.state
;
6 import org
.eclipse
.linuxtools
.lttng
.core
.TraceDebug
;
7 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngEvent
;
8 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngEventContent
;
9 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngEventField
;
10 import org
.eclipse
.linuxtools
.lttng
.core
.state
.StateStrings
.Fields
;
11 import org
.eclipse
.linuxtools
.lttng
.core
.state
.model
.LttngProcessState
;
12 import org
.eclipse
.linuxtools
.lttng
.core
.state
.model
.LttngTraceState
;
13 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
16 * Common utility methods for all state processing handlers, not intended to be
17 * instantiated on its own
22 public abstract class AbsStateProcessing
{
25 * protected method used when a Field is requested among several available
26 * fields and the expected type is Long
30 * @param expectedNumFields
33 protected Long
getAFieldLong(LttngEvent trcEvent
, LttngTraceState traceSt
, Fields expectedField
) {
36 String fieldname
= expectedField
.getInName();
37 LttngEventField field
= (LttngEventField
) ((LttngEventContent
) trcEvent
.getContent()).getField(fieldname
);
39 if ( field
== null ) {
40 TraceDebug
.debug("***************** CONTENT : " + ((LttngEventContent
) trcEvent
.getContent()).toString()); //$NON-NLS-1$
43 Object fieldObj
= field
.getValue();
44 if ( (fieldObj
instanceof Long
) || (fieldObj
instanceof Integer
) ) {
45 // Expected numeric value found
46 fieldVal
= (Long
) field
.getValue();
49 if (TraceDebug
.isDEBUG()) {
50 TraceDebug
.debug("Unexpected field Type. Expected: Long, Received: "+ fieldObj
.getClass().getSimpleName()); //$NON-NLS-1$
56 // TmfEventField[] fields = trcEvent.getContent().getFields();
57 TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent())
60 // At least one field expected
61 if (fields.length == 0) {
62 TraceDebug.debug("Unexpected number of fields received: "
67 LttngEventField field;
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);
83 if (TraceDebug.isDEBUG()) {
85 .debug("Unexpected field Type. Expected: Long, Received: "
86 + fieldObj.getClass().getSimpleName());
94 // if (fieldVal == null) {
95 // if (TraceDebug.isDEBUG()) {
96 // sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname);
103 * protected method used when a Field is requested among several available
104 * fields and the expected type is String
108 * @param expectedNumFields
111 protected String
getAFieldString(LttngEvent trcEvent
,
112 LttngTraceState traceSt
, Fields expectedField
) {
113 String fieldVal
= ""; //$NON-NLS-1$
115 String fieldname
= expectedField
.getInName();
116 LttngEventField field
= (LttngEventField
) ((LttngEventContent
) trcEvent
.getContent()).getField(fieldname
);
118 if ( field
== null ) {
119 TraceDebug
.debug("***************** CONTENT : " + ((LttngEventContent
) trcEvent
.getContent()).toString()); //$NON-NLS-1$
122 Object fieldObj
= field
.getValue();
123 if (fieldObj
instanceof String
) {
124 // Expected numeric value found
125 fieldVal
= (String
) field
.getValue();
128 if (TraceDebug
.isDEBUG()) {
129 TraceDebug
.debug("Unexpected field Type. Expected: String, Received: "+ fieldObj
.getClass().getSimpleName()); //$NON-NLS-1$
135 // TmfEventField[] fields = trcEvent.getContent().getFields();
136 TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent())
137 .getFields(trcEvent);
139 // Only one field expected
140 if (fields.length == 0) {
141 TraceDebug.debug("Unexpected number of fields received: "
146 LttngEventField field;
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();
159 if (TraceDebug.isDEBUG()) {
161 .debug("Unexpected field Type. Expected: String, Received: "
162 + fieldObj.getClass().getSimpleName());
170 // if (fieldVal == null) {
171 // if (TraceDebug.isDEBUG()) {
172 // sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname);
179 * Find the process matching the given pid and cpu
181 * If cpu is 0, the cpu value is not matched and the selection is based on
189 protected LttngProcessState
lttv_state_find_process(
190 LttngTraceState traceState
, Long cpu
, Long pid
) {
192 return traceState
.findProcessState(pid
, cpu
, traceState
.getTraceId());
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() + " ");
207 TraceDebug
.debug(sb
.toString(), 5);