aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/common/sampler
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-11-26 23:00:53 +0000
committerLuck <git@lucko.me>2022-11-26 23:01:02 +0000
commit65f9460a1a27e930b3749525766fd44d57b65300 (patch)
tree8ddf02527b465bd63b768b5ca0c8ee448f272c67 /spark-common/src/main/java/me/lucko/spark/common/sampler
parentdc52696138b2506b5a36e967b98af7e3f67ab0b0 (diff)
downloadspark-65f9460a1a27e930b3749525766fd44d57b65300.tar.gz
spark-65f9460a1a27e930b3749525766fd44d57b65300.tar.bz2
spark-65f9460a1a27e930b3749525766fd44d57b65300.zip
Include player/entity/chunk counts in window statistics
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/sampler')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractSampler.java2
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java2
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/SamplerContainer.java6
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerJob.java6
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncSampler.java14
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaSampler.java14
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/window/WindowStatisticsCollector.java15
7 files changed, 41 insertions, 18 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 59e873c..e324fd3 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
@@ -120,7 +120,7 @@ public abstract class AbstractSampler implements Sampler {
}
@Override
- public void stop() {
+ public void stop(boolean cancelled) {
this.windowStatisticsCollector.stop();
}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java
index 5d2026d..36a63f1 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java
@@ -41,7 +41,7 @@ public interface Sampler {
/**
* Stops the sampler.
*/
- void stop();
+ void stop(boolean cancelled);
/**
* Gets the time when the sampler started (unix timestamp in millis)
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/SamplerContainer.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/SamplerContainer.java
index f56dee5..d55909c 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/SamplerContainer.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/SamplerContainer.java
@@ -66,10 +66,10 @@ public class SamplerContainer implements AutoCloseable {
/**
* Stops the active sampler, if there is one.
*/
- public void stopActiveSampler() {
+ public void stopActiveSampler(boolean cancelled) {
Sampler sampler = this.activeSampler.getAndSet(null);
if (sampler != null) {
- sampler.stop();
+ sampler.stop(cancelled);
}
}
@@ -79,7 +79,7 @@ public class SamplerContainer implements AutoCloseable {
@Override
public void close() {
- stopActiveSampler();
+ stopActiveSampler(true);
}
}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerJob.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerJob.java
index db1808c..d74b75f 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerJob.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerJob.java
@@ -224,13 +224,15 @@ public class AsyncProfilerJob {
}
}
- // delete the output file after reading
+ deleteOutputFile();
+ }
+
+ public void deleteOutputFile() {
try {
Files.deleteIfExists(this.outputFile);
} catch (IOException e) {
// ignore
}
-
}
private void readSegments(JfrReader reader, Predicate<String> threadFilter, AsyncDataAggregator dataAggregator, int window) throws IOException {
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncSampler.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncSampler.java
index f2e7191..178f055 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncSampler.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncSampler.java
@@ -144,7 +144,7 @@ public class AsyncSampler extends AbstractSampler {
}
this.scheduler.schedule(() -> {
- stop();
+ stop(false);
this.future.complete(this);
}, delay, TimeUnit.MILLISECONDS);
}
@@ -153,13 +153,17 @@ public class AsyncSampler extends AbstractSampler {
* Stops the profiler.
*/
@Override
- public void stop() {
- super.stop();
+ public void stop(boolean cancelled) {
+ super.stop(cancelled);
synchronized (this.currentJobMutex) {
this.currentJob.stop();
- this.windowStatisticsCollector.measureNow(this.currentJob.getWindow());
- this.currentJob.aggregate(this.dataAggregator);
+ if (!cancelled) {
+ this.windowStatisticsCollector.measureNow(this.currentJob.getWindow());
+ this.currentJob.aggregate(this.dataAggregator);
+ } else {
+ this.currentJob.deleteOutputFile();
+ }
this.currentJob = null;
}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaSampler.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaSampler.java
index 42a457d..72a37e8 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaSampler.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaSampler.java
@@ -94,13 +94,15 @@ public class JavaSampler extends AbstractSampler implements Runnable {
}
@Override
- public void stop() {
- super.stop();
+ public void stop(boolean cancelled) {
+ super.stop(cancelled);
this.task.cancel(false);
- // collect statistics for the final window
- this.windowStatisticsCollector.measureNow(this.lastWindow.get());
+ if (!cancelled) {
+ // collect statistics for the final window
+ this.windowStatisticsCollector.measureNow(this.lastWindow.get());
+ }
}
@Override
@@ -111,7 +113,7 @@ public class JavaSampler extends AbstractSampler implements Runnable {
long time = System.currentTimeMillis();
if (this.autoEndTime != -1 && this.autoEndTime <= time) {
- stop();
+ stop(false);
this.future.complete(this);
return;
}
@@ -120,7 +122,7 @@ public class JavaSampler extends AbstractSampler implements Runnable {
ThreadInfo[] threadDumps = this.threadDumper.dumpThreads(this.threadBean);
this.workerPool.execute(new InsertDataTask(threadDumps, window));
} catch (Throwable t) {
- stop();
+ stop(false);
this.future.completeExceptionally(t);
}
}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/window/WindowStatisticsCollector.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/window/WindowStatisticsCollector.java
index 7da62fa..ce65013 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/window/WindowStatisticsCollector.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/window/WindowStatisticsCollector.java
@@ -23,6 +23,8 @@ package me.lucko.spark.common.sampler.window;
import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.monitor.cpu.CpuMonitor;
import me.lucko.spark.common.monitor.tick.TickStatistics;
+import me.lucko.spark.common.platform.world.AsyncWorldInfoProvider;
+import me.lucko.spark.common.platform.world.WorldInfoProvider;
import me.lucko.spark.common.tick.TickHook;
import me.lucko.spark.common.util.RollingAverage;
import me.lucko.spark.proto.SparkProtos;
@@ -152,6 +154,19 @@ public class WindowStatisticsCollector {
builder.setCpuProcess(CpuMonitor.processLoad1MinAvg());
builder.setCpuSystem(CpuMonitor.systemLoad1MinAvg());
+ try {
+ AsyncWorldInfoProvider worldInfoProvider = new AsyncWorldInfoProvider(this.platform, this.platform.getPlugin().createWorldInfoProvider());
+ WorldInfoProvider.CountsResult counts = worldInfoProvider.getCounts();
+ if (counts != null) {
+ builder.setPlayers(counts.players());
+ builder.setEntities(counts.entities());
+ builder.setTileEntities(counts.tileEntities());
+ builder.setChunks(counts.chunks());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
return builder.build();
}