Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * William Bourque (wbourque@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.lttng.trace; | |
14 | ||
15 | import java.io.BufferedReader; | |
16 | import java.io.FileReader; | |
17 | import java.io.IOException; | |
18 | import java.util.HashMap; | |
19 | ||
20 | import org.eclipse.linuxtools.lttng.event.LttngEvent; | |
21 | import org.eclipse.linuxtools.lttng.event.LttngEventContent; | |
22 | import org.eclipse.linuxtools.lttng.event.LttngEventField; | |
23 | import org.eclipse.linuxtools.lttng.event.LttngEventReference; | |
24 | import org.eclipse.linuxtools.lttng.event.LttngEventSource; | |
25 | import org.eclipse.linuxtools.lttng.event.LttngEventType; | |
26 | import org.eclipse.linuxtools.lttng.event.LttngTimestamp; | |
27 | import org.eclipse.linuxtools.lttng.jni.JniEvent; | |
cbd4ad82 | 28 | import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException; |
5d10d135 | 29 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; |
9f584e4c | 30 | import org.eclipse.linuxtools.tmf.trace.ITmfLocation; |
9f584e4c FC |
31 | import org.eclipse.linuxtools.tmf.trace.TmfCheckpoint; |
32 | import org.eclipse.linuxtools.tmf.trace.TmfContext; | |
33 | import org.eclipse.linuxtools.tmf.trace.TmfLocation; | |
5d10d135 ASL |
34 | import org.eclipse.linuxtools.tmf.trace.TmfTrace; |
35 | ||
12c155f5 | 36 | public class LTTngTextTrace extends TmfTrace<LttngEvent> { |
5d10d135 ASL |
37 | private LttngTimestamp eventTimestamp = null; |
38 | private LttngEventSource eventSource = null; | |
39 | private LttngEventType eventType = null; | |
40 | private TextLttngEventContent eventContent = null; | |
41 | private LttngEventReference eventReference = null; | |
42 | // The actual event | |
43 | private TextLttngEvent currentLttngEvent = null; | |
44 | ||
45 | private HashMap<String, LttngEventType> traceTypes = null; | |
46 | ||
9c4eb5f7 | 47 | private String tracepath = ""; //$NON-NLS-1$ |
5d10d135 ASL |
48 | private FileReader fr = null; |
49 | private BufferedReader br = null; | |
50 | private Long nbCharRead = 0L; | |
51 | ||
52 | private int cpuNumber = -1; | |
53 | ||
a55a769e | 54 | private boolean showDebug = false; |
5d10d135 ASL |
55 | |
56 | public LTTngTextTrace(String path) throws Exception { | |
8016d660 | 57 | this(path, true); // false); |
5d10d135 ASL |
58 | } |
59 | ||
60 | public LTTngTextTrace(String path, boolean skipIndexing) throws Exception { | |
05bd3318 | 61 | super(path, LttngEvent.class, path, 1, !skipIndexing); |
5d10d135 ASL |
62 | |
63 | tracepath = path; | |
64 | traceTypes = new HashMap<String, LttngEventType>(); | |
65 | ||
66 | eventTimestamp = new LttngTimestamp(); | |
67 | eventSource = new LttngEventSource(); | |
68 | eventType = new LttngEventType(); | |
69 | eventContent = new TextLttngEventContent(currentLttngEvent); | |
70 | eventReference = new LttngEventReference(this.getName()); | |
71 | ||
b7f0ec69 | 72 | currentLttngEvent = new TextLttngEvent(this, eventTimestamp, eventSource, eventType, eventContent, eventReference); |
5d10d135 ASL |
73 | eventContent.setEvent(currentLttngEvent); |
74 | ||
75 | if ( positionToFirstEvent() == false ) { | |
9c4eb5f7 | 76 | throw new IOException("Fail to position to the beginning of the trace"); //$NON-NLS-1$ |
5d10d135 ASL |
77 | } |
78 | else { | |
9f584e4c | 79 | fIndexPageSize = 1000; |
5d10d135 ASL |
80 | |
81 | // Skip indexing if asked | |
550d787e | 82 | // if ( skipIndexing == true ) { |
9f584e4c | 83 | fCheckpoints.add(new TmfCheckpoint(new LttngTimestamp(0L), new TmfLocation<Long>(0L))); |
550d787e FC |
84 | // } |
85 | // else { | |
86 | // indexTrace(true); | |
87 | // } | |
5d10d135 ASL |
88 | |
89 | Long endTime = currentLttngEvent.getTimestamp().getValue(); | |
90 | positionToFirstEvent(); | |
91 | ||
9f584e4c | 92 | getNextEvent(new TmfContext(null, 0)); |
5d10d135 ASL |
93 | Long starTime = currentLttngEvent.getTimestamp().getValue(); |
94 | positionToFirstEvent(); | |
95 | ||
96 | setTimeRange( new TmfTimeRange( new LttngTimestamp(starTime), | |
97 | new LttngTimestamp(endTime) | |
98 | ) ); | |
99 | } | |
100 | } | |
101 | ||
102 | ||
369aca6e WB |
103 | public LTTngTextTrace(LTTngTextTrace oldTrace) throws Exception { |
104 | this(oldTrace.getPath(), true); | |
105 | ||
106 | // *** VERIFY *** | |
107 | // Is this safe? | |
108 | fCheckpoints = oldTrace.fCheckpoints; | |
5d10d135 ASL |
109 | } |
110 | ||
d4011df2 | 111 | @Override |
12c155f5 | 112 | public LTTngTextTrace copy() { |
369aca6e WB |
113 | |
114 | LTTngTextTrace returnedTrace = null; | |
115 | ||
116 | try { | |
117 | returnedTrace = new LTTngTextTrace(this); | |
118 | } | |
119 | catch (Exception e) { | |
9c4eb5f7 | 120 | System.out.println("ERROR : Could not create LTTngTextTrace copy (createTraceCopy).\nError is : " + e.getStackTrace()); //$NON-NLS-1$ |
369aca6e WB |
121 | } |
122 | ||
123 | return returnedTrace; | |
124 | } | |
125 | ||
5d10d135 ASL |
126 | private boolean positionToFirstEvent() { |
127 | ||
128 | boolean isSuccessful = true; | |
129 | ||
130 | try { | |
131 | if ( br != null ) { | |
132 | br.close(); | |
133 | fr.close(); | |
134 | } | |
135 | ||
136 | fr = new FileReader(tracepath); | |
137 | br = new BufferedReader(fr); | |
138 | ||
139 | // Skip the 2 lines header | |
140 | br.readLine(); | |
141 | br.readLine(); | |
142 | ||
143 | // Make sure the event time is consistent | |
144 | eventTimestamp.setValue(0L); | |
145 | } | |
550d787e | 146 | catch (IOException e) { |
5d10d135 ASL |
147 | isSuccessful = false; |
148 | } | |
149 | ||
150 | return isSuccessful; | |
151 | } | |
152 | ||
9f584e4c | 153 | private void skipToPosition(TmfLocation<Long> skip) { |
5d10d135 | 154 | try { |
452ad365 | 155 | long skipPosition = skip.getLocation(); |
e31e01e8 FC |
156 | if ( skipPosition < 0 ) { |
157 | skipPosition = 0L; | |
158 | } | |
159 | ||
5d10d135 | 160 | if ( showDebug == true ) { |
9c4eb5f7 FC |
161 | System.out.println("skipToPosition(Long skipPosition)"); //$NON-NLS-1$ |
162 | System.out.println("\tSkipping to : " + skipPosition); //$NON-NLS-1$ | |
5d10d135 ASL |
163 | System.out.println(); |
164 | } | |
165 | positionToFirstEvent(); | |
b20696db WB |
166 | long nbSkipped = br.skip(skipPosition); |
167 | if ( nbSkipped != skipPosition) { | |
9c4eb5f7 | 168 | throw new IOException("Too few characters skipped, positionning failed! (skipToPosition)"); //$NON-NLS-1$ |
b20696db | 169 | } |
5d10d135 ASL |
170 | |
171 | nbCharRead = skipPosition; | |
172 | } | |
173 | catch (Exception e) { | |
174 | e.printStackTrace(); | |
175 | } | |
176 | } | |
177 | ||
452ad365 FC |
178 | @Override |
179 | @SuppressWarnings("unchecked") | |
180 | public TmfContext seekLocation(ITmfLocation<?> location) { | |
5d10d135 | 181 | if (location == null) { |
9f584e4c | 182 | location = new TmfLocation<Long>(0L); |
5d10d135 | 183 | } |
88144d4a | 184 | |
452ad365 | 185 | if (!((TmfLocation<Long>) location).getLocation().equals(nbCharRead)) { |
9f584e4c | 186 | skipToPosition((TmfLocation<Long>) location); |
88144d4a | 187 | } |
e31e01e8 | 188 | |
9f584e4c | 189 | TmfContext tmpTraceContext = new TmfContext(location, 0L); |
88144d4a | 190 | |
e31e01e8 | 191 | return tmpTraceContext; |
88144d4a ASL |
192 | } |
193 | ||
90e2b925 FC |
194 | @Override |
195 | public TmfContext seekLocation(double ratio) { | |
196 | // TODO Auto-generated method stub | |
197 | return null; | |
198 | } | |
199 | ||
200 | @Override | |
201 | public double getLocationRatio(ITmfLocation<?> location) { | |
202 | // TODO Auto-generated method stub | |
203 | return 0; | |
204 | } | |
205 | ||
206 | private LttngEvent parseMyNextEvent(TmfContext context) { | |
5d10d135 ASL |
207 | |
208 | // All parsing variables declared here so to be able to print them into the catch if needed | |
209 | String tmpContent = null; | |
210 | int tmpCurIndex = 0; | |
211 | int tmpPrevIndex = 0; | |
212 | ||
9c4eb5f7 | 213 | String tracefile = ""; //$NON-NLS-1$ |
5d10d135 | 214 | long tmpCpu = 0; |
9c4eb5f7 | 215 | String marker = ""; //$NON-NLS-1$ |
5d10d135 ASL |
216 | |
217 | long tmpSecond = 0; | |
218 | long tmpNanosecond = 0; | |
219 | ||
9c4eb5f7 FC |
220 | String parsedPayload = ""; //$NON-NLS-1$ |
221 | String markerName = ""; //$NON-NLS-1$ | |
222 | Object payload = ""; //$NON-NLS-1$ | |
5d10d135 ASL |
223 | |
224 | HashMap<String, LttngEventField> fieldsMap = null; | |
225 | ||
226 | LttngEvent returnedEvent = null; | |
227 | ||
228 | try { | |
229 | tmpContent = br.readLine(); | |
230 | ||
231 | if (tmpContent != null) { | |
232 | // *** NOTE : | |
233 | // -1 is the skip the end of line (\n) | |
234 | nbCharRead += (tmpContent.length()+1); | |
235 | ||
236 | if ( (currentLttngEvent != null) && (currentLttngEvent.getContent().getRawContent() != null) ) { | |
237 | currentLttngEvent.getContent().emptyContent(); | |
238 | } | |
239 | ||
240 | // EventSource is always the same for now : | |
9c4eb5f7 | 241 | eventSource.setSourceId("Kernel Core"); //$NON-NLS-1$ |
5d10d135 ASL |
242 | |
243 | ||
244 | // Tracefile and marker are first in the file | |
245 | // Sound like : | |
246 | // kernel.syscall_entry: | |
9c4eb5f7 | 247 | tmpCurIndex = tmpContent.indexOf(".", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
248 | |
249 | // *** HACK *** | |
250 | // Evil exit case here : the two last line of the text dump does not contain "." | |
e31e01e8 | 251 | // We should check in a better way (string comparison and such) but it make the whole process to weight a lot more |
5d10d135 ASL |
252 | // Conclusion : this is ugly but fast. |
253 | if ( tmpCurIndex < 0 ) { | |
254 | if ( showDebug == true ) { | |
9c4eb5f7 | 255 | System.out.println("END OF FILE."); //$NON-NLS-1$ |
5d10d135 ASL |
256 | System.out.println(); |
257 | } | |
e31e01e8 | 258 | return null; |
5d10d135 ASL |
259 | } |
260 | ||
261 | tracefile = tmpContent.substring(tmpPrevIndex, tmpCurIndex ).trim(); | |
262 | /*System.out.println(tracefile);*/ | |
263 | ||
264 | tmpPrevIndex = tmpCurIndex; | |
9c4eb5f7 | 265 | tmpCurIndex = tmpContent.indexOf(":", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
266 | marker = tmpContent.substring(tmpPrevIndex+1, tmpCurIndex ).trim(); |
267 | /*System.out.println(marker);*/ | |
268 | ||
269 | // Timestamp is next but is presented in second.milisecond format, we have to split them | |
270 | // Sound like : | |
271 | // 952.162637168 | |
272 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 273 | tmpCurIndex = tmpContent.indexOf(".", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
274 | tmpSecond = Long.parseLong( tmpContent.substring(tmpPrevIndex, tmpCurIndex ).trim() ); |
275 | /*System.out.println(tmpSecond);*/ | |
276 | ||
277 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 278 | tmpCurIndex = tmpContent.indexOf(" ", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
279 | tmpNanosecond = Long.parseLong( tmpContent.substring(tmpPrevIndex, tmpCurIndex ).trim() ); |
280 | /*System.out.println(tmpNanosecond);*/ | |
281 | ||
282 | // We have enough information here to set the timestamp | |
283 | eventTimestamp.setValue( (tmpSecond * 1000000000) + tmpNanosecond ); | |
284 | /*System.out.println(eventTimestamp.toString());*/ | |
285 | ||
286 | // Next field is the reference | |
287 | // A long string enclosed by parenthesis and ending with a comma | |
288 | // (/home/william/workspace/org.eclipse.linuxtools.lttng.tests/traceset/trace-618339events-1293lost-1cpu/kernel_0), | |
289 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 290 | tmpCurIndex = tmpContent.indexOf("(", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 | 291 | tmpPrevIndex = tmpCurIndex+1; |
9c4eb5f7 | 292 | tmpCurIndex = tmpContent.indexOf("),", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
293 | String fullTracePath = tmpContent.substring(tmpPrevIndex, tmpCurIndex ).trim(); |
294 | /*System.out.println(fullTracePath);*/ | |
295 | ||
296 | eventReference.setValue(fullTracePath); | |
9c4eb5f7 | 297 | String traceName = fullTracePath.substring(fullTracePath.lastIndexOf("/")+1).trim(); //$NON-NLS-1$ |
5d10d135 ASL |
298 | /*System.out.println(traceName);*/ |
299 | eventReference.setTracepath(traceName); | |
300 | ||
301 | ||
302 | // The next few fields are relatives to the state system (pid, ppid, etc...) we need to skip them. | |
303 | // They should be like the following : | |
304 | // 4175, 4175, hal-acl-tool, , 4168, | |
305 | ||
306 | // 1st comma | |
307 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 308 | tmpCurIndex = tmpContent.indexOf(",", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
309 | // 2nd comma |
310 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 311 | tmpCurIndex = tmpContent.indexOf(",", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
312 | // 3rd comma |
313 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 314 | tmpCurIndex = tmpContent.indexOf(",", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
315 | // 4th comma |
316 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 317 | tmpCurIndex = tmpContent.indexOf(",", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
318 | // 5th comma |
319 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 320 | tmpCurIndex = tmpContent.indexOf(",", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
321 | // 6th comma |
322 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 323 | tmpCurIndex = tmpContent.indexOf(",", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
324 | |
325 | // The next field is the CPU, in hexadecimal format | |
326 | // Should be like : | |
327 | // 0x0, | |
328 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 329 | tmpCurIndex = tmpContent.indexOf("0x", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
330 | tmpPrevIndex = tmpCurIndex+2; |
331 | ||
9c4eb5f7 | 332 | tmpCurIndex = tmpContent.indexOf(",", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
333 | tmpCpu = Long.parseLong( tmpContent.substring(tmpPrevIndex, tmpCurIndex ).trim() ); |
334 | ||
335 | // Set the cpu number of trace if we found a "new" cpu | |
336 | if ( cpuNumber < (tmpCpu + 1) ) { | |
337 | cpuNumber = (int)(tmpCpu+1); | |
338 | } | |
339 | /*System.out.println(tmpCpu);*/ | |
340 | ||
341 | ||
342 | // The last field is the parsed content | |
343 | // It is enclosed by { } | |
344 | // Look like : | |
345 | // SYSCALL { ip = 0xb7f05422, syscall_id = 221 [sys_fcntl64+0x0/0x79] } | |
346 | // | |
2d32a807 WB |
347 | // NOTE : it seems some state system events do not respect this format as they have no payload. |
348 | // We will create empty payload then. | |
9c4eb5f7 | 349 | int tmpIndex = tmpContent.indexOf("{", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
350 | if ( tmpIndex != -1 ) { |
351 | tmpPrevIndex = tmpCurIndex+1; | |
352 | tmpCurIndex = tmpIndex; | |
353 | tmpPrevIndex = tmpCurIndex+1; | |
9c4eb5f7 | 354 | tmpCurIndex = tmpContent.indexOf("}", tmpPrevIndex); //$NON-NLS-1$ |
5d10d135 ASL |
355 | parsedPayload = tmpContent.substring(tmpPrevIndex, tmpCurIndex ).trim(); |
356 | ||
357 | // Now add each LttngField | |
358 | boolean isDone = false; | |
359 | int tmpIndexBegin = 0; | |
360 | int tmpIndexEqual = 0; | |
361 | int tmpIndexEnd = 0; | |
362 | ||
363 | fieldsMap = new HashMap<String, LttngEventField>(); | |
364 | ||
365 | while ( isDone == false ) { | |
9c4eb5f7 FC |
366 | tmpIndexEqual = parsedPayload.indexOf("=", (int)tmpIndexBegin); //$NON-NLS-1$ |
367 | tmpIndexEnd = parsedPayload.indexOf(", ", (int)tmpIndexEqual); //$NON-NLS-1$ | |
5d10d135 ASL |
368 | if ( tmpIndexEnd == -1 ) { |
369 | tmpIndexEnd = parsedPayload.length(); | |
370 | isDone = true; | |
371 | } | |
372 | ||
373 | markerName = parsedPayload.substring((int)tmpIndexBegin, (int)tmpIndexEqual-1 ).trim(); | |
9c4eb5f7 | 374 | payload = ((String)parsedPayload.substring((int)tmpIndexEqual+1, (int)tmpIndexEnd )).replace("\"", " ").trim(); //$NON-NLS-1$ //$NON-NLS-2$ |
5d10d135 ASL |
375 | |
376 | // Try to cast the payload into the correct type | |
377 | try { | |
378 | payload = Long.parseLong((String)payload); | |
379 | } | |
380 | catch (NumberFormatException e) { } | |
381 | ||
382 | LttngEventField tmpField = new LttngEventField(eventContent, markerName, payload); | |
383 | fieldsMap.put(markerName, tmpField); | |
384 | ||
385 | tmpIndexBegin = tmpIndexEnd+1; | |
386 | } | |
2d32a807 WB |
387 | } |
388 | else { | |
389 | fieldsMap = new HashMap<String, LttngEventField>(); | |
a3fe52fc | 390 | |
9c4eb5f7 FC |
391 | markerName = ""; //$NON-NLS-1$ |
392 | payload = ""; //$NON-NLS-1$ | |
2d32a807 WB |
393 | |
394 | LttngEventField tmpField = new LttngEventField(eventContent, markerName, payload); | |
395 | fieldsMap.put(markerName, tmpField); | |
5d10d135 ASL |
396 | } |
397 | ||
2d32a807 WB |
398 | eventContent = new TextLttngEventContent(currentLttngEvent, fieldsMap); |
399 | ||
400 | // We now have what we need for the type | |
9c4eb5f7 | 401 | String tmpTypeKey = tracefile + "/" + tmpCpu + "/" + marker; //$NON-NLS-1$ //$NON-NLS-2$ |
2d32a807 | 402 | if ( traceTypes.get(tmpTypeKey) == null ) { |
b12f4544 | 403 | traceTypes.put(tmpTypeKey, new LttngEventType(tracefile, tmpCpu, marker, 0, fieldsMap.keySet().toArray(new String[fieldsMap.size()] )) ); |
2d32a807 WB |
404 | } |
405 | ||
406 | currentLttngEvent.setContent(eventContent); | |
407 | currentLttngEvent.setType(traceTypes.get(tmpTypeKey)); | |
408 | ||
5d10d135 ASL |
409 | returnedEvent = currentLttngEvent; |
410 | } | |
411 | else if ( showDebug == true ) { | |
9c4eb5f7 | 412 | System.out.println("NULL READING"); //$NON-NLS-1$ |
5d10d135 | 413 | System.out.println(); |
2d32a807 | 414 | returnedEvent = null; |
5d10d135 ASL |
415 | } |
416 | } | |
417 | catch (Exception e) { | |
9c4eb5f7 | 418 | System.out.println("Pos is :" + nbCharRead); //$NON-NLS-1$ |
5d10d135 | 419 | if ( tmpContent != null ) { |
9c4eb5f7 | 420 | System.out.println("Erroneous content is :" + tmpContent); //$NON-NLS-1$ |
5d10d135 ASL |
421 | } |
422 | ||
423 | tmpContent = null; | |
424 | e.printStackTrace(); | |
2d32a807 | 425 | returnedEvent = null; |
5d10d135 ASL |
426 | } |
427 | ||
428 | return returnedEvent; | |
429 | } | |
430 | ||
431 | @Override | |
452ad365 | 432 | public ITmfLocation<?> getCurrentLocation() { |
9f584e4c | 433 | return new TmfLocation<Long>(nbCharRead); |
5d10d135 ASL |
434 | } |
435 | ||
e31e01e8 | 436 | @Override |
9f584e4c FC |
437 | public LttngEvent parseEvent(TmfContext context) { |
438 | context = seekLocation(context.getLocation()); | |
e31e01e8 | 439 | return parseMyNextEvent(context); |
88144d4a | 440 | |
5d10d135 ASL |
441 | } |
442 | ||
e31e01e8 | 443 | public int getCpuNumber() { |
5d10d135 ASL |
444 | return cpuNumber; |
445 | } | |
cb866e08 | 446 | |
5d10d135 ASL |
447 | } |
448 | ||
449 | ||
450 | // Redefine event to override method we know won't work with a Text tracefile | |
451 | class TextLttngEvent extends LttngEvent { | |
452 | ||
b7f0ec69 WB |
453 | public TextLttngEvent( TmfTrace<LttngEvent> parent, |
454 | LttngTimestamp timestamp, | |
5d10d135 ASL |
455 | LttngEventSource source, |
456 | LttngEventType type, | |
457 | LttngEventContent content, | |
458 | LttngEventReference reference) | |
459 | { | |
b7f0ec69 | 460 | super(parent, timestamp, source, type, content, reference, null); |
5d10d135 ASL |
461 | } |
462 | ||
2c8610f7 FC |
463 | @SuppressWarnings("unchecked") |
464 | public TextLttngEvent(TextLttngEvent oldEvent) { | |
5d10d135 | 465 | this( |
2c8610f7 | 466 | (TmfTrace<LttngEvent>) oldEvent.getParentTrace(), |
5d10d135 ASL |
467 | (LttngTimestamp)oldEvent.getTimestamp(), |
468 | (LttngEventSource)oldEvent.getSource(), | |
469 | (LttngEventType)oldEvent.getType(), | |
470 | (LttngEventContent)oldEvent.getContent(), | |
471 | (LttngEventReference)oldEvent.getReference() | |
472 | ); | |
473 | } | |
474 | ||
475 | @Override | |
476 | public JniEvent convertEventTmfToJni() { | |
b9763f53 | 477 | System.out.println("WARNING : Cannot use convertEventTmfToJni() on a trace in text format."); //$NON-NLS-1$ |
5d10d135 ASL |
478 | return null; |
479 | } | |
480 | ||
481 | @Override | |
482 | public void updateJniEventReference(JniEvent newJniEventReference) { | |
b9763f53 | 483 | System.out.println("WARNING : Cannot use updateJniEventReference on a trace in text format. Using null."); //$NON-NLS-1$ |
5d10d135 ASL |
484 | } |
485 | } | |
486 | ||
487 | ||
488 | class TextLttngEventContent extends LttngEventContent { | |
489 | ||
490 | public TextLttngEventContent() { | |
491 | super(); | |
492 | } | |
493 | ||
494 | public TextLttngEventContent(TextLttngEvent thisParent) { | |
495 | super(thisParent, null); | |
496 | } | |
497 | ||
498 | public TextLttngEventContent(TextLttngEvent thisParent, HashMap<String, LttngEventField> thisContent) { | |
499 | super(thisParent, thisContent); | |
500 | } | |
501 | ||
502 | public TextLttngEventContent(TextLttngEventContent oldContent) { | |
503 | this( (TextLttngEvent)oldContent.fParentEvent, oldContent.getRawContent()); | |
504 | } | |
505 | ||
506 | @Override | |
507 | public LttngEventField[] getFields() { | |
508 | return getRawContent().values().toArray(new LttngEventField[getRawContent().size()]); | |
509 | } | |
510 | ||
511 | @Override | |
512 | public LttngEventField getField(String name) { | |
513 | LttngEventField returnedField = getRawContent().get(name); | |
514 | ||
515 | return returnedField; | |
516 | } | |
517 | ||
518 | @Override | |
519 | public LttngEventField getField(int position) { | |
520 | LttngEventField returnedField = null; | |
cbd4ad82 FC |
521 | String label = null; |
522 | try { | |
523 | label = fParentEvent.getType().getLabel(position); | |
da838bad WB |
524 | returnedField = this.getField(label); |
525 | } | |
526 | catch (TmfNoSuchFieldException e) { | |
9c4eb5f7 | 527 | System.out.println("Invalid field position requested : " + position + ", ignoring (getField)."); //$NON-NLS-1$ //$NON-NLS-2$ |
cbd4ad82 | 528 | } |
88144d4a | 529 | |
5d10d135 ASL |
530 | return returnedField; |
531 | } | |
12c155f5 | 532 | } |