Commit | Line | Data |
---|---|---|
5d10d135 ASL |
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 | */ | |
28b94d61 | 33 | protected Long getAFieldLong(LttngEvent trcEvent, LttngTraceState traceSt, Fields expectedField) { |
a3fe52fc | 34 | Long fieldVal = 0L; |
28b94d61 FC |
35 | |
36 | String fieldname = expectedField.getInName(); | |
d86b9d98 | 37 | LttngEventField field = (LttngEventField) ((LttngEventContent) trcEvent.getContent()).getField(fieldname); |
28b94d61 | 38 | |
a3fe52fc | 39 | if ( field == null ) { |
3b38ea61 | 40 | TraceDebug.debug("***************** CONTENT : " + ((LttngEventContent) trcEvent.getContent()).toString()); //$NON-NLS-1$ |
a3fe52fc FC |
41 | } |
42 | else { | |
28b94d61 FC |
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()) { | |
3b38ea61 | 50 | TraceDebug.debug("Unexpected field Type. Expected: Long, Received: "+ fieldObj.getClass().getSimpleName()); //$NON-NLS-1$ |
28b94d61 FC |
51 | } |
52 | } | |
a3fe52fc | 53 | } |
28b94d61 FC |
54 | |
55 | /* | |
5d10d135 ASL |
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 | } | |
28b94d61 | 92 | */ |
5d10d135 | 93 | |
28b94d61 FC |
94 | // if (fieldVal == null) { |
95 | // if (TraceDebug.isDEBUG()) { | |
96 | // sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname); | |
97 | // } | |
98 | // } | |
5d10d135 ASL |
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) { | |
3b38ea61 | 113 | String fieldVal = ""; //$NON-NLS-1$ |
28b94d61 FC |
114 | |
115 | String fieldname = expectedField.getInName(); | |
d86b9d98 | 116 | LttngEventField field = (LttngEventField) ((LttngEventContent) trcEvent.getContent()).getField(fieldname); |
28b94d61 | 117 | |
a3fe52fc | 118 | if ( field == null ) { |
3b38ea61 | 119 | TraceDebug.debug("***************** CONTENT : " + ((LttngEventContent) trcEvent.getContent()).toString()); //$NON-NLS-1$ |
a3fe52fc FC |
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()) { | |
3b38ea61 | 129 | TraceDebug.debug("Unexpected field Type. Expected: String, Received: "+ fieldObj.getClass().getSimpleName()); //$NON-NLS-1$ |
a3fe52fc FC |
130 | } |
131 | } | |
132 | } | |
28b94d61 FC |
133 | |
134 | /* | |
5d10d135 ASL |
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 | } | |
28b94d61 FC |
168 | */ |
169 | ||
170 | // if (fieldVal == null) { | |
171 | // if (TraceDebug.isDEBUG()) { | |
172 | // sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname); | |
173 | // } | |
174 | // } | |
5d10d135 ASL |
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( | |
2211df66 | 190 | LttngTraceState traceState, Long cpu, Long pid) { |
5d10d135 | 191 | |
2211df66 | 192 | return traceState.findProcessState(pid, cpu, traceState.getTraceId()); |
5d10d135 ASL |
193 | } |
194 | ||
3b38ea61 | 195 | @SuppressWarnings("nls") |
5d10d135 ASL |
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]; | |
28b94d61 | 204 | sb.append(field.getId() + " "); |
5d10d135 ASL |
205 | } |
206 | ||
207 | TraceDebug.debug(sb.toString(), 5); | |
208 | } | |
209 | ||
210 | } |