Skip to content

Commit 49f5b52

Browse files
committed
Add JVM argument to help prevent mass Spark profile uploads
1 parent 0028761 commit 49f5b52

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/org/embeddedt/modernfix/spark/SparkLaunchProfiler.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,26 @@ public class SparkLaunchProfiler {
3737
private static ExecutorService executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("spark-modernfix-async-worker").build());
3838
private static final SparkPlatform platform = new SparkPlatform(new ModernFixSparkPlugin());
3939

40+
private static final String ALLOW_SPARK_PROFILING_PROP = "modernfix.allowSparkProfiling";
4041
private static final boolean USE_JAVA_SAMPLER_FOR_LAUNCH = !Boolean.getBoolean("modernfix.profileWithAsyncSampler");
42+
private static final boolean ALLOW_SPARK_PROFILING = Boolean.getBoolean(ALLOW_SPARK_PROFILING_PROP);
4143
private static final int SAMPLING_INTERVAL = Integer.getInteger("modernfix.profileSamplingIntervalMicroseconds", 4000);
4244
private static final String THREAD_GROUPER = System.getProperty("modernfix.profileSamplingThreadGrouper", "by-pool");
4345

46+
private static boolean checkSparkProfilingAllowed() {
47+
if (!ALLOW_SPARK_PROFILING) {
48+
ModernFixMixinPlugin.instance.logger.fatal("To reduce excessive load on the Spark servers, you must set " +
49+
"-D{}=true in your JVM arguments for profiling to proceed. Please do " +
50+
"this and relaunch the game.", ALLOW_SPARK_PROFILING_PROP);
51+
return false;
52+
}
53+
return true;
54+
}
55+
4456
public static void start(String key) {
57+
if (!checkSparkProfilingAllowed()) {
58+
return;
59+
}
4560
if (!ongoingSamplers.containsKey(key)) {
4661
Sampler sampler;
4762
SamplerSettings settings = new SamplerSettings(SAMPLING_INTERVAL, ThreadDumper.ALL, ThreadGrouper.parseConfigSetting(THREAD_GROUPER), -1, false);

0 commit comments

Comments
 (0)