diff --git a/modules/cells/src/main/java/dmg/cells/nucleus/CellShell.java b/modules/cells/src/main/java/dmg/cells/nucleus/CellShell.java index 1083b1e2827..838b9d3e976 100644 --- a/modules/cells/src/main/java/dmg/cells/nucleus/CellShell.java +++ b/modules/cells/src/main/java/dmg/cells/nucleus/CellShell.java @@ -54,8 +54,10 @@ import dmg.util.CommandPanicException; import dmg.util.CommandSyntaxException; import dmg.util.CommandThrowableException; +import dmg.util.CpuUsage; import dmg.util.Exceptions; import dmg.util.Formats; +import dmg.util.FractionalCpuUsage; import dmg.util.PropertiesBackedReplaceable; import dmg.util.Replaceable; import dmg.util.ReplaceableBackedProperties; @@ -69,6 +71,7 @@ import org.dcache.util.Args; import org.dcache.util.ColumnWriter; +import org.dcache.util.ColumnWriter.TabulatedRow; import org.dcache.util.Glob; import static dmg.util.CommandException.checkCommand; @@ -978,33 +981,58 @@ private void appendWithIndentation(String indentation, String value) public String call() { if (names == null) { - List list = _nucleus.getCellNames(); - if (full) { - ColumnWriter table = new ColumnWriter().headersInColumns() + List list = _nucleus.getCellNames(); + if (full) { + Map cellCpuUsage = CellNucleus.getFractionalCellCpuUsage(); + + ColumnWriter table = new ColumnWriter().headersInColumns() .header("Name").left("name").space() .header("State").centre("state").space() .header("Queue").right("queue-length").space() .header("Q-time/ms").right("queue-time").space() - .header("Threads").right("thread").space() - .header("Class").left("class").space() + .header("Threads").right("thread").space(); + if (!cellCpuUsage.isEmpty()) { + table.header("System CPU").right("system-cpu").space() + .header("User CPU").right("user-cpu").space(); + } + + table.header("Class").left("class").space() .header("Additional info").left("short-info"); for (String name: list) { CellInfo info = _nucleus.getCellInfo(name); + FractionalCpuUsage cpuUsage = cellCpuUsage.get(name); if (info == null) { table.row("name " + name); } else { - // Work around cells where toString shows only - // the cell name. - String shortInfo = info.getShortInfo().equals(name) ? "" : info.getShortInfo(); - table.row().value("name", name) + // Work around cells where toString shows only + // the cell name. + String shortInfo = info.getShortInfo().equals(name) ? "" : info.getShortInfo(); + + TabulatedRow row = table.row().value("name", name) .value("state", info.getStateName().substring(0,1)) .value("queue-length", info.getEventQueueSize()) .value("queue-time", info.getExpectedQueueTime()) .value("thread", info.getThreadCount()) .value("class", info.getCellSimpleClass()) .value("short-info", shortInfo); + + if (cpuUsage != null) { + String systemUsage = String.format("%.1f%%", cpuUsage.getSystemUsage()*100); + String userUsage = String.format("%.1f%%", cpuUsage.getUserUsage()*100); + row.value("system-cpu", systemUsage) + .value("user-cpu", userUsage); + } } } + FractionalCpuUsage unknownUsage = cellCpuUsage.get("UNKNOWN"); + if (unknownUsage != null) { + String systemUsage = String.format("%.1f%%", unknownUsage.getSystemUsage()*100); + String userUsage = String.format("%.1f%%", unknownUsage.getUserUsage()*100); + table.row().value("name", "UNKNOWN") + .value("system-cpu", systemUsage) + .value("user-cpu", userUsage); + } + sb.append(table); } else { for (String name: list) {