Class HistogramDataModel

java.lang.Object
org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramDataModel
All Implemented Interfaces:
IBaseDistributionModel, IHistogramDataModel

public class HistogramDataModel extends Object implements IHistogramDataModel
Histogram-independent data model. It has the following characteristics:
  • The basetime is the timestamp of the first event
  • There is a fixed number (n) of buckets of uniform duration ( d)
  • The timespan of the model is thus: n * d time units
  • Bucket i holds the number of events that occurred in time range: [ basetime + i * d, basetime + (i + 1) * d)
Initially, the bucket durations is set to 1ns. As the events are read, they are tallied (using countEvent()) in the appropriate bucket (relative to the basetime).

Eventually, an event will have a timestamp that exceeds the timespan high end (determined by n, the number of buckets, and d, the bucket duration). At this point, the histogram needs to be compacted. This is done by simply merging adjacent buckets by pair, in effect doubling the timespan (timespan' = n * d', where d' = 2 d). This compaction happens as needed as the trace is read.

The model allows for timestamps in not increasing order. The timestamps can be fed to the model in any order. If an event has a timestamp less than the basetime, the buckets will be moved to the right to account for the new smaller timestamp. The new basetime is a multiple of the bucket duration smaller then the previous basetime. Note that the basetime might no longer be the timestamp of an event. If necessary, the buckets will be compacted before moving to the right. This might be necessary to not lose any event counts at the end of the buckets array.

The mapping from the model to the UI is performed by the scaleTo() method. By keeping the number of buckets n relatively large with respect to to the number of pixels in the actual histogram, we should achieve a nice result when visualizing the histogram.

Version:
2.0
Author:
Francois Chouinard
  • Field Details

    • DEFAULT_NUMBER_OF_BUCKETS

      public static final int DEFAULT_NUMBER_OF_BUCKETS
      The default number of buckets
      See Also:
    • REFRESH_FREQUENCY

      public static final int REFRESH_FREQUENCY
      Number of events after which listeners will be notified.
      See Also:
  • Constructor Details

    • HistogramDataModel

      public HistogramDataModel()
      Default constructor with default number of buckets.
    • HistogramDataModel

      public HistogramDataModel(long startTime)
      Default constructor with default number of buckets.
      Parameters:
      startTime - The histogram start time
    • HistogramDataModel

      public HistogramDataModel(int nbBuckets)
      Constructor with non-default number of buckets.
      Parameters:
      nbBuckets - A number of buckets.
    • HistogramDataModel

      public HistogramDataModel(long startTime, int nbBuckets)
      Constructor with non-default number of buckets.
      Parameters:
      startTime - the histogram start time
      nbBuckets - A number of buckets.
    • HistogramDataModel

      public HistogramDataModel(HistogramDataModel other)
      Copy constructor.
      Parameters:
      other - A model to copy.
  • Method Details

    • dispose

      public void dispose()
      Disposes the data model
    • getNbEvents

      public long getNbEvents()
      Returns the number of events in the data model.
      Returns:
      number of events.
    • getNbBuckets

      public int getNbBuckets()
      Returns the number of buckets in the model.
      Returns:
      number of buckets.
    • getBucketDuration

      public long getBucketDuration()
      Returns the current bucket duration.
      Returns:
      bucket duration
    • getFirstBucketTime

      public long getFirstBucketTime()
      Returns the time value of the first bucket in the model.
      Returns:
      time of first bucket.
    • getStartTime

      public long getStartTime()
      Returns the time of the first event in the model.
      Returns:
      time of first event.
    • setTrace

      public void setTrace(ITmfTrace trace)
      Sets the trace of this model.
      Parameters:
      trace - - a ITmfTrace
    • getTrace

      public ITmfTrace getTrace()
      Gets the trace of this model.
      Returns:
      a ITmfTrace
    • getTraceNames

      public String[] getTraceNames()
      Gets the traces names of this model.
      Returns:
      an array of trace names
    • getNbTraces

      public int getNbTraces()
      Gets the number of traces of this model.
      Returns:
      the number of traces of this model.
    • setTimeRange

      public void setTimeRange(long startTime, long endTime)
      Sets the model start time
      Parameters:
      startTime - the histogram range start time
      endTime - the histogram range end time
    • setEndTime

      public void setEndTime(long endTime)
      Set the end time. Setting this ensures that the corresponding bucket is displayed regardless of the event counts.
      Parameters:
      endTime - the time of the last used bucket
    • getEndTime

      public long getEndTime()
      Returns the end time.
      Returns:
      the time of the last used bucket
    • getSelectionBegin

      public long getSelectionBegin()
      Returns the begin time of the current selection in the model.
      Returns:
      the begin time of the current selection.
    • getSelectionEnd

      public long getSelectionEnd()
      Returns the end time of the current selection in the model.
      Returns:
      the end time of the current selection.
    • getTimeLimit

      public long getTimeLimit()
      Returns the time limit with is: start time + nbBuckets * bucketDuration
      Returns:
      the time limit.
    • addHistogramListener

      public void addHistogramListener(IHistogramModelListener listener)
      Add a listener to the model to be informed about model changes.
      Parameters:
      listener - A listener to add.
    • removeHistogramListener

      public void removeHistogramListener(IHistogramModelListener listener)
      Remove a given model listener.
      Parameters:
      listener - A listener to remove.
    • complete

      public void complete()
      Description copied from interface: IBaseDistributionModel
      Complete the model (all data received)
      Specified by:
      complete in interface IBaseDistributionModel
    • clear

      public void clear()
      Clear the histogram model.
      Specified by:
      clear in interface IBaseDistributionModel
      See Also:
    • setSelection

      public void setSelection(long beginTime, long endTime)
      Sets the current selection time range (no notification of listeners)
      Parameters:
      beginTime - The selection begin time.
      endTime - The selection end time.
    • setSelectionNotifyListeners

      public void setSelectionNotifyListeners(long beginTime, long endTime)
      Sets the current selection time range with notification of listeners
      Parameters:
      beginTime - The selection begin time.
      endTime - The selection end time.
    • countEvent

      public void countEvent(long eventCount, long timestamp, ITmfTrace trace)
      Add event to the correct bucket, compacting the if needed.
      Specified by:
      countEvent in interface IHistogramDataModel
      Parameters:
      eventCount - The current event Count (for notification purposes)
      timestamp - The timestamp of the event to count
      trace - The event trace
    • countLostEvent

      public void countLostEvent(TmfTimeRange timeRange, long nbLostEvents, boolean fullRange)
      Add lost event to the correct bucket, compacting the if needed.
      Parameters:
      timeRange - time range of a lost event
      nbLostEvents - the number of lost events
      fullRange - Full range or time range for histogram request
    • scaleTo

      public HistogramScaledData scaleTo(int width, int height, int barWidth)
      Scale the model data to the width, height and bar width requested.
      Specified by:
      scaleTo in interface IHistogramDataModel
      Parameters:
      width - A width of the histogram canvas
      height - A height of the histogram canvas
      barWidth - A width (in pixel) of a histogram bar
      Returns:
      the result array of size [width] and where the highest value doesn't exceed [height]
      See Also: