-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic bench-marker and improved usage information
- Loading branch information
Showing
5 changed files
with
164 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import net.minecraft.world.level.storage.AnvilConverter; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.util.logging.*; | ||
|
||
public class AutomaticBenchmarker { | ||
|
||
private static final Logger logger = Logger.getLogger(AutomaticBenchmarker.class.getName()); | ||
|
||
public static void main(String[] args) { | ||
setupLogger(); | ||
|
||
// Notice: This program performs automatic benchmarking of the AnvilConverter application. | ||
logger.info("Starting automatic benchmarking of the AnvilConverter application."); | ||
|
||
// Fake arguments for the AnvilConverter application | ||
String baseFolderPath = "E:\\RetroMC-1\\"; | ||
String worldName = "retromc"; | ||
int[] threadCounts = {32, 16, 8, 4, 2, 1, 0}; // 0 runs the converter sequentially on the main thread | ||
|
||
for (int numThreads : threadCounts) { | ||
logger.info("Running benchmark with " + numThreads + " threads."); | ||
AnvilConverter.main(new String[]{baseFolderPath, worldName, String.valueOf(numThreads)}); | ||
|
||
// Cleanup JVM | ||
System.gc(); | ||
|
||
// Sleep for 1 minute to allow the JVM to cleanup | ||
try { | ||
Thread.sleep(60000); | ||
} catch (InterruptedException e) { | ||
logger.log(Level.WARNING, "Thread interrupted while sleeping", e); | ||
} | ||
} | ||
} | ||
|
||
private static void setupLogger() { | ||
try { | ||
// Create a file handler that writes log record to a file called benchmark.log | ||
FileHandler fileHandler = new FileHandler("benchmark.log", true); | ||
fileHandler.setFormatter(new SimpleFormatter()); | ||
|
||
// Add the file handler to the logger | ||
logger.addHandler(fileHandler); | ||
|
||
// Set the logger level to INFO | ||
logger.setLevel(Level.INFO); | ||
|
||
// Also log to the console | ||
ConsoleHandler consoleHandler = new ConsoleHandler(); | ||
consoleHandler.setFormatter(new SimpleFormatter()); | ||
logger.addHandler(consoleHandler); | ||
|
||
// Redirect System.out and System.err to logger | ||
PrintStream logStream = new PrintStream(new DualOutputStream(System.out, new FileOutputStream("benchmark.log", true))); | ||
System.setOut(logStream); | ||
System.setErr(logStream); | ||
|
||
} catch (IOException e) { | ||
logger.log(Level.SEVERE, "Failed to setup logger", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import java.io.OutputStream; | ||
import java.io.PrintStream; | ||
import java.io.IOException; | ||
|
||
public class DualOutputStream extends OutputStream { | ||
private final OutputStream outputStream1; | ||
private final OutputStream outputStream2; | ||
|
||
public DualOutputStream(OutputStream outputStream1, OutputStream outputStream2) { | ||
this.outputStream1 = outputStream1; | ||
this.outputStream2 = outputStream2; | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
outputStream1.write(b); | ||
outputStream2.write(b); | ||
} | ||
|
||
@Override | ||
public void write(byte[] b) throws IOException { | ||
outputStream1.write(b); | ||
outputStream2.write(b); | ||
} | ||
|
||
@Override | ||
public void write(byte[] b, int off, int len) throws IOException { | ||
outputStream1.write(b, off, len); | ||
outputStream2.write(b, off, len); | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
outputStream1.flush(); | ||
outputStream2.flush(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
outputStream1.close(); | ||
outputStream2.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters