~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
21
21
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
22
22
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
23
 
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
24
23
import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
25
24
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 
25
import org.eclipse.linuxtools.ctf.core.event.types.SimpleDatatypeDefinition;
26
26
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
27
27
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
28
28
import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
32
32
 
33
33
/**
34
34
 * CTF trace packet reader. Reads the events of a packet of a trace file.
35
 
 * 
 
35
 *
36
36
 * @version 1.0
37
37
 * @author Matthew Khouzam
38
38
 * @author Simon Marchi
103
103
 
104
104
    private int lostSoFar;
105
105
 
 
106
    private int lostEventsInThisPacket;
 
107
 
106
108
    // ------------------------------------------------------------------------
107
109
    // Attributes
108
110
    // ------------------------------------------------------------------------
292
294
                 * Read CPU ID
293
295
                 */
294
296
 
295
 
                Definition cpuiddef = getStreamPacketContextDef()
296
 
                        .lookupDefinition("cpu_id"); //$NON-NLS-1$
297
 
                if (cpuiddef instanceof IntegerDefinition) {
298
 
                    currentCpu = (int) ((IntegerDefinition) cpuiddef)
299
 
                            .getValue();
 
297
                if (this.getCurrentPacket().getTarget() != null) {
 
298
                    this.currentCpu = (int) this.getCurrentPacket()
 
299
                            .getTargetId();
300
300
                }
301
301
                /*
302
302
                 * Read number of lost events
303
303
                 */
304
 
                Definition lostEventsdef = getStreamPacketContextDef()
305
 
                        .lookupDefinition("events_discarded"); //$NON-NLS-1$
306
 
                if (cpuiddef instanceof IntegerDefinition) {
307
 
                    lostEvents = (int) ((IntegerDefinition) lostEventsdef)
308
 
                            .getValue();
309
 
                }
 
304
 
 
305
                int totalLostEvents = (int) this.getCurrentPacket()
 
306
                        .getLostEvents();
 
307
                lostEventsInThisPacket = totalLostEvents - lostEvents;
 
308
                lostEvents = totalLostEvents;
 
309
                currentPacket.setLostEvents(lostEventsInThisPacket);
 
310
                lostSoFar = 0;
310
311
 
311
312
            }
312
313
 
344
345
     *             If there was a problem reading the trace
345
346
     */
346
347
    public EventDefinition readNextEvent() throws CTFReaderException {
347
 
        /* WARNING: This is very LTTng-specific. */
 
348
        /* WARNING: This is still LTTng-specific. */
348
349
        Long eventID = null;
349
350
        long timestamp = 0;
350
351
 
351
 
        if (lostEvents > lostSoFar) {
 
352
        if (lostEventsInThisPacket > lostSoFar) {
352
353
            EventDefinition eventDef = EventDeclaration
353
354
                    .getLostEventDeclaration().createDefinition(
354
355
                            streamInputReader);
369
370
            /*
370
371
             * Check for an event id.
371
372
             */
372
 
            EnumDefinition idEnumDef = (EnumDefinition) sehd
 
373
            SimpleDatatypeDefinition idDef = (SimpleDatatypeDefinition) sehd
373
374
                    .lookupDefinition("id"); //$NON-NLS-1$
374
 
            assert (idEnumDef != null);
375
 
 
376
 
            eventID = idEnumDef.getIntegerValue();
 
375
            IntegerDefinition timestampDef = sehd.lookupInteger("timestamp"); //$NON-NLS-1$
 
376
            eventID = idDef.getIntegerValue();
377
377
 
378
378
            /*
379
379
             * Check for the variant v.
380
380
             */
381
381
            VariantDefinition variantDef = (VariantDefinition) sehd
382
382
                    .lookupDefinition("v"); //$NON-NLS-1$
383
 
            assert (variantDef != null);
384
 
 
385
 
            /*
386
 
             * Get the variant current field
387
 
             */
388
 
            StructDefinition variantCurrentField = (StructDefinition) variantDef
389
 
                    .getCurrentField();
390
 
            assert (variantCurrentField != null);
391
 
 
392
 
            /*
393
 
             * Try to get the id field in the current field of the variant. If
394
 
             * it is present, it overrides the previously read event id.
395
 
             */
396
 
            IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField
397
 
                    .lookupDefinition("id"); //$NON-NLS-1$
398
 
            if (idIntegerDef != null) {
399
 
                eventID = idIntegerDef.getValue();
 
383
            if (variantDef != null) {
 
384
 
 
385
                /*
 
386
                 * Get the variant current field
 
387
                 */
 
388
                StructDefinition variantCurrentField = (StructDefinition) variantDef
 
389
                        .getCurrentField();
 
390
 
 
391
                /*
 
392
                 * Try to get the id field in the current field of the variant.
 
393
                 * If it is present, it overrides the previously read event id.
 
394
                 */
 
395
                IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField
 
396
                        .lookupDefinition("id"); //$NON-NLS-1$
 
397
                if (idIntegerDef != null) {
 
398
                    eventID = idIntegerDef.getValue();
 
399
                }
 
400
                /*
 
401
                 * Get the timestamp.
 
402
                 */
 
403
                timestampDef = (IntegerDefinition) variantCurrentField
 
404
                        .lookupDefinition("timestamp"); //$NON-NLS-1$
 
405
 
400
406
            }
401
407
 
402
408
            /*
403
 
             * Get the timestamp.
404
 
             */
405
 
            IntegerDefinition timestampDef = (IntegerDefinition) variantCurrentField
406
 
                    .lookupDefinition("timestamp"); //$NON-NLS-1$
407
 
            assert (timestampDef != null);
408
 
 
409
 
            /*
410
409
             * Calculate the event timestamp.
411
410
             */
412
411
            timestamp = calculateTimestamp(timestampDef);
413
412
        }
414
413
 
 
414
        EventDefinition eventDef = events.get(eventID);
 
415
        if (eventDef == null) {
 
416
            throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$
 
417
        }
 
418
 
415
419
        /*
416
420
         * Read the stream event context.
417
421
         */
422
426
        /*
423
427
         * Get the right event definition using the event id.
424
428
         */
425
 
        EventDefinition eventDef = events.get(eventID);
426
 
        if (eventDef == null) {
427
 
            throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$
428
 
        }
 
429
 
429
430
 
430
431
        /*
431
432
         * Read the event context.
432
433
         */
433
 
        if (eventDef.getContext() != null) {
434
 
            eventDef.getContext().read(currentBitBuffer);
 
434
        if (eventDef.getEventContext() != null) {
 
435
            eventDef.getEventContext().read(currentBitBuffer);
435
436
        }
436
437
 
437
438
        /*