1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Added setter and getter and bar width support
12 * Francois Chouinard - Moved from LTTng to TMF
13 * Patrick Tasse - Support selection range
14 * Jean-Christian Kouamé - Support to manage lost events
15 * Xavier Raynaud - Support multi-trace coloring
16 *******************************************************************************/
18 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.histogram
;
20 import java
.util
.Arrays
;
23 * Convenience class/struct for scaled histogram data.
26 * @author Francois Chouinard
28 public class HistogramScaledData
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
35 * Indicator value that bucket is out of range (not filled).
37 public static final int OUT_OF_RANGE_BUCKET
= -1;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 * Width of histogram canvas (number of pixels).
47 * Height of histogram canvas (number of pixels).
51 * Width of one histogram bar (number of pixels).
55 * Array of scaled values
57 public HistogramBucket
[] fData
;
59 * Array of scaled values combined including the lost events.
60 * This array contains the number of lost events for each bar in the histogram
63 public final int[] fLostEventsData
;
65 * The bucket duration of a scaled data bucket.
67 public long fBucketDuration
;
69 * The maximum number of events of all buckets.
71 public long fMaxValue
;
73 * the maximum of events of all buckets including the lost events
76 public long fMaxCombinedValue
;
78 * The index of the selection begin bucket.
81 public int fSelectionBeginBucket
;
83 * The index of the selection end bucket.
86 public int fSelectionEndBucket
;
88 * The index of the last bucket.
90 public int fLastBucket
;
92 * The scaling factor used to fill the scaled data.
94 public double fScalingFactor
;
96 * The scaling factor used to fill the scaled data including the lost events.
99 public double fScalingFactorCombined
;
101 * The scaling factor used to fill the combining scaled data including lost events
104 * Time of first bucket.
106 public long fFirstBucketTime
;
108 * The time of the first event.
110 public long fFirstEventTime
;
112 * show the lost events or not
115 public static volatile boolean hideLostEvents
= false;
117 // ------------------------------------------------------------------------
119 // ------------------------------------------------------------------------
123 * @param width the canvas width
124 * @param height the canvas height
125 * @param barWidth the required bar width
127 public HistogramScaledData(int width
, int height
, int barWidth
) {
130 fBarWidth
= barWidth
;
131 fData
= new HistogramBucket
[width
/ fBarWidth
];
132 fLostEventsData
= new int[width
/ fBarWidth
];
135 fMaxCombinedValue
= 0;
136 fSelectionBeginBucket
= 0;
137 fSelectionEndBucket
= 0;
140 fScalingFactorCombined
= 1;
141 fFirstBucketTime
= 0;
146 * @param other another scaled data.
148 public HistogramScaledData(HistogramScaledData other
) {
149 fWidth
= other
.fWidth
;
150 fHeight
= other
.fHeight
;
151 fBarWidth
= other
.fBarWidth
;
152 fData
= Arrays
.copyOf(other
.fData
, other
.fData
.length
);
153 fLostEventsData
= Arrays
.copyOf(other
.fLostEventsData
, other
.fLostEventsData
.length
);
154 fBucketDuration
= other
.fBucketDuration
;
155 fMaxValue
= other
.fMaxValue
;
156 fMaxCombinedValue
= other
.fMaxCombinedValue
;
157 fSelectionBeginBucket
= other
.fSelectionBeginBucket
;
158 fSelectionEndBucket
= other
.fSelectionEndBucket
;
159 fLastBucket
= other
.fLastBucket
;
160 fScalingFactor
= other
.fScalingFactor
;
161 fScalingFactorCombined
= other
.fScalingFactorCombined
;
162 fFirstBucketTime
= other
.fFirstBucketTime
;
165 // ------------------------------------------------------------------------
167 // ------------------------------------------------------------------------
170 * Returns the time of the first bucket of the scaled data.
171 * @return the time of the first bucket.
173 public long getFirstBucketTime() {
174 return fFirstBucketTime
;
178 * Set the first event time.
179 * @param firstEventTime The time to set
181 public void setFirstBucketTime(long firstEventTime
) {
182 fFirstBucketTime
= firstEventTime
;
186 * Returns the time of the last bucket.
187 * @return last bucket time
189 public long getLastBucketTime() {
190 return getBucketStartTime(fLastBucket
);
194 * Returns the time of the bucket start time for given index.
195 * @param index A bucket index.
196 * @return the time of the bucket start time
198 public long getBucketStartTime(int index
) {
199 return fFirstBucketTime
+ index
* fBucketDuration
;
203 * Returns the time of the bucket end time for given index.
204 * @param index A bucket index.
205 * @return the time of the bucket end time
207 public long getBucketEndTime(int index
) {
208 return getBucketStartTime(index
) + fBucketDuration
;