Skip to content

Commit

Permalink
only:verbose requestWaitAndGetPTrace result
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Feb 22, 2024
1 parent 567e463 commit 9b761b4
Showing 1 changed file with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

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;
Expand All @@ -21,28 +23,43 @@ public static void grabPerformanceTrace(JComponent parent, BinaryProtocol bp) {
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() {
Expand Down

0 comments on commit 9b761b4

Please sign in to comment.