aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2024-09-03 00:11:24 +0100
committerLuck <git@lucko.me>2024-09-03 00:11:24 +0100
commit35b557af4fd1bc0ce0a5745716e898cd1300a08c (patch)
tree5927e55839d5dd1a0759db3a2fd54f9f8df5d032 /spark-common/src/main/java
parent55b38397296813b66082ad935f773357c8ad5282 (diff)
downloadspark-35b557af4fd1bc0ce0a5745716e898cd1300a08c.tar.gz
spark-35b557af4fd1bc0ce0a5745716e898cd1300a08c.tar.bz2
spark-35b557af4fd1bc0ce0a5745716e898cd1300a08c.zip
Improve unit tests
Diffstat (limited to 'spark-common/src/main/java')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractSampler.java4
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProfilingWindowUtils.java2
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProtoTimeEncoder.java23
3 files changed, 13 insertions, 16 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractSampler.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractSampler.java
index 7453074..20e7973 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractSampler.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractSampler.java
@@ -23,14 +23,11 @@ package me.lucko.spark.common.sampler;
import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.command.sender.CommandSender;
import me.lucko.spark.common.monitor.memory.GarbageCollectorStatistics;
-import me.lucko.spark.common.platform.MetadataProvider;
import me.lucko.spark.common.platform.SparkMetadata;
-import me.lucko.spark.common.platform.serverconfig.ServerConfigProvider;
import me.lucko.spark.common.sampler.aggregator.DataAggregator;
import me.lucko.spark.common.sampler.node.MergeMode;
import me.lucko.spark.common.sampler.node.ThreadNode;
import me.lucko.spark.common.sampler.source.ClassSourceLookup;
-import me.lucko.spark.common.sampler.source.SourceMetadata;
import me.lucko.spark.common.sampler.window.ProtoTimeEncoder;
import me.lucko.spark.common.sampler.window.WindowStatisticsCollector;
import me.lucko.spark.common.util.classfinder.ClassFinder;
@@ -42,7 +39,6 @@ import me.lucko.spark.proto.SparkSamplerProtos.SamplerMetadata;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProfilingWindowUtils.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProfilingWindowUtils.java
index be6f08a..ca44b31 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProfilingWindowUtils.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProfilingWindowUtils.java
@@ -61,7 +61,7 @@ public enum ProfilingWindowUtils {
/**
* Gets a prune predicate that can be passed to {@link DataAggregator#pruneData(IntPredicate)}.
*
- * @return the prune predicate
+ * @return the prune predicate - returns true for windows that should be pruned
*/
public static IntPredicate keepHistoryBefore(int currentWindow) {
// windows that were earlier than (currentWindow minus history size) should be pruned
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProtoTimeEncoder.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProtoTimeEncoder.java
index fb4a4fc..db0800d 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProtoTimeEncoder.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/window/ProtoTimeEncoder.java
@@ -20,8 +20,8 @@
package me.lucko.spark.common.sampler.window;
-import me.lucko.spark.common.sampler.async.jfr.Dictionary;
import me.lucko.spark.common.sampler.node.ThreadNode;
+import org.jetbrains.annotations.VisibleForTesting;
import java.util.HashMap;
import java.util.List;
@@ -43,16 +43,10 @@ public class ProtoTimeEncoder {
/** A map of key value -> index in the keys array */
private final Map<Integer, Integer> keysToIndex;
- public ProtoTimeEncoder(LongToDoubleFunction valueTransformer, List<ThreadNode> sourceData) {
+ @VisibleForTesting
+ ProtoTimeEncoder(LongToDoubleFunction valueTransformer, IntStream keys) {
this.valueTransformer = valueTransformer;
-
- // get an array of all keys that show up in the source data
- this.keys = sourceData.stream()
- .map(n -> n.getTimeWindows().stream().mapToInt(i -> i))
- .reduce(IntStream.empty(), IntStream::concat)
- .distinct()
- .sorted()
- .toArray();
+ this.keys = keys.distinct().sorted().toArray();
// construct a reverse index lookup
this.keysToIndex = new HashMap<>(this.keys.length);
@@ -61,6 +55,13 @@ public class ProtoTimeEncoder {
}
}
+ public ProtoTimeEncoder(LongToDoubleFunction valueTransformer, List<ThreadNode> sourceData) {
+ this(valueTransformer, sourceData.stream()
+ .map(n -> n.getTimeWindows().stream().mapToInt(i -> i))
+ .reduce(IntStream.empty(), IntStream::concat)
+ );
+ }
+
/**
* Gets an array of the keys that could be encoded by this encoder.
*
@@ -71,7 +72,7 @@ public class ProtoTimeEncoder {
}
/**
- * Encode a {@link Dictionary} (map) of times/durations into a double array.
+ * Encode a map of times/durations into a double array.
*
* @param times a dictionary of times (unix-time millis -> duration in microseconds)
* @return the times encoded as a double array