Add a generic 'lost events' event to TMF
authorFrancois Chouinard <fchouinard@gmail.com>
Thu, 9 Aug 2012 17:55:31 +0000 (13:55 -0400)
committerFrancois Chouinard <fchouinard@gmail.com>
Thu, 9 Aug 2012 18:03:55 +0000 (14:03 -0400)
Change-Id: Ic7d1189e3bca397a4bb7a775e7b1757dfde00926
Signed-off-by: Francois Chouinard <fchouinard@gmail.com>
Reviewed-on: https://git.eclipse.org/r/7100

org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfLostEvent.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfLostEvent.java [new file with mode: 0644]

diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfLostEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfLostEvent.java
new file mode 100644 (file)
index 0000000..4cc5f79
--- /dev/null
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.event;
+
+/**
+ * The generic lost event structure in TMF.
+ *
+ * In some demanding situations, tracers can be overwhelmed and have a hard time
+ * keeping up with the flow of events to record. Usually, even if a tracer can't
+ * keep up, it can at least record the number of events that it lost.
+ *
+ * This interface provides the different components (e.g. views) with a mean to
+ * identify and highlight such events.
+ *
+ * This interface extends ITmfEvent by adding the number of lost events for a
+ * 'problematic' time range.
+ *
+ * @see TmfLostEvent
+ *
+ * @author Francois Chouinard
+ * @version 1.0
+ * @since 1.2
+ */
+public interface ITmfLostEvent extends ITmfEvent {
+
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the 'problem' time range
+     */
+    public TmfTimeRange getTimeRange();
+
+    /**
+     * @return the number of lost events in the time range
+     */
+    public long getNbLostEvents();
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfLostEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfLostEvent.java
new file mode 100644 (file)
index 0000000..656137d
--- /dev/null
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.event;
+
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+
+/**
+ * A basic implementation of ITmfLostEvent.
+ *
+ * @author Francois Chouinard
+ * @version 1.0
+ * @since 1.2
+*/
+public class TmfLostEvent extends TmfEvent implements ITmfLostEvent {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private TmfTimeRange fTimeRange;
+    private long fNbLostEvents;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Default constructor which boils down to the default TmfEvent with no
+     * lost event over the empty time range.
+     */
+    public TmfLostEvent() {
+        this(null, ITmfContext.UNKNOWN_RANK, null, null, null, null, TmfTimeRange.NULL_RANGE, 0);
+    }
+
+    /**
+     * Full constructor
+     *
+     * @param trace the parent trace
+     * @param rank the event rank (in the trace)
+     * @param timestamp the event timestamp
+     * @param source the event source
+     * @param type the event type
+     * @param reference the event reference
+     * @param timeRange the 'problematic' time range
+     * @param nbLostEvents the number of lost events in the time range
+     */
+    public TmfLostEvent(final ITmfTrace<? extends ITmfEvent> trace, final long rank, final ITmfTimestamp timestamp,
+            final String source, final ITmfEventType type, final String reference, final TmfTimeRange timeRange, final long nbLostEvents)
+    {
+        super(trace, rank, timestamp, source, type, null, reference);
+        fTimeRange = timeRange;
+        fNbLostEvents = nbLostEvents;
+    }
+
+    /**
+     * Copy constructor
+     *
+     * @param event the original event
+     */
+    public TmfLostEvent(final ITmfLostEvent event) {
+        if (event == null) {
+            throw new IllegalArgumentException();
+        }
+        setTrace(event.getTrace());
+        setRank(event.getRank());
+        setTimestamp(event.getTimestamp());
+        setSource(event.getSource());
+        setType(event.getType());
+        setContent(event.getContent());
+        setReference(event.getReference());
+
+        fTimeRange = event.getTimeRange();
+        fNbLostEvents = event.getNbLostEvents();
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfLostEvent
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent#getTimeRange()
+     */
+    @Override
+    public TmfTimeRange getTimeRange() {
+        return fTimeRange;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent#getNbLostEvents()
+     */
+    @Override
+    public long getNbLostEvents() {
+        return fNbLostEvents;
+    }
+
+    // ------------------------------------------------------------------------
+    // Convenience setters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @param timeRange the 'problematic' time range
+     */
+    protected void setTimeRange(final TmfTimeRange timeRange) {
+        fTimeRange = timeRange;
+    }
+
+    /**
+     * @param nbLostEvents the number of lost events
+     */
+    protected void setNbLostEvents(final long nbLostEvents) {
+        fNbLostEvents = nbLostEvents;
+    }
+
+    // ------------------------------------------------------------------------
+    // Cloneable
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public TmfLostEvent clone() {
+        TmfLostEvent clone = null;
+        try {
+            clone = (TmfLostEvent) super.clone();
+            clone.fTimeRange = fTimeRange.clone();
+            clone.fNbLostEvents = fNbLostEvents;
+        } catch (CloneNotSupportedException e) {
+        }
+        return clone;
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + (int) (fNbLostEvents ^ (fNbLostEvents >>> 32));
+        result = prime * result + ((fTimeRange == null) ? 0 : fTimeRange.hashCode());
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (!(obj instanceof TmfLostEvent)) {
+            return false;
+        }
+        TmfLostEvent other = (TmfLostEvent) obj;
+        if (fNbLostEvents != other.fNbLostEvents) {
+            return false;
+        }
+        if (fTimeRange == null) {
+            if (other.fTimeRange != null) {
+                return false;
+            }
+        } else if (!fTimeRange.equals(other.fTimeRange)) {
+            return false;
+        }
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        return "TmfLostEvent [Event=" + super.toString() + ", fTimeRange=" + fTimeRange + ", fNbLostEvents=" + fNbLostEvents + "]";
+    }
+
+}
This page took 0.029355 seconds and 5 git commands to generate.