MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / MemoryMonitor

Class MemoryMonitor

ij/src/main/java/ij/plugin/frame/MemoryMonitor.java:11–132  ·  view source on GitHub ↗

This plugin continuously plots ImageJ's memory utilization. Click on the plot to force the JVM to do garbage collection.

Source from the content-addressed store, hash-verified

9/** This plugin continuously plots ImageJ's memory utilization.
10 Click on the plot to force the JVM to do garbage collection. */
11public class MemoryMonitor extends PlugInFrame {
12 private static final double scale = Prefs.getGuiScale();
13 private static final int width = (int)(250*scale);
14 private static final int height = (int)(90*scale);
15 private static final String LOC_KEY = "memory.loc";
16 private static MemoryMonitor instance;
17 private Image image;
18 private Graphics2D g;
19 private int frames;
20 private double[] mem;
21 private int index;
22 private long value;
23 private double defaultMax = 20*1024*1024; // 20MB
24 private double max = defaultMax;
25 private long maxMemory = IJ.maxMemory();
26 private boolean done;
27
28 public MemoryMonitor() {
29 super("Memory");
30 if (instance!=null) {
31 WindowManager.toFront(instance);
32 return;
33 }
34 instance = this;
35 WindowManager.addWindow(this);
36
37 setLayout(new BorderLayout());
38 Canvas ic = new PlotCanvas();
39 ic.setSize(width, height);
40 add(ic);
41 setResizable(false);
42 pack();
43 Point loc = Prefs.getLocation(LOC_KEY);
44 if (loc!=null)
45 setLocation(loc);
46 else
47 GUI.centerOnImageJScreen(this);
48 image = createImage(width,height);
49 g = (Graphics2D)image.getGraphics();
50 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
51 g.setColor(Color.white);
52 g.fillRect(0, 0, width, height);
53 g.setFont(new Font("SansSerif",Font.PLAIN,(int)(12*Prefs.getGuiScale())));
54 show();
55 ImageJ ij = IJ.getInstance();
56 if (ij!=null) {
57 addKeyListener(ij);
58 ic.addKeyListener(ij);
59 ic.addMouseListener(ij);
60 }
61 mem = new double[width+1];
62 Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
63 while (!done) {
64 updatePlot();
65 addText();
66 ic.repaint();
67 IJ.wait(50);
68 frames++;

Callers

nothing calls this directly

Calls 2

getGuiScaleMethod · 0.95
maxMemoryMethod · 0.95

Tested by

no test coverage detected