better logging requires better thread names

This commit is contained in:
rusefi 2020-07-25 16:00:09 -04:00
parent 5d91702272
commit 52caab3989
7 changed files with 30 additions and 20 deletions

View File

@ -11,6 +11,8 @@ import java.util.function.Consumer;
* Andrey Belomutskiy, (c) 2013-2020
*/
public class SimulatorExecHelper {
private final static NamedThreadFactory THREAD_FACTORY = new NamedThreadFactory("SimulatorExecHelper", true);
// see also SimulatorHelper
private static final String SIMULATOR_BINARY = "../simulator/build/rusefi_simulator.exe";
static Process simulatorProcess;
@ -42,8 +44,7 @@ public class SimulatorExecHelper {
public static void dumpProcessOutput(Process process) throws IOException {
BufferedReader input =
new BufferedReader(new InputStreamReader(process.getInputStream()));
Thread thread = new Thread(createErrorStreamEcho(process));
thread.setDaemon(true);
Thread thread = THREAD_FACTORY.newThread(createErrorStreamEcho(process));
thread.start();
String prefix = "from console: ";

View File

@ -6,6 +6,7 @@ import com.opensr5.Logger;
import com.opensr5.io.ConfigurationImageFile;
import com.opensr5.io.DataListener;
import com.rusefi.ConfigurationImageDiff;
import com.rusefi.NamedThreadFactory;
import com.rusefi.Timeouts;
import com.rusefi.composite.CompositeEvent;
import com.rusefi.composite.CompositeParser;
@ -32,25 +33,23 @@ import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.*;
import static com.devexperts.logging.Logging.getLogging;
import static com.rusefi.binaryprotocol.IoHelper.*;
/**
* This object represents logical state of physical connection.
*
* <p>
* Instance is connected until we experience issues. Once we decide to close the connection there is no restart -
* new instance of this class would need to be created once we establish a new physical connection.
*
* <p>
* Andrey Belomutskiy, (c) 2013-2020
* 3/6/2015
*/
public class BinaryProtocol implements BinaryProtocolCommands {
private static final Logging log = getLogging(BinaryProtocol.class);
private static final ThreadFactory THREAD_FACTORY = new NamedThreadFactory("text pull");
private static final String USE_PLAIN_PROTOCOL_PROPERTY = "protocol.plain";
private static final String CONFIGURATION_RUSEFI_BINARY = "current_configuration.rusefi_binary";
@ -101,7 +100,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
case Fields.TS_OUTPUT_COMMAND:
return "TS_OUTPUT_COMMAND";
default:
return "command " + (char) + command + "/" + command;
return "command " + (char) +command + "/" + command;
}
}
@ -228,7 +227,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
private void startTextPullThread(final DataListener listener) {
if (!linkManager.COMMUNICATION_QUEUE.isEmpty()) {
System.out.println("Current queue: " + linkManager.COMMUNICATION_QUEUE.size());
log.info("Current queue: " + linkManager.COMMUNICATION_QUEUE.size());
}
Runnable textPull = new Runnable() {
@Override
@ -254,8 +253,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
log.info("Stopping text pull");
}
};
Thread tr = new Thread(textPull);
tr.setName("text pull");
Thread tr = THREAD_FACTORY.newThread(textPull);
tr.start();
}
@ -396,7 +394,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
if (localCached != null) {
int crcOfLocallyCachedConfiguration = IoHelper.getCrc32(localCached.getContent());
System.out.printf(CONFIGURATION_RUSEFI_BINARY + " Local cache CRC %x\n", crcOfLocallyCachedConfiguration);
log.info(String.format(CONFIGURATION_RUSEFI_BINARY + " Local cache CRC %x\n", crcOfLocallyCachedConfiguration));
byte packet[] = new byte[7];
packet[0] = COMMAND_CRC_CHECK_COMMAND;
@ -407,7 +405,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
// that's unusual - most of the protocol is LITTLE_ENDIAN
bb.order(ByteOrder.BIG_ENDIAN);
int crcFromController = bb.getInt();
System.out.printf("From rusEFI CRC %x\n", crcFromController);
log.info(String.format("From rusEFI CRC %x\n", crcFromController));
if (crcOfLocallyCachedConfiguration == crcFromController) {
return localCached;
}

View File

@ -8,10 +8,12 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ThreadFactory;
import static com.rusefi.ui.util.UiUtils.setToolTip;
public class SimulatorHelper {
private final static ThreadFactory THREAD_FACTORY = new NamedThreadFactory("SimulatorHelper");
public static final String BINARY = "rusefi_simulator.exe";
private static Process process;
@ -27,7 +29,7 @@ public class SimulatorHelper {
LinkManager.isSimulationMode = true;
FileLog.MAIN.logLine("Executing " + BINARY);
new Thread(new Runnable() {
THREAD_FACTORY.newThread(new Runnable() {
@Override
public void run() {
try {

View File

@ -1,6 +1,7 @@
package com.rusefi.sensor_logs;
import com.rusefi.FileLog;
import com.rusefi.NamedThreadFactory;
import com.rusefi.Timeouts;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
@ -13,7 +14,7 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class BinarySensorLogRestarter implements SensorLog {
private final static Executor UPLOAD_EXECUTOR = Executors.newSingleThreadExecutor();
private final static Executor UPLOAD_EXECUTOR = Executors.newSingleThreadExecutor(new NamedThreadFactory("BinarySensorLogRestarter"));
private BinarySensorLog logger;

View File

@ -1,5 +1,6 @@
package com.rusefi.ui;
import com.rusefi.NamedThreadFactory;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCategory;
import com.rusefi.core.SensorCentral;
@ -11,6 +12,7 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.LinkedList;
import java.util.concurrent.ThreadFactory;
/**
* Andrey Belomutskiy, (c) 2013-2020
@ -18,6 +20,7 @@ import java.util.LinkedList;
*/
@SuppressWarnings("InfiniteLoopStatement")
public class SensorLiveGraph extends JPanel {
private final static ThreadFactory THREAD_FACTORY = new NamedThreadFactory("SensorLiveGraph", true);
private static final int COUNT = 30;
private static final String SENSOR_TYPE = "sensor";
private static final String PERIOD = "period";
@ -41,8 +44,7 @@ public class SensorLiveGraph extends JPanel {
String gaugeName = config.getProperty(SENSOR_TYPE, defaultSensor.name());
this.sensor = Sensor.lookup(gaugeName, defaultSensor);
Thread thread = new Thread(createRunnable());
thread.setDaemon(true);
Thread thread = THREAD_FACTORY.newThread(createRunnable());
thread.start();
period = ChangePeriod.lookup(config.getProperty(PERIOD));
autoScale = config.getBoolProperty(USE_AUTO_SCALE);

View File

@ -1,5 +1,6 @@
package com.rusefi.ui.light;
import com.rusefi.NamedThreadFactory;
import com.rusefi.Timeouts;
import javax.swing.*;
@ -8,8 +9,10 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.ThreadFactory;
public class InternetStatus {
private final static ThreadFactory THREAD_FACTORY = new NamedThreadFactory("InternetStatus");
private static final String GOOGLE = "http://google.com";
private final JPanel panel = new JPanel();
private final JLabel status = new JLabel();
@ -19,7 +22,7 @@ public class InternetStatus {
Font defaultFont = status.getFont();
status.setFont(new Font(defaultFont.getName(), defaultFont.getStyle(), 2 * defaultFont.getSize()));
new Thread(() -> {
THREAD_FACTORY.newThread(() -> {
while (true) {
boolean isConnected = isServerReachable();
try {

View File

@ -4,6 +4,7 @@ import com.fathzer.soft.javaluator.DoubleEvaluator;
import com.rusefi.AutoTest;
import com.rusefi.FileLog;
import com.rusefi.InfixConverter;
import com.rusefi.NamedThreadFactory;
import com.rusefi.core.MessagesCentral;
import com.rusefi.io.CommandQueue;
import com.rusefi.io.LinkManager;
@ -21,6 +22,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
@ -29,6 +31,7 @@ import java.util.function.Function;
* Andrey Belomutskiy, (c) 2013-2020
*/
public class AnyCommand {
private final static ThreadFactory THREAD_FACTORY = new NamedThreadFactory("AnyCommand");
public static final String KEY = "last_value";
private static final String DECODE_RPN = "decode_rpn";
@ -171,7 +174,7 @@ public class AnyCommand {
int rpm = Integer.parseInt(parts[1]);
int settleTime = Integer.parseInt(parts[2]);
int durationTime = Integer.parseInt(parts[3]);
new Thread(new Runnable() {
THREAD_FACTORY.newThread(new Runnable() {
@Override
public void run() {
MessagesCentral.getInstance().postMessage(AnyCommand.class, "Will test with RPM " + rpm + ", settle time" + settleTime + "s and duration" + durationTime + "s");