Skip to content

Commit

Permalink
revive ptrace #5983
Browse files Browse the repository at this point in the history
HW CI
  • Loading branch information
rusefillc authored and rusefillc committed Feb 22, 2024
1 parent 9b761b4 commit dea9e4f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.rusefi.common.MiscTest;
import com.rusefi.f4discovery.CompositeLoggerTest;
import com.rusefi.f4discovery.HighRevTest;
import com.rusefi.f4discovery.PTraceTest;
import com.rusefi.proteus.ProteusAnalogTest;

/**
Expand All @@ -11,6 +12,7 @@
public class HwCiProteus {
public static void main(String[] args) {
CmdJUnitRunner.runHardwareTestAndExit(new Class[]{
PTraceTest.class,
CompositeLoggerTest.class,
HighRevTest.class,
MiscTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.rusefi.f4discovery;

import com.rusefi.RusefiTestBase;
import com.rusefi.io.LinkManager;
import com.rusefi.io.commands.PTraceHelper;
import com.rusefi.tracing.Entry;
import org.junit.Test;

import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static org.junit.Assert.assertTrue;

public class PTraceTest extends RusefiTestBase {
@Test
public void assertPTrace() throws InterruptedException {
LinkManager linkManager = ecu.getLinkManager();
AtomicReference<List<Entry>> result = new AtomicReference<>();

CountDownLatch latch = new CountDownLatch(1);
linkManager.submit(new Runnable() {
@Override
public void run() {
result.set(PTraceHelper.requestWaitAndGetPTrace(linkManager.getBinaryProtocol()));
latch.countDown();

}
});


latch.await(30, TimeUnit.SECONDS);
List<Entry> entries = result.get();
assertTrue(entries != null && !entries.isEmpty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.rusefi.io.commands;

import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.generated.Fields;
import com.rusefi.tracing.Entry;
import org.jetbrains.annotations.NotNull;

import java.util.List;

import static com.rusefi.binaryprotocol.IoHelper.checkResponseCode;

public class PTraceHelper {
@NotNull
public 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.rusefi;

import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.MessagesCentral;
import com.rusefi.io.commands.PTraceHelper;
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;
import java.io.IOException;
import java.util.List;

import static com.rusefi.binaryprotocol.IoHelper.checkResponseCode;
import static com.rusefi.tools.ConsoleTools.startAndConnect;

public class PerformanceTraceHelper {
Expand All @@ -25,7 +23,7 @@ public static void grabPerformanceTrace(JComponent parent, BinaryProtocol bp) {
}

try {
List<Entry> data = requestWaitAndGetPTrace(bp);
List<Entry> data = PTraceHelper.requestWaitAndGetPTrace(bp);
if (data.isEmpty()) {
String msg = "Empty PERF_TRACE response";
JOptionPane.showMessageDialog(parent, msg, msg, JOptionPane.ERROR_MESSAGE);
Expand All @@ -41,27 +39,6 @@ public static void grabPerformanceTrace(JComponent parent, BinaryProtocol bp) {
}
}

@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();
Expand Down

0 comments on commit dea9e4f

Please sign in to comment.