All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hyperfoil.cli.commands.Cpu Maven / Gradle / Ivy

package io.hyperfoil.cli.commands;

import java.util.Map;

import org.aesh.command.CommandDefinition;
import org.aesh.command.CommandException;
import org.aesh.command.CommandResult;

import io.hyperfoil.cli.Table;
import io.hyperfoil.cli.context.HyperfoilCommandInvocation;
import io.hyperfoil.controller.Client;

@CommandDefinition(name = "cpu", description = "Show agent CPU usage")
public class Cpu extends BaseRunIdCommand {

   @Override
   public CommandResult execute(HyperfoilCommandInvocation invocation) throws CommandException, InterruptedException {
      Client.RunRef runRef = getRunRef(invocation);
      Map> cpu = runRef.agentCpu();
      if (cpu == null || cpu.isEmpty()) {
         invocation.println("No agent CPU data available from run " + runRef.id() + " (maybe not completed yet).");
         return CommandResult.FAILURE;
      }
      Table>> table = new Table<>();
      table.column("PHASE", Map.Entry::getKey);
      String[] agents = cpu.values().stream().flatMap(e -> e.keySet().stream()).sorted().distinct().toArray(String[]::new);
      for (String agent : agents) {
         table.column(agent, e -> e.getValue().get(agent));
      }
      table.print(invocation, cpu.entrySet().stream());
      return CommandResult.SUCCESS;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy