diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/ProcessesForm.form b/src/main/java/com/luoboduner/moo/info/ui/form/ProcessesForm.form index 05b893c..83c49e7 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/ProcessesForm.form +++ b/src/main/java/com/luoboduner/moo/info/ui/form/ProcessesForm.form @@ -1,16 +1,16 @@
- + - + - + @@ -21,6 +21,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/ProcessesForm.java b/src/main/java/com/luoboduner/moo/info/ui/form/ProcessesForm.java index 56ced76..4cb70e0 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/ProcessesForm.java +++ b/src/main/java/com/luoboduner/moo/info/ui/form/ProcessesForm.java @@ -4,6 +4,7 @@ import cn.hutool.log.Log; import cn.hutool.log.LogFactory; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; import com.luoboduner.moo.info.App; import com.luoboduner.moo.info.ui.UiConsts; import lombok.Getter; @@ -40,6 +41,11 @@ public class ProcessesForm { private static ProcessesForm processesForm; private JPanel mainPanel; private JTable processTable; + private JRadioButton cpuButton; + private JRadioButton cumulativeCpuButton; + private JRadioButton memButton; + private JRadioButton perProc; + private JRadioButton perSystem; public static ProcessesForm getInstance() { if (processesForm == null) { @@ -56,6 +62,38 @@ public class ProcessesForm { } private static void initUi() { + resetCpuPercentButtonGroup(); + resetSortByButtonGroup(); + + processesForm = getInstance(); + if (SystemInfo.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) { + processesForm.perSystem.setSelected(true); + } else { + processesForm.perProc.setSelected(true); + } + processesForm.cpuButton.setSelected(true); + + processesForm.perProc.addActionListener(e -> { + resetCpuPercentButtonGroup(); + processesForm.perProc.setSelected(true); + }); + processesForm.perSystem.addActionListener(e -> { + resetCpuPercentButtonGroup(); + processesForm.perSystem.setSelected(true); + }); + + processesForm.cpuButton.addActionListener(e -> { + resetSortByButtonGroup(); + processesForm.cpuButton.setSelected(true); + }); + processesForm.cumulativeCpuButton.addActionListener(e -> { + resetSortByButtonGroup(); + processesForm.cumulativeCpuButton.setSelected(true); + }); + processesForm.memButton.addActionListener(e -> { + resetSortByButtonGroup(); + processesForm.memButton.setSelected(true); + }); } /** @@ -105,6 +143,7 @@ public class ProcessesForm { * @return */ private static Object[][] parseProcesses(List list, SystemInfo si) { + processesForm = getInstance(); long totalMem = si.getHardware().getMemory().getTotal(); int cpuCount = si.getHardware().getProcessor().getLogicalProcessorCount(); // Build a map with a value for each process to control the sort @@ -114,7 +153,13 @@ public class ProcessesForm { // Ignore the Idle process on Windows if (pid > 0 || !SystemInfo.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) { // Set up for appropriate sort - processSortValueMap.put(p, (double) p.getResidentSetSize()); + if (processesForm.cpuButton.isSelected()) { + processSortValueMap.put(p, p.getProcessCpuLoadBetweenTicks(priorSnapshotMap.get(pid))); + } else if (processesForm.cumulativeCpuButton.isSelected()) { + processSortValueMap.put(p, p.getProcessCpuLoadCumulative()); + } else { + processSortValueMap.put(p, (double) p.getResidentSetSize()); + } } } // Now sort the list by the values @@ -132,7 +177,11 @@ public class ProcessesForm { procArr[i][0] = pid; procArr[i][1] = p.getParentProcessID(); procArr[i][2] = p.getThreadCount(); - { + if (processesForm.perProc.isSelected()) { + procArr[i][3] = String.format("%.1f", + 100d * p.getProcessCpuLoadBetweenTicks(priorSnapshotMap.get(pid)) / cpuCount); + procArr[i][4] = String.format("%.1f", 100d * p.getProcessCpuLoadCumulative() / cpuCount); + } else { procArr[i][3] = String.format("%.1f", 100d * p.getProcessCpuLoadBetweenTicks(priorSnapshotMap.get(pid))); procArr[i][4] = String.format("%.1f", 100d * p.getProcessCpuLoadCumulative()); @@ -166,6 +215,21 @@ public class ProcessesForm { } } + private static void resetSortByButtonGroup() { + processesForm = getInstance(); + + processesForm.cpuButton.setSelected(false); + processesForm.cumulativeCpuButton.setSelected(false); + processesForm.memButton.setSelected(false); + } + + private static void resetCpuPercentButtonGroup() { + processesForm = getInstance(); + + processesForm.perProc.setSelected(false); + processesForm.perSystem.setSelected(false); + } + { // GUI initializer generated by IntelliJ IDEA GUI Designer // >>> IMPORTANT!! <<< @@ -182,11 +246,37 @@ public class ProcessesForm { */ private void $$$setupUI$$$() { mainPanel = new JPanel(); - mainPanel.setLayout(new GridLayoutManager(1, 1, new Insets(20, 20, 20, 20), -1, -1)); + mainPanel.setLayout(new GridLayoutManager(2, 1, new Insets(20, 20, 20, 20), -1, -1)); final JScrollPane scrollPane1 = new JScrollPane(); - mainPanel.add(scrollPane1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + mainPanel.add(scrollPane1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); processTable = new JTable(); scrollPane1.setViewportView(processTable); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 8, new Insets(0, 0, 10, 0), -1, -1)); + mainPanel.add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + final JLabel label1 = new JLabel(); + label1.setText("Sort by: "); + panel1.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(0, 4, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + final JLabel label2 = new JLabel(); + label2.setText("CPU %: "); + panel1.add(label2, new GridConstraints(0, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + cpuButton = new JRadioButton(); + cpuButton.setText("CPU %"); + panel1.add(cpuButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + cumulativeCpuButton = new JRadioButton(); + cumulativeCpuButton.setText("Cumulative CPU"); + panel1.add(cumulativeCpuButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + memButton = new JRadioButton(); + memButton.setText("Memory %"); + panel1.add(memButton, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + perProc = new JRadioButton(); + perProc.setText("of one Processor"); + panel1.add(perProc, new GridConstraints(0, 6, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + perSystem = new JRadioButton(); + perSystem.setText("of System"); + panel1.add(perSystem, new GridConstraints(0, 7, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); } /**