Commit 5f676ce9 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

CLAUDE: McpServer: hold balanced power profile while MCP is running



Spawns attic/elphel-agent-tools/bin/cpu_profile_hold.py on startup,
which calls power-profiles-daemon HoldProfile('balanced') via DBus.
Released automatically via SIGTERM on JVM shutdown.

Design: KDE AC default is power-saver; this hold raises the profile to
balanced (hardware-driven boost under load) while ImageJ is running,
then releases it so the machine drops back to power-saver on exit.

Co-authored-by: default avatarClaude <claude@elphel.com>
parent b7cd20d7
Loading
Loading
Loading
Loading
+23 −0
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ import com.sun.net.httpserver.HttpServer;


public class McpServer {
public class McpServer {
    private static McpServer INSTANCE;
    private static McpServer INSTANCE;
    private static Process powerHoldProcess;


    private final Eyesis_Correction owner;
    private final Eyesis_Correction owner;
    private final int port;
    private final int port;
@@ -57,6 +58,7 @@ public class McpServer {
        McpFsAccess.ensureConfigured();
        McpFsAccess.ensureConfigured();
        McpServer instance = new McpServer(owner, port);
        McpServer instance = new McpServer(owner, port);
        instance.start();
        instance.start();
        startPowerHold();
        if (hasReverseSshTunnel(port)) {
        if (hasReverseSshTunnel(port)) {
            System.out.println("MCP: reverse SSH tunnel detected for port " + port);
            System.out.println("MCP: reverse SSH tunnel detected for port " + port);
        } else {
        } else {
@@ -66,6 +68,27 @@ public class McpServer {
        return instance;
        return instance;
    }
    }


    private static void startPowerHold() {
        java.io.File script = new java.io.File(
                System.getProperty("user.dir"),
                "attic/elphel-agent-tools/bin/cpu_profile_hold.py");
        if (!script.exists()) return;
        try {
            powerHoldProcess = new ProcessBuilder("python3", script.getAbsolutePath())
                    .redirectErrorStream(true)
                    .start();
            Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                if (powerHoldProcess != null && powerHoldProcess.isAlive()) {
                    powerHoldProcess.destroy();
                }
            }, "cpu-profile-hold-release"));
            System.out.println("MCP: power profile hold started (balanced, pid="
                    + powerHoldProcess.pid() + ")");
        } catch (Exception e) {
            System.out.println("MCP: could not start power profile hold: " + e.getMessage());
        }
    }

    private static boolean hasReverseSshTunnel(int port) {
    private static boolean hasReverseSshTunnel(int port) {
        String needle = "127.0.0.1:" + port + ":127.0.0.1:" + port;
        String needle = "127.0.0.1:" + port + ":127.0.0.1:" + port;
        final boolean[] found = new boolean[] { false };
        final boolean[] found = new boolean[] { false };