Adding the RecentEstimatedHistogram
Some of the jmx methods uses the notion of recent estimated histogram. In origin the implementation uses an estimated histogram and clean the histogram values on each call. The RecentEstimatedHistogram mimic this behaviour, it store the latest values of the last call. In each call new values are stored in the histogram and the results is the delta between the last two calls. Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This commit is contained in:
parent
be8eea6bd4
commit
a568e52cb5
@ -0,0 +1,62 @@
|
||||
package com.cloudius.urchin.utils;
|
||||
/*
|
||||
* Copyright (C) 2015 ScyllaDB
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of Scylla.
|
||||
*
|
||||
* Scylla is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Scylla is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* RecentEstimatedHistogram In the (deprecated) 'recent' functionality, each
|
||||
* call to get the values cleans the value.
|
||||
*
|
||||
* The RecentEstimatedHistogram support recent call to EstimatedHistogram.
|
||||
* It holds the latest total values and a call to getBuckets return the delta.
|
||||
*
|
||||
*/
|
||||
public class RecentEstimatedHistogram extends EstimatedHistogram {
|
||||
public RecentEstimatedHistogram() {
|
||||
}
|
||||
|
||||
public RecentEstimatedHistogram(int bucketCount) {
|
||||
super(bucketCount);
|
||||
}
|
||||
|
||||
public RecentEstimatedHistogram(long[] offsets, long[] bucketData) {
|
||||
super(offsets, bucketData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current buckets to new value and return the delta from the last
|
||||
* getBuckets call
|
||||
*
|
||||
* @param bucketData
|
||||
* - new bucket value
|
||||
* @return a long[] containing the current histogram difference buckets
|
||||
*/
|
||||
public long[] getBuckets(long[] bucketData) {
|
||||
final int len = buckets.length();
|
||||
long[] rv = new long[len];
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
rv[i] = bucketData[i];
|
||||
rv[i] -= buckets.getAndSet(i, bucketData[i]);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user