-
Notifications
You must be signed in to change notification settings - Fork 20
Refactored M3 reporting to remove any unnecessary allocations #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f785329
2004798
3d86581
1edef39
6e9dd71
17e61fb
75d15c4
afdea13
edb4b70
c50e2c2
86b58c0
6151fe0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,30 +21,39 @@ | |
| package com.uber.m3.tally; | ||
|
|
||
| import com.uber.m3.util.Duration; | ||
| import com.uber.m3.util.ImmutableList; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.ListIterator; | ||
|
|
||
| /** | ||
| * Abstract {@link Buckets} implementation for common functionality. | ||
| * @deprecated DO NOT USE | ||
| * | ||
| * Please use {@link ImmutableBuckets} instead | ||
| */ | ||
| public abstract class AbstractBuckets<T> implements Buckets<T> { | ||
| @Deprecated | ||
| public abstract class AbstractBuckets<T extends Comparable<T>> implements Buckets<T> { | ||
| protected List<T> buckets; | ||
|
|
||
| AbstractBuckets(T[] buckets) { | ||
| if (buckets == null) { | ||
| this.buckets = new ArrayList<>(); | ||
| } else { | ||
| this.buckets = new ArrayList<>(Arrays.asList(buckets)); | ||
| throw new IllegalArgumentException("provided buckets could not be null"); | ||
| } | ||
|
|
||
| validate(buckets); | ||
|
|
||
| this.buckets = new ImmutableList<>(Arrays.asList(buckets)); | ||
| } | ||
|
|
||
| AbstractBuckets() { | ||
| this(null); | ||
| public void validate(T[] buckets) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
| for (int i = 1; i < buckets.length; ++i) { | ||
| if (buckets[i - 1].compareTo(buckets[i]) > 0) { | ||
| throw new IllegalArgumentException("buckets should be in a non-decreasing order"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,12 +22,10 @@ | |
|
|
||
| import com.uber.m3.util.Duration; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| /** | ||
| * Default implementation of a {@link BucketPair} | ||
| * | ||
| * @deprecated will be removed | ||
| * @deprecated DO NOT USE, WILL BE REMOVED IN THE NEXT VERSION | ||
| */ | ||
| @Deprecated | ||
| public class BucketPairImpl implements BucketPair { | ||
|
|
@@ -60,8 +58,6 @@ public static BucketPair[] bucketPairs(Buckets buckets) { | |
| }; | ||
| } | ||
|
|
||
| Collections.sort(buckets); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, confirming this is fine because of the validate above?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is actually not used anymore |
||
|
|
||
| Double[] asValueBuckets = buckets.asValues(); | ||
| Duration[] asDurationBuckets = buckets.asDurations(); | ||
| BucketPair[] pairs = new BucketPair[buckets.size() + 1]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright (c) 2020 Uber Technologies, Inc. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
|
|
||
| package com.uber.m3.tally; | ||
|
|
||
| import com.uber.m3.util.Duration; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Abstracts buckets used in {@link Histogram} metrics, | ||
| * | ||
| * Buckets are defined by the list of upper-bounds in the following way: | ||
| * | ||
| * <blockquote> | ||
| * <pre> | ||
| * double bounds[] = new double[] { 1, 2, 4, 8, 16 }; | ||
| * | ||
| * // For the given set of bounds: | ||
| * // first bucket [-inf, 1) | ||
| * // second bucket [1, 2) | ||
| * // ... | ||
| * // last bucket [16, +inf) | ||
| * </pre> | ||
| * </blockquote> | ||
| */ | ||
| public interface ImmutableBuckets { | ||
|
|
||
| /** | ||
| * Gets corresponding bucket lower bound | ||
| */ | ||
| double getValueLowerBoundFor(int bucketIndex); | ||
|
|
||
| /** | ||
| * Gets corresponding bucket upper bound | ||
| */ | ||
| double getValueUpperBoundFor(int bucketIndex); | ||
|
|
||
| /** | ||
| * Gets corresponding bucket lower bound | ||
| */ | ||
| Duration getDurationLowerBoundFor(int bucketIndex); | ||
|
|
||
| /** | ||
| * Gets corresponding bucket upper bound | ||
| */ | ||
| Duration getDurationUpperBoundFor(int bucketIndex); | ||
|
|
||
| /** | ||
| * Gets index of the corresponding bucket this value would fall under | ||
| */ | ||
| int getBucketIndexFor(double value); | ||
|
|
||
| /** | ||
| * Gets index of the corresponding bucket this value would fall under | ||
| */ | ||
| int getBucketIndexFor(Duration value); | ||
|
|
||
| /** | ||
| * Returns defined buckets' upper-bound values as {@link Double}s. | ||
| * @return an immutable list of {@code double}s representing these buckets | ||
| */ | ||
| List<Double> getValueUpperBounds(); | ||
|
|
||
| /** | ||
| * Returns defined buckets' upper-bound values as {@link Duration}s. | ||
| * @return an immutable list of {@link Duration}s representing these buckets | ||
| */ | ||
| List<Duration> getDurationUpperBounds(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
confirming that this is is now ok because the Scope always provides non-null buckets because of #76, yeah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes