diff --git a/java_console/ui/src/main/java/com/rusefi/PerformanceTraceHelper.java b/java_console/ui/src/main/java/com/rusefi/PerformanceTraceHelper.java index 4b14a1c734..b1db5ce6bd 100644 --- a/java_console/ui/src/main/java/com/rusefi/PerformanceTraceHelper.java +++ b/java_console/ui/src/main/java/com/rusefi/PerformanceTraceHelper.java @@ -2,9 +2,11 @@ package com.rusefi; import com.rusefi.binaryprotocol.BinaryProtocol; import com.rusefi.config.generated.Fields; +import com.rusefi.core.MessagesCentral; import com.rusefi.tracing.Entry; import com.rusefi.tracing.JsonOutput; import com.rusefi.ui.RpmModel; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.io.FileOutputStream; @@ -21,30 +23,45 @@ public class PerformanceTraceHelper { JOptionPane.showMessageDialog(parent, msg, msg, JOptionPane.ERROR_MESSAGE); return; } - bp.executeCommand(Fields.TS_PERF_TRACE_BEGIN, "begin trace"); try { - Thread.sleep(500); - - byte[] packet = bp.executeCommand(Fields.TS_PERF_TRACE_GET_BUFFER, "get trace"); - if (!checkResponseCode(packet, (byte) Fields.TS_RESPONSE_OK) || ((packet.length - 1) % 8) != 0) - throw new IllegalStateException("Unexpected packet, length=" + (packet != null ? 0 : packet.length)); - - List data = Entry.parseBuffer(packet); + List data = requestWaitAndGetPTrace(bp); if (data.isEmpty()) { String msg = "Empty PERF_TRACE response"; JOptionPane.showMessageDialog(parent, msg, msg, JOptionPane.ERROR_MESSAGE); return; } + MessagesCentral.getInstance().postMessage(PerformanceTraceHelper.class, "Got " + data.size() + " PTrace entries"); int rpm = RpmModel.getInstance().getValue(); String fileName = FileLog.getDate() + "_rpm_" + rpm + "_rusEFI_trace" + ".json"; JsonOutput.writeToStream(data, new FileOutputStream(fileName)); - } catch (IOException | InterruptedException e1) { - throw new IllegalStateException(e1); + } catch (IOException e) { + throw new IllegalStateException(e); } } + @NotNull + private static List requestWaitAndGetPTrace(BinaryProtocol bp) { + bp.executeCommand(Fields.TS_PERF_TRACE_BEGIN, "begin trace"); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + + return executeGetPTraceCommand(bp); + } + + @NotNull + private static List executeGetPTraceCommand(BinaryProtocol bp) { + byte[] packet = bp.executeCommand(Fields.TS_PERF_TRACE_GET_BUFFER, "get trace"); + if (!checkResponseCode(packet, (byte) Fields.TS_RESPONSE_OK) || ((packet.length - 1) % 8) != 0) + throw new IllegalStateException("Unexpected packet, length=" + (packet != null ? 0 : packet.length)); + + return Entry.parseBuffer(packet); + } + public static void getPerformanceTune() { startAndConnect(linkManager -> { BinaryProtocol binaryProtocol = linkManager.getConnector().getBinaryProtocol();