diff --git a/pom.xml b/pom.xml index b377ccf..dac8cf9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.luoboduner.moo.info MooInfo - 1.0.0 + 1.1.0 jar MooInfo @@ -26,11 +26,12 @@ 3.12.0 31.0.1-jre 4.9.3 - 1.6.5 - 1.6.5 + 2.0-rc1 + 2.0-rc1 5.7.16 1.2.78 - 5.8.5 + 5.8.6 + 1.5.3 @@ -120,6 +121,12 @@ oshi-core ${oshi-core.version} + + + org.jfree + jfreechart + ${jfreechart.version} + @@ -134,47 +141,47 @@ true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bundling-for-linux - package - - package - - - linux - true - - - + + bundling-for-windows + package + + package + + + windows + true + + + + + true + true + true + + + installForAllUsers + true + false + false + + compiler:Default.isl + + + + + + + + + + + + + + + + + diff --git a/screenshot/cpu_mac.png b/screenshot/cpu_mac.png index 61372e3..24c9636 100644 Binary files a/screenshot/cpu_mac.png and b/screenshot/cpu_mac.png differ diff --git a/screenshot/processes_mac.png b/screenshot/processes_mac.png index 6bf008c..d66a526 100644 Binary files a/screenshot/processes_mac.png and b/screenshot/processes_mac.png differ diff --git a/src/main/java/com/luoboduner/moo/info/App.java b/src/main/java/com/luoboduner/moo/info/App.java index f78c47b..4c3c66e 100644 --- a/src/main/java/com/luoboduner/moo/info/App.java +++ b/src/main/java/com/luoboduner/moo/info/App.java @@ -1,12 +1,17 @@ package com.luoboduner.moo.info; +import com.formdev.flatlaf.extras.FlatDesktop; import com.formdev.flatlaf.util.SystemInfo; import com.luoboduner.moo.info.ui.Init; +import com.luoboduner.moo.info.ui.dialog.AboutDialog; +import com.luoboduner.moo.info.ui.dialog.SettingDialog; import com.luoboduner.moo.info.ui.form.LoadingForm; import com.luoboduner.moo.info.ui.form.MainWindow; import com.luoboduner.moo.info.ui.frame.MainFrame; import com.luoboduner.moo.info.util.ConfigUtil; import com.luoboduner.moo.info.util.UpgradeUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.exception.ExceptionUtils; import javax.swing.*; import java.awt.*; @@ -17,6 +22,7 @@ * @author RememBerBer * @since 2021/11/07. */ +@Slf4j public class App { public static ConfigUtil config = ConfigUtil.getInstance(); @@ -34,6 +40,29 @@ public static void main(String[] args) { System.setProperty("apple.awt.application.name", "MooInfo"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MooInfo"); System.setProperty("apple.awt.application.appearance", "system"); + + FlatDesktop.setAboutHandler(() -> { + try { + AboutDialog dialog = new AboutDialog(); + + dialog.pack(); + dialog.setVisible(true); + } catch (Exception e2) { + log.error(ExceptionUtils.getStackTrace(e2)); + } + }); + FlatDesktop.setPreferencesHandler(() -> { + try { + SettingDialog dialog = new SettingDialog(); + + dialog.pack(); + dialog.setVisible(true); + } catch (Exception e2) { + log.error(ExceptionUtils.getStackTrace(e2)); + } + }); + FlatDesktop.setQuitHandler(FlatDesktop.QuitResponse::performQuit); + } Init.initTheme(); diff --git a/src/main/java/com/luoboduner/moo/info/ui/UiConsts.java b/src/main/java/com/luoboduner/moo/info/ui/UiConsts.java index 83fe712..30d6b95 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/UiConsts.java +++ b/src/main/java/com/luoboduner/moo/info/ui/UiConsts.java @@ -11,7 +11,7 @@ public class UiConsts { public static final String APP_NAME = "MooInfo"; - public static final String APP_VERSION = "1.0.0"; + public static final String APP_VERSION = "1.1.0"; public static final int TABLE_ROW_HEIGHT = 36; diff --git a/src/main/java/com/luoboduner/moo/info/ui/component/TopMenuBar.java b/src/main/java/com/luoboduner/moo/info/ui/component/TopMenuBar.java index c20d3af..82abc33 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/component/TopMenuBar.java +++ b/src/main/java/com/luoboduner/moo/info/ui/component/TopMenuBar.java @@ -8,6 +8,7 @@ import com.luoboduner.moo.info.ui.dialog.AboutDialog; import com.luoboduner.moo.info.ui.dialog.SettingDialog; import com.luoboduner.moo.info.ui.dialog.SystemEnvResultDialog; +import com.luoboduner.moo.info.ui.dialog.SystemInfoTestDialog; import com.luoboduner.moo.info.ui.form.MainWindow; import com.luoboduner.moo.info.util.SystemUtil; import com.luoboduner.moo.info.util.UpgradeUtil; @@ -107,6 +108,12 @@ public void init() { logMenuItem.addActionListener(e -> logActionPerformed()); appMenu.add(logMenuItem); + // System Info Test + JMenuItem syInfoTestMenuItem = new JMenuItem(); + syInfoTestMenuItem.setText("System Info Test"); + syInfoTestMenuItem.addActionListener(e -> sysInfoTestActionPerformed()); + appMenu.add(syInfoTestMenuItem); + // System environment variables JMenuItem sysEnvMenuItem = new JMenuItem(); sysEnvMenuItem.setText("System environment variables"); @@ -335,6 +342,16 @@ private void aboutActionPerformed() { } } + private void sysInfoTestActionPerformed() { + try { + SystemInfoTestDialog dialog = new SystemInfoTestDialog(); + dialog.pack(); + dialog.setVisible(true); + } catch (Exception e2) { + log.error("Show system info test dialog failed", e2); + } + } + private void sysEnvActionPerformed() { try { SystemEnvResultDialog dialog = new SystemEnvResultDialog(); diff --git a/src/main/java/com/luoboduner/moo/info/ui/dialog/SystemInfoTestDialog.form b/src/main/java/com/luoboduner/moo/info/ui/dialog/SystemInfoTestDialog.form new file mode 100644 index 0000000..367eb42 --- /dev/null +++ b/src/main/java/com/luoboduner/moo/info/ui/dialog/SystemInfoTestDialog.form @@ -0,0 +1,77 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/com/luoboduner/moo/info/ui/dialog/SystemInfoTestDialog.java b/src/main/java/com/luoboduner/moo/info/ui/dialog/SystemInfoTestDialog.java new file mode 100644 index 0000000..e64229a --- /dev/null +++ b/src/main/java/com/luoboduner/moo/info/ui/dialog/SystemInfoTestDialog.java @@ -0,0 +1,464 @@ +package com.luoboduner.moo.info.ui.dialog; + +import cn.hutool.core.thread.ThreadUtil; +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.util.ComponentUtil; +import com.luoboduner.moo.info.util.ConsoleUtil; +import oshi.SystemInfo; +import oshi.hardware.*; +import oshi.software.os.*; +import oshi.util.FormatUtil; +import oshi.util.Util; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class SystemInfoTestDialog extends JDialog { + private static final Log logger = LogFactory.get(); + + private JPanel contentPane; + private JButton buttonOK; + private JButton buttonCancel; + private JTextArea textArea1; + + public SystemInfoTestDialog() { + super(App.mainFrame, "System Info Test"); + ComponentUtil.setPreferSizeAndLocateToCenter(this, 0.6, 0.64); + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + } + }); + + buttonCancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }); + + // call onCancel() when cross is clicked + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + onCancel(); + } + }); + + // call onCancel() on ESCAPE + contentPane.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + } + + private void onOK() { + ThreadUtil.execute(this::sysInfoTest); + } + + private void sysInfoTest() { + logger.info("Initializing System..."); + SystemInfo si = new SystemInfo(); + + HardwareAbstractionLayer hal = si.getHardware(); + OperatingSystem os = si.getOperatingSystem(); + + printOperatingSystem(os); + textArea1.append("\n"); + + logger.info("Checking computer system..."); + printComputerSystem(hal.getComputerSystem()); + textArea1.append("\n"); + + logger.info("Checking Processor..."); + printProcessor(hal.getProcessor()); + textArea1.append("\n"); + + logger.info("Checking Memory..."); + printMemory(hal.getMemory()); + textArea1.append("\n"); + + logger.info("Checking CPU..."); + printCpu(hal.getProcessor()); + textArea1.append("\n"); + + logger.info("Checking Processes..."); + printProcesses(os, hal.getMemory()); + textArea1.append("\n"); + + logger.info("Checking Services..."); + printServices(os); + textArea1.append("\n"); + + logger.info("Checking Sensors..."); + printSensors(hal.getSensors()); + textArea1.append("\n"); + + logger.info("Checking Power sources..."); + printPowerSources(hal.getPowerSources()); + textArea1.append("\n"); + + logger.info("Checking Disks..."); + printDisks(hal.getDiskStores()); + textArea1.append("\n"); + + logger.info("Checking Logical Volume Groups ..."); + printLVgroups(hal.getLogicalVolumeGroups()); + textArea1.append("\n"); + + logger.info("Checking File System..."); + printFileSystem(os.getFileSystem()); + textArea1.append("\n"); + + logger.info("Checking Network interfaces..."); + printNetworkInterfaces(hal.getNetworkIFs()); + textArea1.append("\n"); + + logger.info("Checking Network parameters..."); + printNetworkParameters(os.getNetworkParams()); + textArea1.append("\n"); + + logger.info("Checking IP statistics..."); + printInternetProtocolStats(os.getInternetProtocolStats()); + textArea1.append("\n"); + + logger.info("Checking Displays..."); + printDisplays(hal.getDisplays()); + textArea1.append("\n"); + + logger.info("Checking USB Devices..."); + printUsbDevices(hal.getUsbDevices(true)); + textArea1.append("\n"); + + logger.info("Checking Sound Cards..."); + printSoundCards(hal.getSoundCards()); + textArea1.append("\n"); + + logger.info("Checking Graphics Cards..."); + printGraphicsCards(hal.getGraphicsCards()); + + JOptionPane.showMessageDialog(contentPane, "Done!\n", "Finished!", JOptionPane.PLAIN_MESSAGE); + } + + private void onCancel() { + // add your code here if necessary + dispose(); + } + + // all functions codes bellow are copied from oshi-core, and have some changed + private void printOperatingSystem(final OperatingSystem os) { + + ConsoleUtil.consoleOnly(textArea1, String.valueOf(os)); + ConsoleUtil.consoleOnly(textArea1, "Booted: " + Instant.ofEpochSecond(os.getSystemBootTime())); + ConsoleUtil.consoleOnly(textArea1, "Uptime: " + FormatUtil.formatElapsedSecs(os.getSystemUptime())); + ConsoleUtil.consoleOnly(textArea1, "Running with" + (os.isElevated() ? "" : "out") + " elevated permissions."); + ConsoleUtil.consoleOnly(textArea1, "Sessions:"); + for (OSSession s : os.getSessions()) { + ConsoleUtil.consoleOnly(textArea1, " " + s.toString()); + } + } + + private void printComputerSystem(final ComputerSystem computerSystem) { + ConsoleUtil.consoleOnly(textArea1, "System: " + computerSystem.toString()); + ConsoleUtil.consoleOnly(textArea1, " Firmware: " + computerSystem.getFirmware().toString()); + ConsoleUtil.consoleOnly(textArea1, " Baseboard: " + computerSystem.getBaseboard().toString()); + } + + private void printProcessor(CentralProcessor processor) { + ConsoleUtil.consoleOnly(textArea1, processor.toString()); + } + + private void printMemory(GlobalMemory memory) { + ConsoleUtil.consoleOnly(textArea1, "Physical Memory: \n " + memory.toString()); + VirtualMemory vm = memory.getVirtualMemory(); + ConsoleUtil.consoleOnly(textArea1, "Virtual Memory: \n " + vm.toString()); + List pmList = memory.getPhysicalMemory(); + if (!pmList.isEmpty()) { + ConsoleUtil.consoleOnly(textArea1, "Physical Memory: "); + for (PhysicalMemory pm : pmList) { + ConsoleUtil.consoleOnly(textArea1, " " + pm.toString()); + } + } + } + + private void printCpu(CentralProcessor processor) { + ConsoleUtil.consoleOnly(textArea1, "Context Switches/Interrupts: " + processor.getContextSwitches() + " / " + processor.getInterrupts()); + + long[] prevTicks = processor.getSystemCpuLoadTicks(); + long[][] prevProcTicks = processor.getProcessorCpuLoadTicks(); + ConsoleUtil.consoleOnly(textArea1, "CPU, IOWait, and IRQ ticks @ 0 sec:" + Arrays.toString(prevTicks)); + // Wait a second... + Util.sleep(1000); + long[] ticks = processor.getSystemCpuLoadTicks(); + ConsoleUtil.consoleOnly(textArea1, "CPU, IOWait, and IRQ ticks @ 1 sec:" + Arrays.toString(ticks)); + long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()]; + long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()]; + long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()]; + long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()]; + long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()]; + long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()]; + long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()]; + long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()]; + long totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal; + + ConsoleUtil.consoleOnly(textArea1, String.format( + "User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% IOwait: %.1f%% IRQ: %.1f%% SoftIRQ: %.1f%% Steal: %.1f%%", + 100d * user / totalCpu, 100d * nice / totalCpu, 100d * sys / totalCpu, 100d * idle / totalCpu, + 100d * iowait / totalCpu, 100d * irq / totalCpu, 100d * softirq / totalCpu, 100d * steal / totalCpu)); + ConsoleUtil.consoleOnly(textArea1, String.format("CPU load: %.1f%%", processor.getSystemCpuLoadBetweenTicks(prevTicks) * 100)); + double[] loadAverage = processor.getSystemLoadAverage(3); + ConsoleUtil.consoleOnly(textArea1, "CPU load averages:" + (loadAverage[0] < 0 ? " N/A" : String.format(" %.2f", loadAverage[0])) + + (loadAverage[1] < 0 ? " N/A" : String.format(" %.2f", loadAverage[1])) + + (loadAverage[2] < 0 ? " N/A" : String.format(" %.2f", loadAverage[2]))); + // per core CPU + StringBuilder procCpu = new StringBuilder("CPU load per processor:"); + double[] load = processor.getProcessorCpuLoadBetweenTicks(prevProcTicks); + for (double avg : load) { + procCpu.append(String.format(" %.1f%%", avg * 100)); + } + ConsoleUtil.consoleOnly(textArea1, procCpu.toString()); + long freq = processor.getProcessorIdentifier().getVendorFreq(); + if (freq > 0) { + ConsoleUtil.consoleOnly(textArea1, "Vendor Frequency: " + FormatUtil.formatHertz(freq)); + } + freq = processor.getMaxFreq(); + if (freq > 0) { + ConsoleUtil.consoleOnly(textArea1, "Max Frequency: " + FormatUtil.formatHertz(freq)); + } + long[] freqs = processor.getCurrentFreq(); + if (freqs[0] > 0) { + StringBuilder sb = new StringBuilder("Current Frequencies: "); + for (int i = 0; i < freqs.length; i++) { + if (i > 0) { + sb.append(", "); + } + sb.append(FormatUtil.formatHertz(freqs[i])); + } + ConsoleUtil.consoleOnly(textArea1, sb.toString()); + } + } + + private void printProcesses(OperatingSystem os, GlobalMemory memory) { + OSProcess myProc = os.getProcess(os.getProcessId()); + // current process will never be null. Other code should check for null here + ConsoleUtil.consoleOnly(textArea1, + "My PID: " + myProc.getProcessID() + " with affinity " + Long.toBinaryString(myProc.getAffinityMask())); + ConsoleUtil.consoleOnly(textArea1, "Processes: " + os.getProcessCount() + ", Threads: " + os.getThreadCount()); + // Sort by highest CPU + List procs = os.getProcesses(OperatingSystem.ProcessFiltering.ALL_PROCESSES, OperatingSystem.ProcessSorting.CPU_DESC, 5); + ConsoleUtil.consoleOnly(textArea1, " PID %CPU %MEM VSZ RSS Name"); + for (int i = 0; i < procs.size() && i < 5; i++) { + OSProcess p = procs.get(i); + ConsoleUtil.consoleOnly(textArea1, String.format(" %5d %5.1f %4.1f %9s %9s %s", p.getProcessID(), + 100d * (p.getKernelTime() + p.getUserTime()) / p.getUpTime(), + 100d * p.getResidentSetSize() / memory.getTotal(), FormatUtil.formatBytes(p.getVirtualSize()), + FormatUtil.formatBytes(p.getResidentSetSize()), p.getName())); + } + OSProcess p = os.getProcess(os.getProcessId()); + ConsoleUtil.consoleOnly(textArea1, "Current process arguments: "); + for (String s : p.getArguments()) { + ConsoleUtil.consoleOnly(textArea1, " " + s); + } + ConsoleUtil.consoleOnly(textArea1, "Current process environment: "); + for (Map.Entry e : p.getEnvironmentVariables().entrySet()) { + ConsoleUtil.consoleOnly(textArea1, " " + e.getKey() + "=" + e.getValue()); + } + } + + private void printServices(OperatingSystem os) { + ConsoleUtil.consoleOnly(textArea1, "Services: "); + ConsoleUtil.consoleOnly(textArea1, " PID State Name"); + // DO 5 each of running and stopped + int i = 0; + for (OSService s : os.getServices()) { + if (s.getState().equals(OSService.State.RUNNING) && i++ < 5) { + ConsoleUtil.consoleOnly(textArea1, String.format(" %5d %7s %s", s.getProcessID(), s.getState(), s.getName())); + } + } + i = 0; + for (OSService s : os.getServices()) { + if (s.getState().equals(OSService.State.STOPPED) && i++ < 5) { + ConsoleUtil.consoleOnly(textArea1, String.format(" %5d %7s %s", s.getProcessID(), s.getState(), s.getName())); + } + } + } + + private void printSensors(Sensors sensors) { + ConsoleUtil.consoleOnly(textArea1, "Sensors: " + sensors.toString()); + } + + private void printPowerSources(List list) { + StringBuilder sb = new StringBuilder("Power Sources: "); + if (list.isEmpty()) { + sb.append("Unknown"); + } + for (PowerSource powerSource : list) { + sb.append("\n ").append(powerSource.toString()); + } + ConsoleUtil.consoleOnly(textArea1, sb.toString()); + } + + private void printDisks(List list) { + ConsoleUtil.consoleOnly(textArea1, "Disks:"); + for (HWDiskStore disk : list) { + ConsoleUtil.consoleOnly(textArea1, " " + disk.toString()); + + List partitions = disk.getPartitions(); + for (HWPartition part : partitions) { + ConsoleUtil.consoleOnly(textArea1, " |-- " + part.toString()); + } + } + + } + + private void printLVgroups(List list) { + if (!list.isEmpty()) { + ConsoleUtil.consoleOnly(textArea1, "Logical Volume Groups:"); + for (LogicalVolumeGroup lvg : list) { + ConsoleUtil.consoleOnly(textArea1, " " + lvg.toString()); + } + } + } + + private void printFileSystem(FileSystem fileSystem) { + ConsoleUtil.consoleOnly(textArea1, "File System:"); + + ConsoleUtil.consoleOnly(textArea1, String.format(" File Descriptors: %d/%d", fileSystem.getOpenFileDescriptors(), + fileSystem.getMaxFileDescriptors())); + + for (OSFileStore fs : fileSystem.getFileStores()) { + long usable = fs.getUsableSpace(); + long total = fs.getTotalSpace(); + ConsoleUtil.consoleOnly(textArea1, String.format( + " %s (%s) [%s] %s of %s free (%.1f%%), %s of %s files free (%.1f%%) is %s " + + (fs.getLogicalVolume() != null && fs.getLogicalVolume().length() > 0 ? "[%s]" : "%s") + + " and is mounted at %s", + fs.getName(), fs.getDescription().isEmpty() ? "file system" : fs.getDescription(), fs.getType(), + FormatUtil.formatBytes(usable), FormatUtil.formatBytes(fs.getTotalSpace()), 100d * usable / total, + FormatUtil.formatValue(fs.getFreeInodes(), ""), FormatUtil.formatValue(fs.getTotalInodes(), ""), + 100d * fs.getFreeInodes() / fs.getTotalInodes(), fs.getVolume(), fs.getLogicalVolume(), + fs.getMount())); + } + } + + private void printNetworkInterfaces(List list) { + StringBuilder sb = new StringBuilder("Network Interfaces:"); + if (list.isEmpty()) { + sb.append(" Unknown"); + } else { + for (NetworkIF net : list) { + sb.append("\n ").append(net.toString()); + } + } + ConsoleUtil.consoleOnly(textArea1, sb.toString()); + } + + private void printNetworkParameters(NetworkParams networkParams) { + ConsoleUtil.consoleOnly(textArea1, "Network parameters:\n " + networkParams.toString()); + } + + private void printInternetProtocolStats(InternetProtocolStats ip) { + ConsoleUtil.consoleOnly(textArea1, "Internet Protocol statistics:"); + ConsoleUtil.consoleOnly(textArea1, " TCPv4: " + ip.getTCPv4Stats()); + ConsoleUtil.consoleOnly(textArea1, " TCPv6: " + ip.getTCPv6Stats()); + ConsoleUtil.consoleOnly(textArea1, " UDPv4: " + ip.getUDPv4Stats()); + ConsoleUtil.consoleOnly(textArea1, " UDPv6: " + ip.getUDPv6Stats()); + } + + private void printDisplays(List list) { + ConsoleUtil.consoleOnly(textArea1, "Displays:"); + int i = 0; + for (Display display : list) { + ConsoleUtil.consoleOnly(textArea1, " Display " + i + ":"); + ConsoleUtil.consoleOnly(textArea1, String.valueOf(display)); + i++; + } + } + + private void printUsbDevices(List list) { + ConsoleUtil.consoleOnly(textArea1, "USB Devices:"); + for (UsbDevice usbDevice : list) { + ConsoleUtil.consoleOnly(textArea1, String.valueOf(usbDevice)); + } + } + + private void printSoundCards(List list) { + ConsoleUtil.consoleOnly(textArea1, "Sound Cards:"); + for (SoundCard card : list) { + ConsoleUtil.consoleOnly(textArea1, " " + String.valueOf(card)); + } + } + + private void printGraphicsCards(List list) { + ConsoleUtil.consoleOnly(textArea1, "Graphics Cards:"); + if (list.isEmpty()) { + ConsoleUtil.consoleOnly(textArea1, " None detected."); + } else { + for (GraphicsCard card : list) { + ConsoleUtil.consoleOnly(textArea1, " " + String.valueOf(card)); + } + } + } + + { +// GUI initializer generated by IntelliJ IDEA GUI Designer +// >>> IMPORTANT!! <<< +// DO NOT EDIT OR ADD ANY CODE HERE! + $$$setupUI$$$(); + } + + /** + * Method generated by IntelliJ IDEA GUI Designer + * >>> IMPORTANT!! <<< + * DO NOT edit this method OR call it in your code! + * + * @noinspection ALL + */ + private void $$$setupUI$$$() { + contentPane = new JPanel(); + contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + final JPanel panel2 = new JPanel(); + panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false)); + panel1.add(panel2, new GridConstraints(0, 1, 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)); + buttonOK = new JButton(); + buttonOK.setText("Start"); + panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + buttonCancel = new JButton(); + buttonCancel.setText("Cancel"); + panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JPanel panel3 = new JPanel(); + panel3.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel3, 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 JScrollPane scrollPane1 = new JScrollPane(); + panel3.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)); + textArea1 = new JTextArea(); + scrollPane1.setViewportView(textArea1); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return contentPane; + } + +} diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/CpuForm.form b/src/main/java/com/luoboduner/moo/info/ui/form/CpuForm.form index aa88354..c843346 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/CpuForm.form +++ b/src/main/java/com/luoboduner/moo/info/ui/form/CpuForm.form @@ -36,8 +36,8 @@ - - + + @@ -45,7 +45,7 @@ - + @@ -69,7 +69,7 @@ - + @@ -96,7 +96,7 @@ - + @@ -122,9 +122,18 @@ - + + + + + + + + + + diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/CpuForm.java b/src/main/java/com/luoboduner/moo/info/ui/form/CpuForm.java index 3251db4..3530087 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/CpuForm.java +++ b/src/main/java/com/luoboduner/moo/info/ui/form/CpuForm.java @@ -9,6 +9,11 @@ import com.luoboduner.moo.info.ui.Style; import com.luoboduner.moo.info.util.ScrollUtil; import lombok.Getter; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.data.time.DynamicTimeSeriesCollection; +import org.jfree.data.time.Second; import oshi.hardware.CentralProcessor; import oshi.hardware.Sensors; @@ -17,8 +22,11 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.text.DecimalFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -53,6 +61,7 @@ public class CpuForm { private JLabel voltageLabel; private JLabel fanSpeedsLabel; private JSplitPane splitPane; + private JPanel chartPanel; private static final Log logger = LogFactory.get(); @@ -65,6 +74,8 @@ public class CpuForm { private static List processorProgressBars; private static List processorTextFields; + private static DynamicTimeSeriesCollection sysData; + public static CpuForm getInstance() { if (cpuForm == null) { cpuForm = new CpuForm(); @@ -143,6 +154,31 @@ private static void initUi() { processorTextFields.add(textField); } + // Codes bellow are copied from oshi demo. + Date date = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()); + sysData = new DynamicTimeSeriesCollection(1, 60, new Second()); + sysData.setTimeBase(new Second(date)); + sysData.addSeries(floatArrayPercent(cpuData(cpu)), 0, "All cpus"); + + JFreeChart systemCpu = ChartFactory.createTimeSeriesChart(null, null, null, sysData, false, + true, false); + + systemCpu.setBackgroundPaint(cpuForm.getChartPanel().getBackground()); + systemCpu.setAntiAlias(true); + systemCpu.getXYPlot().setDomainGridlinesVisible(false); + systemCpu.getXYPlot().setRangeGridlinesVisible(false); + systemCpu.getXYPlot().setBackgroundPaint(cpuForm.getScuProgressBar().getBackground()); + systemCpu.getXYPlot().setOutlinePaint(cpuForm.getScuProgressBar().getBackground()); + systemCpu.getXYPlot().getRenderer().setSeriesPaint(0, cpuForm.getScuProgressBar().getForeground()); + systemCpu.getXYPlot().getRenderer().setSeriesStroke(0, new BasicStroke(2f)); + systemCpu.getXYPlot().getDomainAxis().setVisible(false); + systemCpu.getXYPlot().getRangeAxis().setVisible(false); + + cpuForm.getChartPanel().setPreferredSize(new Dimension(-1, 100)); + cpuForm.getChartPanel().setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); + cpuForm.getChartPanel().add(new ChartPanel(systemCpu), new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(150, 50), null, 0, false)); + + } private static void initCpuInfo() { @@ -200,6 +236,9 @@ private static void initPcuInfo() { long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()]; long totalCpu = Math.max(user + nice + cSys + idle + ioWait + irq + softIrq + steal, 0); + sysData.advanceTime(); + sysData.appendData(floatArrayPercent(cpuData(processor))); + prevTicks = ticks; double free = Double.parseDouble(format.format(idle <= 0 ? 0 : (100d * idle / totalCpu))); @@ -291,6 +330,32 @@ private static void initIndicatorInfo() { cpuForm.getFanSpeedsLabel().setText(Arrays.toString(sensors.getFanSpeeds())); } + /** + * Codes are copied from oshi demo. + * + * @param d + * @return + */ + private static float[] floatArrayPercent(double d) { + float[] f = new float[1]; + f[0] = (float) (100d * d); + return f; + } + + /** + * Codes are copied from oshi demo. + * + * @param proc + * @return + */ + private static double cpuData(CentralProcessor proc) { + if (prevTicks == null) { + return 0; + } + double d = proc.getSystemCpuLoadBetweenTicks(prevTicks); + return d; + } + { // GUI initializer generated by IntelliJ IDEA GUI Designer // >>> IMPORTANT!! <<< @@ -319,11 +384,11 @@ private static void initIndicatorInfo() { scrollPaneLeft = new JScrollPane(); panel2.add(scrollPaneLeft, 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)); final JPanel panel3 = new JPanel(); - panel3.setLayout(new GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1)); + panel3.setLayout(new GridLayoutManager(5, 1, new Insets(8, 0, 0, 0), -1, -1)); scrollPaneLeft.setViewportView(panel3); scuPanel = new JPanel(); scuPanel.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); - panel3.add(scuPanel, 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)); + panel3.add(scuPanel, new GridConstraints(1, 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)); scuTitleLabel = new JLabel(); scuTitleLabel.setText("System CPU Usage"); scuPanel.add(scuTitleLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); @@ -331,7 +396,7 @@ private static void initIndicatorInfo() { scuPanel.add(scuProgressBar, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); pcuPanel = new JPanel(); pcuPanel.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); - panel3.add(pcuPanel, new GridConstraints(1, 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)); + panel3.add(pcuPanel, new GridConstraints(2, 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)); pcuTitleLabel = new JLabel(); pcuTitleLabel.setText("Processor CPU Usage"); pcuPanel.add(pcuTitleLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); @@ -340,7 +405,7 @@ private static void initIndicatorInfo() { pcuPanel.add(pcuProgressBarPanel, new GridConstraints(1, 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)); panel1 = new JPanel(); panel1.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); - panel3.add(panel1, new GridConstraints(2, 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)); + panel3.add(panel1, new GridConstraints(3, 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)); pcfLabel = new JLabel(); pcfLabel.setText("Processor CPU Frequency"); panel1.add(pcfLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); @@ -348,7 +413,10 @@ private static void initIndicatorInfo() { pcfPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); panel1.add(pcfPanel, new GridConstraints(1, 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 Spacer spacer1 = new Spacer(); - panel3.add(spacer1, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + panel3.add(spacer1, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + chartPanel = new JPanel(); + chartPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); + panel3.add(chartPanel, 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 JPanel panel4 = new JPanel(); panel4.setLayout(new GridLayoutManager(3, 1, new Insets(10, 0, 10, 10), -1, -1)); splitPane.setRightComponent(panel4); diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/DetailForm.java b/src/main/java/com/luoboduner/moo/info/ui/form/DetailForm.java index c4c00d2..0ba1ab7 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/DetailForm.java +++ b/src/main/java/com/luoboduner/moo/info/ui/form/DetailForm.java @@ -9,8 +9,10 @@ import com.intellij.uiDesigner.core.Spacer; import com.luoboduner.moo.info.App; import com.luoboduner.moo.info.ui.Style; +import com.luoboduner.moo.info.util.DateTimeUtil; import com.luoboduner.moo.info.util.ScrollUtil; import lombok.Getter; +import org.apache.commons.lang3.time.DateFormatUtils; import oshi.hardware.*; import oshi.software.os.NetworkParams; import oshi.software.os.OperatingSystem; @@ -146,8 +148,8 @@ private static String getOsInfo() { builder.append("
Open File Descriptors: ").append(operatingSystem.getFileSystem().getOpenFileDescriptors()); builder.append("
Thread Count: ").append(operatingSystem.getThreadCount()); builder.append("
Process Count: ").append(operatingSystem.getProcessCount()); - builder.append("
System Boot Time: ").append(operatingSystem.getSystemBootTime()); - builder.append("
System Uptime: ").append(operatingSystem.getSystemUptime()); + builder.append("
System Boot Time: ").append(DateFormatUtils.format(operatingSystem.getSystemBootTime() * 1000, "yyyy-MM-dd HH:mm:ss")); + builder.append("
System Uptime: ").append(DateTimeUtil.toReadableTime(operatingSystem.getSystemUptime())); return builder.toString(); } 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.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 static void init() { } 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 @@ private static void initInfo() { * @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 @@ private static Object[][] parseProcesses(List list, SystemInfo si) { // 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 @@ private static Object[][] parseProcesses(List list, SystemInfo si) { 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 @@ private static void resizeColumns(TableColumnModel tableColumnModel) { } } + 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 @@ private static void resizeColumns(TableColumnModel tableColumnModel) { */ 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)); } /** diff --git a/src/main/java/com/luoboduner/moo/info/util/ConsoleUtil.java b/src/main/java/com/luoboduner/moo/info/util/ConsoleUtil.java new file mode 100644 index 0000000..af7979b --- /dev/null +++ b/src/main/java/com/luoboduner/moo/info/util/ConsoleUtil.java @@ -0,0 +1,36 @@ +package com.luoboduner.moo.info.util; + +import cn.hutool.log.Log; +import cn.hutool.log.LogFactory; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.time.DateFormatUtils; + +import javax.swing.*; +import java.util.Date; + +/** + *
+ * ConsoleUtil to print text into textarea
+ * 
+ * + * @author RememBerBer + * @since 2021/12/15. + */ +@Slf4j +public class ConsoleUtil { + + private static final Log logger = LogFactory.get(); + + public static void consoleWithLog(JTextArea textArea, String log) { + textArea.append(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS") + " "); + textArea.append(log + "\n"); + textArea.setCaretPosition(textArea.getText().length()); + logger.warn(log); + } + + public static void consoleOnly(JTextArea textArea, String log) { + textArea.append(log + "\n"); + textArea.setCaretPosition(textArea.getText().length()); + } + +} diff --git a/src/main/java/com/luoboduner/moo/info/util/DateTimeUtil.java b/src/main/java/com/luoboduner/moo/info/util/DateTimeUtil.java new file mode 100644 index 0000000..2dc8bef --- /dev/null +++ b/src/main/java/com/luoboduner/moo/info/util/DateTimeUtil.java @@ -0,0 +1,14 @@ +package com.luoboduner.moo.info.util; + +public class DateTimeUtil { + + public static String toReadableTime(long seconds) { + String readableTime; + int hours = (int) (seconds / 3600); + int minutes = (int) (seconds % 3600 / 60); + readableTime = String.format("%dh:%02dmin", hours, minutes); + + return readableTime; + } + +} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 19f778a..d29c463 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -13,6 +13,11 @@ %date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} :%line - %msg%n + + ERROR + ACCEPT + DENY + diff --git a/src/main/resources/version_summary.json b/src/main/resources/version_summary.json index 8acae24..ecc3d99 100644 --- a/src/main/resources/version_summary.json +++ b/src/main/resources/version_summary.json @@ -1,8 +1,9 @@ { - "currentVersion": "1.0.0", + "currentVersion": "1.1.0", "versionIndex": { "0.0.0": "0", - "1.0.0": "1" + "1.0.0": "1", + "1.1.0": "2" }, "versionDetailList": [ { @@ -14,6 +15,11 @@ "version": "1.0.0", "title": "The first version", "log": "The first version\n" + }, + { + "version": "1.1.0", + "title": "Some minor features and optimizations", + "log": "● update oshi-core to 5.8.6\n● update flatlaf to 2.0-rc1(Support Windows 11 snap layouts menu, macOS screen menu optimization)\n● processes sort method added same as the oshi's demo\n● add cpu usage chart\n● make System Boot Time and Uptime readable\n● add System Info Test function menu same as oshi-core\n" } ] } \ No newline at end of file