4 package org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.state
;
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
;
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
= ((LttngEventContent
) trcEvent
.getContent()).getField(fieldname
);
39 if ( field
== null ) {
40 TraceDebug
.debug("***************** CONTENT : " + ((LttngEventContent
) trcEvent
.getContent()).toString());
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());
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
= "";
115 String fieldname
= expectedField
.getInName();
116 LttngEventField field
= ((LttngEventContent
) trcEvent
.getContent()).getField(fieldname
);
118 if ( field
== null ) {
119 TraceDebug
.debug("***************** CONTENT : " + ((LttngEventContent
) trcEvent
.getContent()).toString());
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());
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 protected void sendNoFieldFoundMsg(TmfEventField
[] fields
,
196 String expectedFieldName
) {
197 LttngEventField field
;
198 StringBuilder sb
= new StringBuilder("Field not found, requested: "
199 + expectedFieldName
);
200 sb
.append(" number of fields: " + fields
.length
+ "Fields: ");
201 for (int i
= 0; i
< fields
.length
; i
++) {
202 field
= (LttngEventField
) fields
[i
];
203 sb
.append(field
.getId() + " ");
206 TraceDebug
.debug(sb
.toString(), 5);