001: package tide.profiler;
002:
003: import javax.swing.border.LineBorder;
004: import tide.editor.MainEditorFrame;
005: import snow.utils.gui.Icons;
006: import tide.execute.ProcessItem;
007: import java.io.File;
008: import snow.sortabletable.*;
009: import javax.swing.*;
010: import javax.swing.event.*;
011: import java.awt.*;
012: import java.awt.event.*;
013:
014: /** A panel as output tab, to see the histogram of the used objects in memory.
015: */
016: public final class JMapViewer extends JPanel {
017: final JTable table;
018: SortableTableModel sortableTableModel;
019: JMapReader reader;
020: final ProcessItem pi;
021:
022: public JMapViewer(final JMapReader reader, final ProcessItem pi,
023: final File jmap) {
024: super (new BorderLayout());
025:
026: this .pi = pi;
027: this .reader = reader;
028: this .sortableTableModel = new SortableTableModel(reader);
029: table = new JTable(this .sortableTableModel);
030:
031: add(new JScrollPane(table), BorderLayout.CENTER);
032: sortableTableModel.installGUI(table);
033: table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
034:
035: MultiSearchPanel asp2 = new MultiSearchPanel("Filter: ", null,
036: sortableTableModel);
037: JPanel northPan = new JPanel();
038: northPan.setLayout(new BoxLayout(northPan, BoxLayout.X_AXIS));
039: northPan.add(asp2);
040: add(northPan, BorderLayout.NORTH);
041:
042: JButton delta = new JButton("look again for diffs");
043: delta
044: .setToolTipText("Repopulates the actual object histogram and shows the differences");
045: delta.setMargin(new Insets(0, 4, 0, 4));
046: northPan.add(Box.createHorizontalStrut(5));
047: northPan.add(delta);
048: delta.addActionListener(new ActionListener() {
049: public void actionPerformed(ActionEvent ae) {
050: try {
051: if (pi.isTerminated())
052: throw new Exception("Process " + pi.pid
053: + " is no more running");
054: Process np = Runtime.getRuntime().exec(
055: new String[] { jmap.getAbsolutePath(),
056: "-histo", pi.pid });
057: JMapReader newReader = new JMapReader(np);
058: np.waitFor();
059: reader.addDiffAnalysis(newReader);
060: newReader.terminate();
061: EventQueue.invokeLater(new Runnable() {
062: public void run() {
063: sortableTableModel.setAllColumnsVisible();
064: sortableTableModel.sort(reader
065: .getColumnCount(), false);
066: sortableTableModel
067: .setPreferredColumnSizesFromModel();
068: }
069: });
070:
071: } catch (Exception e) {
072: JOptionPane.showMessageDialog(JMapViewer.this , ""
073: + e.getMessage(), "Cannot observe process",
074: JOptionPane.ERROR_MESSAGE);
075: e.printStackTrace();
076: }
077: }
078: });
079:
080: // TODO: same functions as in the ProcessesManager
081: JButton deep = new JButton("deep view with jhat");
082: deep
083: .setToolTipText("<html><body>Creates a dump to a file with jmap and lauch jhat to browse it.<br>"
084: + "Subsequent calls shows differences.");
085: deep.setMargin(new Insets(0, 4, 0, 4));
086: northPan.add(Box.createHorizontalStrut(5));
087: northPan.add(deep);
088: deep.addActionListener(new ActionListener() {
089: public void actionPerformed(ActionEvent ae) {
090: File previous = pi.getLastValidDump();
091: try {
092: if (pi.isTerminated())
093: throw new Exception("Process " + pi.pid
094: + " is no more running");
095: File newDump = ProfilerUtils.dumpToFileWithJMap(pi,
096: previous);
097: if (newDump == null)
098: return;
099: if (pi.isTerminated())
100: throw new Exception("Process " + pi.pid
101: + " is no more running");
102: ProfilerUtils.analyseProfilerResultWithJHatTool(
103: newDump, previous);
104: } catch (Exception e) {
105: JOptionPane.showMessageDialog(JMapViewer.this , ""
106: + e.getMessage(), "Cannot analyse process",
107: JOptionPane.ERROR_MESSAGE);
108: e.printStackTrace();
109: }
110: }
111: });
112:
113: JButton close = new JButton(Icons.sharedCross); //"close view");
114: close.setMargin(new Insets(0, 0, 0, 0));
115: northPan.add(Box.createHorizontalStrut(5));
116: northPan.add(close);
117: close.addActionListener(new ActionListener() {
118: public void actionPerformed(ActionEvent ae) {
119: if (getParent() instanceof JTabbedPane) {
120: JTabbedPane tp = (JTabbedPane) getParent();
121: tp.remove(JMapViewer.this );
122: }
123:
124: sortableTableModel.removeOldListeners();
125: reader.terminate();
126: }
127: });
128: }
129:
130: public void installAsTab() {
131: final JTabbedPane tp = MainEditorFrame.instance.outputPanels;
132: String title = "JMap of " + pi.pid;
133: tp.addTab(title, this );
134:
135: JPanel rp = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
136: rp.setOpaque(false);
137: rp.add(new JLabel(title));
138: JButton cb = new JButton(new Icons.CrossIcon(8, 8, true));
139: rp.add(cb);
140: cb.setFocusPainted(false);
141: cb.setMargin(new Insets(0, 0, 0, 0));
142: cb.setBorder(new LineBorder(Color.lightGray, 1, true)); //null);
143: cb.addActionListener(new ActionListener() {
144: public void actionPerformed(ActionEvent ae) {
145: tp.remove(JMapViewer.this );
146: }
147: });
148: tp.setTabComponentAt(tp.getTabCount() - 1, rp);
149: }
150:
151: }
|