only:verbose requestWaitAndGetPTrace result

This commit is contained in:
rusefillc 2024-02-22 16:47:48 -05:00
parent 567e46371d
commit 9b761b438c
1 changed files with 27 additions and 10 deletions

View File

@ -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<Entry> data = Entry.parseBuffer(packet);
List<Entry> 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<Entry> 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<Entry> 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();