1 /*******************************************************************************
2 * Copyright (c) 2011 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 * Bernd Hufmann - Initial API and implementation
11 ******************************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.distribution
.model
;
14 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.latency
.model
.Config
;
15 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.distribution
.model
.BaseDistributionData
;
18 * <b><u>DistributionData</u></b>
20 * The algorithm is based on the algorithm for the Histogram. The difference is that
21 * it supports two dimensions. For more details about the model principle
22 * @see org.eclipse.linuxtools.lttng.ui.views.histogram.HistogramDataModel
25 abstract public class DistributionData
extends BaseDistributionData
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
32 * Flag to indicate if given timestamp is the first one to count
34 protected boolean fIsFirst
;
37 * reference to fBuckets
39 protected final int [][] fBuckets
;
42 * Time limit (current available longest time)
44 protected long fTimeLimit
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
49 public DistributionData(int[][] buckets
) {
50 this(Config
.DEFAULT_NUMBER_OF_BUCKETS
, buckets
);
53 public DistributionData(int nbBuckets
, int[][] buckets
) {
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 public long getTimeLimit() {
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
73 * @see org.eclipse.linuxtools.lttng.ui.views.distribution.model.BaseDistributionData#clear()
82 public boolean isFirst() {
86 public int countEvent(long timestamp
) {
88 // Set the start/end time if not already done
91 fFirstBucketTime
= timestamp
;
92 fFirstEventTime
= timestamp
;
97 // save first event time if necessary
98 if (timestamp
< fFirstEventTime
) {
99 fFirstEventTime
= timestamp
;
102 // save last event time if necessary
103 if (fLastEventTime
< timestamp
) {
104 fLastEventTime
= timestamp
;
108 if (timestamp
>= fFirstBucketTime
) {
110 while (timestamp
>= fTimeLimit
) {
116 // Get offset for buckets adjustment
117 int offset
= getOffset(timestamp
);
120 while (fLastBucket
+ offset
>= fNbBuckets
) {
122 offset
= getOffset(timestamp
);
125 // Move buckets with offset (to right)
128 // Adjust start/end time and index
129 fLastBucket
= fLastBucket
+ offset
;
130 fFirstBucketTime
= fFirstBucketTime
- offset
* fBucketDuration
;
134 // Increment the right bucket
135 int index
= (int) ((timestamp
- fFirstBucketTime
) / fBucketDuration
);
137 if (fLastBucket
< index
) {
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
149 * Moves content of buckets with the given offset in positive direction.
150 * It has to be implemented accordingly in the relevant sub-classes for
151 * horizontal and vertical direction.
153 * @param buckets - 2-dimensional array of buckets
154 * @param offset - offset to move
156 abstract protected void moveBuckets(int offset
);
159 * Merges buckets if end time is exceeded. It has to be implemented
160 * accordingly in the relevant sub-classes for horizontal and
161 * vertical direction.
164 abstract protected void mergeBuckets();
166 // ------------------------------------------------------------------------
168 // ------------------------------------------------------------------------
169 protected int getOffset(long timestamp
) {
170 int offset
= (int) ((fFirstBucketTime
- timestamp
) / fBucketDuration
);
171 if ((fFirstBucketTime
- timestamp
) % fBucketDuration
!= 0) {
177 protected void updateEndTime() {
178 fTimeLimit
= fFirstBucketTime
+ fNbBuckets
* fBucketDuration
;