mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GP-3844: Replacing the 'Show VM Memory' dialog with an upgraded 'Runtime Information' dialog
This commit is contained in:
parent
f739df7c21
commit
8c89a8bb3c
19 changed files with 949 additions and 594 deletions
|
@ -1,88 +0,0 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.app.plugin.debug;
|
||||
|
||||
import docking.ActionContext;
|
||||
import docking.DialogComponentProvider;
|
||||
import docking.action.DockingAction;
|
||||
import docking.action.MenuData;
|
||||
import ghidra.app.plugin.PluginCategoryNames;
|
||||
import ghidra.framework.main.ApplicationLevelOnlyPlugin;
|
||||
import ghidra.framework.main.UtilityPluginPackage;
|
||||
import ghidra.framework.plugintool.*;
|
||||
import ghidra.framework.plugintool.util.PluginStatus;
|
||||
import ghidra.util.HelpLocation;
|
||||
|
||||
//@formatter:off
|
||||
@PluginInfo(
|
||||
status = PluginStatus.RELEASED,
|
||||
packageName = UtilityPluginPackage.NAME,
|
||||
category = PluginCategoryNames.SUPPORT,
|
||||
shortDescription = "VM Memory Display",
|
||||
description = "Plugin for displaying the VM memory information."
|
||||
)
|
||||
//@formatter:on
|
||||
public class MemoryUsagePlugin extends Plugin implements ApplicationLevelOnlyPlugin {
|
||||
private DialogComponentProvider dialog;
|
||||
|
||||
public MemoryUsagePlugin(PluginTool tool) {
|
||||
|
||||
super(tool);
|
||||
|
||||
setupActions();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispose() {
|
||||
super.dispose();
|
||||
|
||||
if (dialog != null) {
|
||||
dialog.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupActions() {
|
||||
DockingAction action;
|
||||
|
||||
// add menu action for Hello->Program
|
||||
action = new DockingAction("Show VM memory", getName()) {
|
||||
@Override
|
||||
public void actionPerformed(ActionContext context) {
|
||||
showMemory();
|
||||
}
|
||||
};
|
||||
|
||||
action.setEnabled(true);
|
||||
action.setHelpLocation(new HelpLocation("FrontEndPlugin", "ShowMemoryUsage"));
|
||||
String group = "YYY"; // trying to put this just above the last menu entry
|
||||
action.setMenuBarData(new MenuData(new String[] { "Help", "Show VM Memory" }, group));
|
||||
tool.addAction(action);
|
||||
|
||||
}
|
||||
|
||||
void clearDialog() {
|
||||
dialog = null;
|
||||
}
|
||||
|
||||
public void showMemory() {
|
||||
if (dialog == null) {
|
||||
dialog = new ShowMemoryDialog(this);
|
||||
}
|
||||
else {
|
||||
dialog.toFront();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.app.plugin.debug;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import docking.ReusableDialogComponentProvider;
|
||||
import docking.widgets.label.GDLabel;
|
||||
import docking.widgets.label.GLabel;
|
||||
import ghidra.util.layout.PairLayout;
|
||||
|
||||
class ShowMemoryDialog extends ReusableDialogComponentProvider {
|
||||
private MemoryUsagePlugin plugin;
|
||||
private JLabel maxMem;
|
||||
private JLabel totalMem;
|
||||
private JLabel freeMem;
|
||||
private JLabel usedMem;
|
||||
private Timer timer;
|
||||
|
||||
ShowMemoryDialog(MemoryUsagePlugin plugin) {
|
||||
super("VM Memory Usage", false, false, true, false);
|
||||
this.plugin = plugin;
|
||||
addOKButton();
|
||||
setOkButtonText("GC");
|
||||
addWorkPanel(createWorkPanel());
|
||||
plugin.getTool().showDialog(this);
|
||||
final DecimalFormat df = new DecimalFormat();
|
||||
timer = new Timer(2000, e -> {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
maxMem.setText(df.format(runtime.maxMemory() / 1000) + "K");
|
||||
totalMem.setText(df.format(runtime.totalMemory() / 1000) + "K");
|
||||
freeMem.setText(df.format(runtime.freeMemory() / 1000) + "K");
|
||||
usedMem.setText(
|
||||
df.format((runtime.totalMemory() - runtime.freeMemory()) / 1000) + "K");
|
||||
});
|
||||
timer.start();
|
||||
}
|
||||
|
||||
boolean isInitialized() {
|
||||
String text = maxMem.getText();
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
if ('0' != c) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cancelCallback() {
|
||||
timer.stop();
|
||||
plugin.clearDialog();
|
||||
super.cancelCallback();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void okCallback() {
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
|
||||
private JComponent createWorkPanel() {
|
||||
JPanel panel = new JPanel(new PairLayout());
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
maxMem = new GDLabel("00000000000", SwingConstants.RIGHT);
|
||||
totalMem = new GDLabel("00000000000", SwingConstants.RIGHT);
|
||||
freeMem = new GDLabel("00000000000", SwingConstants.RIGHT);
|
||||
usedMem = new GDLabel("00000000000", SwingConstants.RIGHT);
|
||||
|
||||
panel.add(new GLabel("Max Memory:"));
|
||||
panel.add(maxMem);
|
||||
panel.add(new GLabel("Total Memory:"));
|
||||
panel.add(totalMem);
|
||||
panel.add(new GLabel("Free Memory:"));
|
||||
panel.add(freeMem);
|
||||
panel.add(new GLabel("Used Memory:"));
|
||||
panel.add(usedMem);
|
||||
|
||||
return panel;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue