Skip to content

Commit 430b719

Browse files
committed
feat: add measure of intervals between outputs
1 parent 415c7b8 commit 430b719

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

backend/src/main/java/net/laprun/sustainability/power/nuprocess/OutputRecordingProcessHandler.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,27 @@
55
import java.nio.ByteBuffer;
66
import java.util.concurrent.CompletableFuture;
77

8+
import com.zaxxer.nuprocess.NuProcess;
9+
810
import io.quarkus.logging.Log;
911

1012
public class OutputRecordingProcessHandler extends BaseProcessHandler {
1113
private final GrowableBuffer stdOutBuffer;
1214
private final CompletableFuture<InputStream> output = new CompletableFuture<>();
13-
private final boolean debug = false;
15+
private final boolean debug = true;
16+
private long startTime;
1417

1518
public OutputRecordingProcessHandler(int bufferSize, String... command) {
1619
super(command);
1720
stdOutBuffer = new GrowableBuffer(bufferSize);
1821
}
1922

23+
@Override
24+
public void onStart(NuProcess nuProcess) {
25+
super.onStart(nuProcess);
26+
startTime = System.currentTimeMillis();
27+
}
28+
2029
@Override
2130
public void onStdout(ByteBuffer buffer, boolean closed) {
2231
if (buffer.hasRemaining() && !closed) {
@@ -25,7 +34,9 @@ public void onStdout(ByteBuffer buffer, boolean closed) {
2534
var bytes = new byte[remaining];
2635
buffer.duplicate().get(bytes);
2736
final var read = new String(bytes);
28-
Log.infof("=== read %d:\n\n%s\n\n===\n", remaining, read);
37+
final var now = System.currentTimeMillis();
38+
Log.infof("=== read %d after %dms:\n\n%s\n\n===\n", remaining, now - startTime, read);
39+
startTime = now;
2940
}
3041
stdOutBuffer.put(buffer);
3142
}

0 commit comments

Comments
 (0)