maybe helping simulator performance

This commit is contained in:
rusefi 2018-10-13 09:25:11 -04:00
parent 8ba703da6b
commit 12f72e7d82
3 changed files with 28 additions and 16 deletions

View File

@ -6,6 +6,7 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.function.Consumer;
/** /**
* 3/18/14 * 3/18/14
@ -46,29 +47,40 @@ public class ExecHelper {
thread.setDaemon(true); thread.setDaemon(true);
thread.start(); thread.start();
readAndPrint("from console: ", input); String prefix = "from console: ";
Consumer<String> PRINT_AND_LOG = string -> {
// looks like this is a performance issue since so many lines are printed? looks like it's helping to not write this?
// System.out.println(prefix + string);
// FileLog.SIMULATOR_CONSOLE.logLine(string);
};
readAndPrint(PRINT_AND_LOG, input);
input.close(); input.close();
} }
private static void readAndPrint(String prefix, BufferedReader input) throws IOException { private static void readAndPrint(Consumer<String> consumer, BufferedReader input) throws IOException {
String line; String line;
while ((line = input.readLine()) != null) { while ((line = input.readLine()) != null) {
System.out.println(prefix + line); consumer.accept(line);
FileLog.SIMULATOR_CONSOLE.logLine(line);
} }
} }
private static Runnable createErrorStreamEcho(final Process process) { private static Runnable createErrorStreamEcho(final Process process) {
return new Runnable() { return () -> {
@Override BufferedReader err =
public void run() { new BufferedReader(new InputStreamReader(process.getErrorStream()));
BufferedReader err = try {
new BufferedReader(new InputStreamReader(process.getErrorStream())); String prefix = "from console: ";
try { Consumer<String> PRINT_AND_LOG = string -> {
readAndPrint("from err: ", err); System.out.println(prefix + string);
} catch (IOException e) { FileLog.SIMULATOR_CONSOLE.logLine(string);
throw new IllegalStateException(e); };
}
readAndPrint(PRINT_AND_LOG, err);
} catch (IOException e) {
throw new IllegalStateException(e);
} }
}; };
} }

View File

@ -29,7 +29,7 @@ public class IncomingDataBuffer {
} }
public void addData(byte[] freshData) { public void addData(byte[] freshData) {
logger.info(freshData.length + " byte(s) arrived"); logger.info("IncomingDataBuffer: " + freshData.length + " byte(s) arrived");
synchronized (cbb) { synchronized (cbb) {
if (cbb.size() - cbb.length() < freshData.length) { if (cbb.size() - cbb.length() < freshData.length) {
logger.error("IncomingDataBuffer: buffer overflow not expected"); logger.error("IncomingDataBuffer: buffer overflow not expected");

View File

@ -45,7 +45,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* @see EngineSnifferPanel * @see EngineSnifferPanel
*/ */
public class Launcher { public class Launcher {
public static final int CONSOLE_VERSION = 20181012; public static final int CONSOLE_VERSION = 20181013;
public static final boolean SHOW_STIMULATOR = false; public static final boolean SHOW_STIMULATOR = false;
private static final String TAB_INDEX = "main_tab"; private static final String TAB_INDEX = "main_tab";
protected static final String PORT_KEY = "port"; protected static final String PORT_KEY = "port";