001: package tide.profiler;
002:
003: import tide.project.*;
004: import tide.editor.*;
005: import javax.swing.*;
006: import java.awt.*;
007: import java.awt.event.*;
008: import javax.swing.border.*;
009: import java.util.*;
010: import java.io.*;
011: import snow.utils.*;
012: import snow.utils.storage.*;
013: import snow.utils.gui.*;
014:
015: /** Configures the internal HPROF profiler.
016: */
017: public final class ProfilerSettingsDialog extends JDialog {
018: private JTextField stacktraceDepth = new JTextField(6);
019: private JTextField samplingInterval = new JTextField(8);
020: private JTextField cutoff = new JTextField(8);
021: private JButton viewOpts = new JButton("View HPROF help", Icons
022: .createHelpIcon(16, true));
023: private final ProjectSettings settings;
024:
025: public ProfilerSettingsDialog(final JFrame parent,
026: final ProjectSettings settings) {
027: super (parent, "JDK Profiler Settings", true);
028: this .settings = settings;
029:
030: JComponent ta = GUIUtils
031: .createReadOnlyDescriptionArea("Already since JDK1.2.2, java, javac and other JDK tools have an integrated profiler."
032: + "\nCPU and memory usage can be monitored. One can find out which methods takes "
033: + "\nmost CPU time or waste at most memory resoures."
034: + "\r\nCAUTION: HProf is not an official product or formal part of the JDK."
035: + "\n\nSampling modes leads to inacurate results but doesn't slow the running application."
036: + "\nThe standard profilers can be started from the sources tree context menu."
037: + "\nThe profiler outputs are in the folder \".tide/profile\" of the project folder."
038: + "\nAt application end, the new profiler results are automatically added in an output tab,"
039: + "\nexcept for heap dumps. Old profiler results can be reopened from the Project menu."
040: + "\n\njmap and jHAT (standard since JDK6+) can be used from the processes tab to create live dumps"
041: + "\nand differential heap dumps and browse them at http://localhost:7000"
042: + "\n\nOf course, you can start the profiler manually: just pass the command to the Runtime JVM"
043: + "\narguments, for example \"-agentlib:hprof=heap=sites\"."
044: + "\nYou can also profile the other jdk tools (as javac or javadoc!), pass them the command with a"
045: + "\nprefixed -J before the agentlib command."
046: + "\n\nAn excellent usage help is available at http://java.sun.com/javase/6/webnotes/trouble/"
047:
048: );
049:
050: //ta.setEditable(false);
051: //ta.setBackground(getBackground());
052: //ta.setBorder(BorderFactory.createEmptyBorder(5,10,10,5));
053: add(ta, BorderLayout.NORTH);
054:
055: JPanel inputPanel = new JPanel();
056: add(inputPanel, BorderLayout.CENTER);
057: GridLayout3 gl3 = new GridLayout3(2, inputPanel);
058: gl3.addSeparator();
059:
060: gl3.add(viewOpts);
061: viewOpts.setMargin(new Insets(0, 2, 0, 2));
062: gl3.add(""); //displays the command line help of HPROF");
063: viewOpts.addActionListener(new ActionListener() {
064: public void actionPerformed(ActionEvent ae) {
065: displayOptions();
066: }
067: });
068: //viewOpts
069:
070: gl3.add("Stacktrace depths");
071: gl3.add(stacktraceDepth);
072: try {
073: stacktraceDepth.setText(settings.getProperty(
074: "Profiler_stacktraceDepth", "5"));
075: } catch (Exception e) {
076: }
077:
078: gl3.add("Sampling interval [ms]");
079: gl3.add(samplingInterval);
080: try {
081: samplingInterval.setText(settings.getProperty(
082: "Profiler_samplingInterval", "30"));
083: } catch (Exception e) {
084: }
085:
086: gl3.add("Cutoff [ms]");
087: gl3.add(cutoff);
088: try {
089: cutoff.setText(settings.getProperty("Profiler_cutoff",
090: "0.0001"));
091: } catch (Exception e) {
092: }
093:
094: //gl3.add("Hat tool [optional tool to analyse dumps]");
095: //gl3.add(hatLoc);
096: // hatLoc.setComponentWidth(200);
097: // hatLoc.setPath( settings.getProperty("Profiler_hat_loc", "c:/java/hat/hat.jar"));
098:
099: CloseControlPanel ccp = new CloseControlPanel(this , true, true,
100: "Ok");
101: add(ccp, BorderLayout.SOUTH);
102:
103: pack();
104: this .setLocationRelativeTo(parent);
105: this .setVisible(true); // MODAL => waits
106:
107: if (ccp.getWasCancelled())
108: return;
109:
110: // save settings
111: settings.setProperty("Profiler_stacktraceDepth",
112: stacktraceDepth.getText());
113: settings.setProperty("Profiler_samplingInterval",
114: samplingInterval.getText());
115: settings.setProperty("Profiler_cutoff", cutoff.getText());
116: // settings.setProperty("Profiler_hat_loc", hatLoc.getPath().getAbsolutePath());
117: }
118:
119: private void displayOptions() {
120: ProjectSettings actualProject = settings; //MainEditorFrame.instance.getActualProject();
121: StringBuilder comp = new StringBuilder();
122: try {
123: Vector<String> args = new Vector<String>();
124: args.add(actualProject.getJava_TOOL().getAbsolutePath());
125: args.add("-agentlib:hprof=help");
126: comp.append(ProcessUtils.readWholeProcessStack(args));
127: } catch (Exception e) {
128: comp.append("\r\nError: " + e.getMessage());
129: e.printStackTrace();
130: }
131:
132: JDialog optionsDialog = new JDialog(this ,
133: "HPROF Help (java -agentlib:hprof=help)", false);
134: JTextPane tp = new JTextPane();
135: tp.setFont(MainEditorFrame.fixedWidthFontForProcesses);
136: tp.setText(comp.toString().trim());
137: optionsDialog.add(new JScrollPane(tp), BorderLayout.CENTER);
138: CloseControlPanel ccp = new CloseControlPanel(optionsDialog,
139: false, true, "Close");
140: optionsDialog.add(ccp, BorderLayout.SOUTH);
141: tp.setEditable(false);
142: tp.setCaretPosition(0);
143: optionsDialog.setSize(680, 700);
144: optionsDialog.setLocationRelativeTo(viewOpts);
145: optionsDialog.setVisible(true);
146: }
147:
148: /*test
149: public static void main(String[] aa)
150: {
151: JFrame f = new JFrame("Test");
152: f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
153: ProjectSettings props = new ProjectSettings();
154: props.setJava_Home(new File("c:/java/jdk1.6.0_05/"));
155: new ProfilerSettingsDialog(f, props);
156: System.exit(0);
157: }*/
158: }
|