New CPUPanel to show process load vs. system load.

Small cleanup.
This commit is contained in:
Fabian Becker 2014-11-18 17:15:40 +01:00
parent 91549862f1
commit ad7a5ea86c
4 changed files with 89 additions and 7 deletions

View File

@ -0,0 +1,80 @@
package eva2.gui;
import com.sun.management.OperatingSystemMXBean;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.management.ManagementFactory;
import java.util.LinkedList;
/**
* Small Panel that shows the current OS and Process CPU usage.
*
* Sliding window with n time steps, where each time step has a
* resolution of 500ms.
*/
public class CPUPanel extends JPanel {
private LinkedList<Double> processLoadList = new LinkedList<>();
private LinkedList<Double> osLoadList = new LinkedList<>();
private int maxTimeSteps = 100;
private OperatingSystemMXBean osBean;
public CPUPanel(int timeSteps) {
Timer timer = new Timer(500, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CPUPanel.this.updateLoad();
CPUPanel.this.repaint();
}
});
timer.start();
maxTimeSteps = timeSteps;
setMinimumSize(new Dimension(timeSteps, 1));
setPreferredSize(new Dimension(timeSteps, 1));
osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
}
private void updateLoad() {
// What % CPU load this current JVM is taking, from 0.0-1.0
processLoadList.add(osBean.getProcessCpuLoad());
// What % load the overall system is at, from 0.0-1.0
osLoadList.add(osBean.getSystemCpuLoad());
if (processLoadList.size() > maxTimeSteps) {
processLoadList.removeFirst();
}
if (osLoadList.size() > maxTimeSteps) {
osLoadList.removeFirst();
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Dimension panelSize = this.getSize();
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setColor(Color.LIGHT_GRAY);
int pos = maxTimeSteps - osLoadList.size();
for(Double load : osLoadList) {
g2d.drawLine(pos, panelSize.height - 1, pos, (int)(panelSize.height - 1 - (panelSize.height * load)));
pos++;
}
g2d.setColor(Color.GREEN);
pos = maxTimeSteps - processLoadList.size();
for(Double load : processLoadList) {
g2d.drawLine(pos, panelSize.height - 1, pos, (int)(panelSize.height - 1 - (panelSize.height * load)));
pos++;
}
}
}

View File

@ -457,6 +457,14 @@ public class Main extends JFrame implements OptimizationStateListener {
progressBar.setStringPainted(true);
statusBarControls.add(progressBar);
statusBarControls.add(Box.createHorizontalStrut(5));
statusBarControls.add(new JSeparator(JSeparator.VERTICAL));
statusBarControls.add(Box.createHorizontalStrut(5));
/* Create ProgressBar and add it to the status bar */
statusBarControls.add(new JLabel("CPU"));
statusBarControls.add(Box.createHorizontalStrut(5));
statusBarControls.add(new CPUPanel(100));
statusBar.add(statusBarControls);
gbConstraints.gridx = 0;

View File

@ -170,7 +170,6 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
if (isOptimizationRunning() && saveParams) {
try {
optimizationParameters.saveInstance();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Could not save optimization instance!", e);
}
@ -231,7 +230,6 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
InterfaceTerminator terminator = this.optimizationParameters.getTerminator();
InterfaceOptimizer optimizer = this.optimizationParameters.getOptimizer();
InterfaceOptimizationProblem problem = this.optimizationParameters.getProblem();
optimizer.addPopulationChangedEventListener(this);
/**
* We keep the optimization running until it is aborted by the user or
@ -261,7 +259,6 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
*/
do {
maybeUpdateParamCtrl(optimizationParameters);
optimizer.optimize();
} while (isOptimizationRunning() && !terminator.isTerminated(optimizer.getAllSolutions()));

View File

@ -1,7 +1,6 @@
package eva2.util;
import eva2.gui.LoggingPanel;
import eva2.optimization.EvAMainAdapter;
import eva2.optimization.EvAMainAdapterImpl;
import eva2.optimization.go.InterfaceOptimizationParameters;
@ -14,7 +13,6 @@ import java.util.logging.Logger;
*/
public class EvAComAdapter {
private final static Logger LOGGER = Logger.getLogger(EvAComAdapter.class.getName());
private LoggingPanel loggingPanel;
private EvAMainAdapterImpl localMainAdapter;
private static EvAComAdapter instance;
@ -58,13 +56,12 @@ public class EvAComAdapter {
*/
public String[] getModuleNameList() {
System.exit(1);
System.out.println("SAYYYYY WHAAAAAT?");
String[] list = getLocalMainAdapter().getModuleNameList();
LOGGER.info("List of modules available:");
if (list != null) {
for (String item : list) {
if (!item.isEmpty() && loggingPanel != null) {
if (!item.isEmpty()) {
LOGGER.info(item);
}
}