Class HistogramDataModel
- All Implemented Interfaces:
IBaseDistributionModel,IHistogramDataModel
- 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)
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default number of bucketsstatic final intNumber of events after which listeners will be notified. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor with default number of buckets.HistogramDataModel(int nbBuckets) Constructor with non-default number of buckets.HistogramDataModel(long startTime) Default constructor with default number of buckets.HistogramDataModel(long startTime, int nbBuckets) Constructor with non-default number of buckets.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHistogramListener(IHistogramModelListener listener) Add a listener to the model to be informed about model changes.voidclear()Clear the histogram model.voidcomplete()Complete the model (all data received)voidcountEvent(long eventCount, long timestamp, ITmfTrace trace) Add event to the correct bucket, compacting the if needed.voidcountLostEvent(TmfTimeRange timeRange, long nbLostEvents, boolean fullRange) Add lost event to the correct bucket, compacting the if needed.voiddispose()Disposes the data modellongReturns the current bucket duration.longReturns the end time.longReturns the time value of the first bucket in the model.intReturns the number of buckets in the model.longReturns the number of events in the data model.intGets the number of traces of this model.longReturns the begin time of the current selection in the model.longReturns the end time of the current selection in the model.longReturns the time of the first event in the model.longReturns the time limit with is: start time + nbBuckets * bucketDurationgetTrace()Gets the trace of this model.String[]Gets the traces names of this model.voidRemove a given model listener.scaleTo(int width, int height, int barWidth) Scale the model data to the width, height and bar width requested.voidsetEndTime(long endTime) Set the end time.voidsetSelection(long beginTime, long endTime) Sets the current selection time range (no notification of listeners)voidsetSelectionNotifyListeners(long beginTime, long endTime) Sets the current selection time range with notification of listenersvoidsetTimeRange(long startTime, long endTime) Sets the model start timevoidSets the trace of this model.
-
Field Details
-
DEFAULT_NUMBER_OF_BUCKETS
public static final int DEFAULT_NUMBER_OF_BUCKETSThe default number of buckets- See Also:
-
REFRESH_FREQUENCY
public static final int REFRESH_FREQUENCYNumber 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 timenbBuckets- A number of buckets.
-
HistogramDataModel
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
Sets the trace of this model.- Parameters:
trace- - aITmfTrace
-
getTrace
Gets the trace of this model.- Returns:
- a
ITmfTrace
-
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 timeendTime- 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
Add a listener to the model to be informed about model changes.- Parameters:
listener- A listener to add.
-
removeHistogramListener
Remove a given model listener.- Parameters:
listener- A listener to remove.
-
complete
public void complete()Description copied from interface:IBaseDistributionModelComplete the model (all data received)- Specified by:
completein interfaceIBaseDistributionModel
-
clear
public void clear()Clear the histogram model.- Specified by:
clearin interfaceIBaseDistributionModel- 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
Add event to the correct bucket, compacting the if needed.- Specified by:
countEventin interfaceIHistogramDataModel- Parameters:
eventCount- The current event Count (for notification purposes)timestamp- The timestamp of the event to counttrace- The event trace
-
countLostEvent
Add lost event to the correct bucket, compacting the if needed.- Parameters:
timeRange- time range of a lost eventnbLostEvents- the number of lost eventsfullRange- Full range or time range for histogram request
-
scaleTo
Scale the model data to the width, height and bar width requested.- Specified by:
scaleToin interfaceIHistogramDataModel- Parameters:
width- A width of the histogram canvasheight- A height of the histogram canvasbarWidth- 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:
-