Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3e199a8986b7194cb712cb2a934a265b03393003 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**
 * 
 */
package org.eclipse.linuxtools.internal.lttng.core.state.evProcessor.state;

import org.eclipse.linuxtools.internal.lttng.core.TraceDebug;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEventContent;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEventField;
import org.eclipse.linuxtools.internal.lttng.core.state.StateStrings.Fields;
import org.eclipse.linuxtools.internal.lttng.core.state.model.LttngProcessState;
import org.eclipse.linuxtools.internal.lttng.core.state.model.LttngTraceState;
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;

/**
 * Common utility methods for all state processing handlers, not intended to be
 * instantiated on its own
 * 
 * @author alvaro
 * 
 */
public abstract class AbsStateProcessing {

	/**
	 * protected method used when a Field is requested among several available
	 * fields and the expected type is Long
	 * 
	 * @param trcEvent
	 * @param traceSt
	 * @param expectedNumFields
	 * @return
	 */
	protected Long getAFieldLong(LttngEvent trcEvent, LttngTraceState traceSt, Fields expectedField) {
		Long fieldVal = 0L;
		
        String fieldname = expectedField.getInName();
		LttngEventField field = (LttngEventField) ((LttngEventContent) trcEvent.getContent()).getField(fieldname);
		
		if ( field == null ) {
			TraceDebug.debug("***************** CONTENT : " + ((LttngEventContent) trcEvent.getContent()).toString()); //$NON-NLS-1$
		}
		else {
            Object fieldObj = field.getValue();
            if ( (fieldObj instanceof Long) || (fieldObj instanceof Integer) ) {
                // Expected numeric value found
                fieldVal = (Long) field.getValue();
            } 
            else {
                if (TraceDebug.isDEBUG()) {
                    TraceDebug.debug("Unexpected field Type. Expected: Long, Received: "+ fieldObj.getClass().getSimpleName()); //$NON-NLS-1$
                }
            }
		}
		
		/*
		// TmfEventField[] fields = trcEvent.getContent().getFields();
		TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent())
				.getFields(trcEvent);
	
		// At least one field expected
		if (fields.length == 0) {
			TraceDebug.debug("Unexpected number of fields received: "
					+ fields.length);
			return null;
		}
	
		LttngEventField field;
		String fieldname;
		String expectedFieldName = expectedField.getInName();
		for (int i = 0; i < fields.length; i++) {
			field = (LttngEventField) fields[i];
			fieldname = field.getName();
			if (fieldname.equals(expectedFieldName)) {
				Object fieldObj = field.getValue();
				if (fieldObj instanceof Long) {
					// Expected value found
					fieldVal = (Long) field.getValue();
					// if (expectedField == Fields.LTT_FIELD_TYPE) {
					// TraceDebug.debug("Field Type value is: " + fieldVal);
					// }
					break;
				} else {
					if (TraceDebug.isDEBUG()) {
						TraceDebug
								.debug("Unexpected field Type. Expected: Long, Received: "
										+ fieldObj.getClass().getSimpleName());
					}
					return null;
				}
			}
		}
		*/
	
//		if (fieldVal == null) {
//			if (TraceDebug.isDEBUG()) {
//				sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname);
//			}
//		}
		return fieldVal;
	}

	/**
	 * protected method used when a Field is requested among several available
	 * fields and the expected type is String
	 * 
	 * @param trcEvent
	 * @param traceSt
	 * @param expectedNumFields
	 * @return
	 */
	protected String getAFieldString(LttngEvent trcEvent,
			LttngTraceState traceSt, Fields expectedField) {
		String fieldVal = ""; //$NON-NLS-1$
		
		String fieldname = expectedField.getInName();
        LttngEventField field = (LttngEventField) ((LttngEventContent) trcEvent.getContent()).getField(fieldname);
        
		if ( field == null ) {
			TraceDebug.debug("***************** CONTENT : " + ((LttngEventContent) trcEvent.getContent()).toString()); //$NON-NLS-1$
		}
		else {
	        Object fieldObj = field.getValue();
	        if (fieldObj instanceof String) {
	            // Expected numeric value found
	            fieldVal = (String) field.getValue();
	        } 
	        else {
	            if (TraceDebug.isDEBUG()) {
	                TraceDebug.debug("Unexpected field Type. Expected: String, Received: "+ fieldObj.getClass().getSimpleName()); //$NON-NLS-1$
	            }
	        }
		}
		
		/*
		// TmfEventField[] fields = trcEvent.getContent().getFields();
		TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent())
				.getFields(trcEvent);

		// Only one field expected
		if (fields.length == 0) {
			TraceDebug.debug("Unexpected number of fields received: "
					+ fields.length);
			return null;
		}
	
		LttngEventField field;
		String fieldname;
		String expectedFieldName = expectedField.getInName();
		for (int i = 0; i < fields.length; i++) {
			field = (LttngEventField) fields[i];
			fieldname = field.getName();
			if (fieldname.equals(expectedFieldName)) {
				Object fieldObj = field.getValue();
				if (fieldObj instanceof String) {
					// Expected value found
					fieldVal = (String) field.getValue();
					break;
				} else {
					if (TraceDebug.isDEBUG()) {
						TraceDebug
								.debug("Unexpected field Type. Expected: String, Received: "
										+ fieldObj.getClass().getSimpleName());
					}
					return null;
				}
			}
		}
	    */
	    
//        if (fieldVal == null) {
//            if (TraceDebug.isDEBUG()) {
//                sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname);
//            }
//        }
		return fieldVal;
	}

	/**
	 * Find the process matching the given pid and cpu
	 * 
	 * If cpu is 0, the cpu value is not matched and the selection is based on
	 * pid value only
	 * 
	 * @param traceState
	 * @param cpu
	 * @param pid
	 * @return
	 */
	protected LttngProcessState lttv_state_find_process(
							LttngTraceState traceState, Long cpu, Long pid) {

		return traceState.findProcessState(pid, cpu, traceState.getTraceId());
	}

	@SuppressWarnings("nls")
	protected void sendNoFieldFoundMsg(TmfEventField[] fields,
			String expectedFieldName) {
		LttngEventField field;
		StringBuilder sb = new StringBuilder("Field not found, requested: "
				+ expectedFieldName);
		sb.append(" number of fields: " + fields.length + "Fields: ");
		for (int i = 0; i < fields.length; i++) {
			field = (LttngEventField) fields[i];
			sb.append(field.getName() + " ");
		}
	
		TraceDebug.debug(sb.toString(), 5);
	}

}

Back to the top