This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 206859
Collapse All | Expand All

(-)a/core.ui/nbproject/project.xml (-5 / +8 lines)
Lines 77-82 Link Here
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
80
                    <code-name-base>org.netbeans.modules.sampler</code-name-base>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
83
                    <run-dependency>
84
                        <specification-version>1.0</specification-version>
85
                    </run-dependency>
86
                </dependency>
87
                <dependency>
80
                    <code-name-base>org.netbeans.spi.quicksearch</code-name-base>
88
                    <code-name-base>org.netbeans.spi.quicksearch</code-name-base>
81
                    <build-prerequisite/>
89
                    <build-prerequisite/>
82
                    <compile-dependency/>
90
                    <compile-dependency/>
Lines 180-190 Link Here
180
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
188
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
181
                        <compile-dependency/>
189
                        <compile-dependency/>
182
                    </test-dependency>
190
                    </test-dependency>
183
                    <test-dependency>
184
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
185
                        <recursive/>
186
                        <compile-dependency/>
187
                    </test-dependency>
188
                </test-type>
191
                </test-type>
189
            </test-dependencies>
192
            </test-dependencies>
190
            <public-packages/>
193
            <public-packages/>
(-)a/core.ui/src/org/netbeans/core/ui/sampler/Bundle.properties (-2 lines)
Lines 46-50 Link Here
46
SelfSamplerAction_ActionNameStop=Stop Application Profiling and Take a Snapshot
46
SelfSamplerAction_ActionNameStop=Stop Application Profiling and Take a Snapshot
47
SelfSamplerAction_ActionDescription=Will take a snapshot based on the thread dump
47
SelfSamplerAction_ActionDescription=Will take a snapshot based on the thread dump
48
SelfSamplerAction_NotSupported=Self Sampler is not available.
48
SelfSamplerAction_NotSupported=Self Sampler is not available.
49
SelfSamplerAction_SavedFile=Snapshot was saved to {0}
50
Save_Progress=Saving snapshot
(-)a/core.ui/src/org/netbeans/core/ui/sampler/SelfSamplerAction.java (-173 / +7 lines)
Lines 42-79 Link Here
42
package org.netbeans.core.ui.sampler;
42
package org.netbeans.core.ui.sampler;
43
43
44
import java.awt.AWTEvent;
44
import java.awt.AWTEvent;
45
import java.awt.EventQueue;
46
import java.awt.Toolkit;
45
import java.awt.Toolkit;
47
import java.awt.event.AWTEventListener;
46
import java.awt.event.AWTEventListener;
48
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionEvent;
49
import java.awt.event.KeyEvent;
48
import java.awt.event.KeyEvent;
50
import java.io.File;
51
import java.io.FileOutputStream;
52
import java.io.IOException;
53
import java.lang.management.ManagementFactory;
54
import java.lang.management.RuntimeMXBean;
55
import java.lang.management.ThreadMXBean;
56
import java.text.MessageFormat;
57
import java.util.List;
58
import java.util.concurrent.atomic.AtomicReference;
49
import java.util.concurrent.atomic.AtomicReference;
59
import java.util.logging.Level;
60
import java.util.logging.Logger;
61
import javax.swing.AbstractAction;
50
import javax.swing.AbstractAction;
62
import javax.swing.Action;
51
import javax.swing.Action;
63
import javax.swing.SwingWorker;
52
import javax.swing.SwingWorker;
64
import org.netbeans.api.progress.ProgressHandle;
53
import org.netbeans.modules.sampler.Sampler;
65
import org.netbeans.api.progress.ProgressHandleFactory;
66
import org.openide.DialogDisplayer;
54
import org.openide.DialogDisplayer;
67
import org.openide.NotifyDescriptor;
55
import org.openide.NotifyDescriptor;
68
import org.openide.awt.ActionID;
56
import org.openide.awt.ActionID;
69
import org.openide.awt.ActionReference;
57
import org.openide.awt.ActionReference;
70
import org.openide.awt.ActionReferences;
58
import org.openide.awt.ActionReferences;
71
import org.openide.awt.ActionRegistration;
59
import org.openide.awt.ActionRegistration;
72
import org.openide.cookies.OpenCookie;
73
import org.openide.filesystems.FileObject;
74
import org.openide.filesystems.FileUtil;
75
import org.openide.loaders.DataObject;
76
import org.openide.util.Exceptions;
77
import org.openide.util.NbBundle;
60
import org.openide.util.NbBundle;
78
61
79
/**
62
/**
Lines 93-112 Link Here
93
    private static final String ACTION_NAME_STOP = NbBundle.getMessage(SelfSamplerAction.class, "SelfSamplerAction_ActionNameStop");
76
    private static final String ACTION_NAME_STOP = NbBundle.getMessage(SelfSamplerAction.class, "SelfSamplerAction_ActionNameStop");
94
//    private static final String ACTION_DESCR = NbBundle.getMessage(SelfSamplerAction.class, "SelfSamplerAction_ActionDescription");
77
//    private static final String ACTION_DESCR = NbBundle.getMessage(SelfSamplerAction.class, "SelfSamplerAction_ActionDescription");
95
    private static final String NOT_SUPPORTED = NbBundle.getMessage(SelfSamplerAction.class, "SelfSamplerAction_NotSupported");
78
    private static final String NOT_SUPPORTED = NbBundle.getMessage(SelfSamplerAction.class, "SelfSamplerAction_NotSupported");
96
    private static final String SAVE_MSG = NbBundle.getMessage(SelfSamplerAction.class, "SelfSamplerAction_SavedFile");
97
    private static final String DEBUG_ARG = "-Xdebug"; // NOI18N
98
    private static final Logger LOGGER = Logger.getLogger(SelfSamplerAction.class.getName());
99
    private final AtomicReference<Sampler> RUNNING = new AtomicReference<Sampler>();
79
    private final AtomicReference<Sampler> RUNNING = new AtomicReference<Sampler>();
100
    private static Boolean debugMode;
101
    private static String lastReason;
102
    private static Class defaultDataObject;
103
    static {
104
        try {
105
            defaultDataObject = Class.forName("org.openide.loaders.DefaultDataObject"); // NOI18N
106
        } catch (ClassNotFoundException ex) {
107
            Exceptions.printStackTrace(ex);
108
        }
109
    }
110
80
111
    //~ Constructors -------------------------------------------------------------------------------------------------------------
81
    //~ Constructors -------------------------------------------------------------------------------------------------------------
112
    public SelfSamplerAction() {
82
    public SelfSamplerAction() {
Lines 125-137 Link Here
125
     */
95
     */
126
    @Override
96
    @Override
127
    public void actionPerformed(final ActionEvent e) {
97
    public void actionPerformed(final ActionEvent e) {
128
        if (SamplesOutputStream.isSupported()) {
98
        Sampler c = Sampler.getGenericSampler("Self Sampler");  // NOI18N
129
            Sampler c;
99
        if (c != null) {
130
            if (RUNNING.compareAndSet(null, c = new InternalSampler("Self Sampler"))) { // NOI18N
100
            if (RUNNING.compareAndSet(null, c)) {
131
                putValue(Action.NAME, ACTION_NAME_STOP);
101
                putValue(Action.NAME, ACTION_NAME_STOP);
132
                putValue(Action.SHORT_DESCRIPTION, ACTION_NAME_STOP);
102
                putValue(Action.SHORT_DESCRIPTION, ACTION_NAME_STOP);
133
                putValue ("iconBase", "org/netbeans/core/ui/sampler/selfSamplerRunning.png"); // NOI18N
103
                putValue ("iconBase", "org/netbeans/core/ui/sampler/selfSamplerRunning.png"); // NOI18N
134
                c.run();
104
                c.start();
135
            } else if ((c = RUNNING.getAndSet(null)) != null) {
105
            } else if ((c = RUNNING.getAndSet(null)) != null) {
136
                final Sampler controller = c;
106
                final Sampler controller = c;
137
107
Lines 140-146 Link Here
140
110
141
                    @Override
111
                    @Override
142
                    protected Object doInBackground() throws Exception {
112
                    protected Object doInBackground() throws Exception {
143
                        controller.actionPerformed(new ActionEvent(this, 0, "show")); // NOI18N
113
                        controller.stop();
144
                        return null;
114
                        return null;
145
                    }
115
                    }
146
116
Lines 156-161 Link Here
156
            }
126
            }
157
        } else {
127
        } else {
158
            NotifyDescriptor d = new NotifyDescriptor.Message(NOT_SUPPORTED, NotifyDescriptor.INFORMATION_MESSAGE);
128
            NotifyDescriptor d = new NotifyDescriptor.Message(NOT_SUPPORTED, NotifyDescriptor.INFORMATION_MESSAGE);
129
            DialogDisplayer.getDefault().notify(d);
159
        }
130
        }
160
    }
131
    }
161
132
Lines 168-311 Link Here
168
        }
139
        }
169
    }
140
    }
170
141
171
    @Override
172
    public Object getValue(String key) {
173
        Object o = super.getValue(key);
174
        if (o == null && key.startsWith("logger-") && SamplesOutputStream.isSupported() && isRunMode()) { // NOI18N
175
            return new InternalSampler(key);
176
        }
177
        return o;
178
    }
179
180
    final boolean isProfileMe(Sampler c) {
142
    final boolean isProfileMe(Sampler c) {
181
        return c == RUNNING.get();
143
        return c == RUNNING.get();
182
    }
144
    }
183
    
184
    private static synchronized boolean isDebugged() {
185
        if (debugMode == null) {
186
            debugMode = Boolean.FALSE;
187
188
            // check if we are debugged
189
            RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
190
            List<String> args = runtime.getInputArguments();
191
            if (args.contains(DEBUG_ARG)) {
192
                debugMode = Boolean.TRUE;
193
            }
194
        }
195
        return debugMode.booleanValue();
196
    }
197
198
    private static boolean isRunMode() {
199
        boolean runMode = true;
200
        String reason = null;
201
202
        if (isDebugged()) {
203
            reason = "running in debug mode";   // NOI18N
204
            runMode = false;
205
        }
206
        if (runMode) {
207
            // check if netbeans is profiled
208
            try {
209
                Class.forName("org.netbeans.lib.profiler.server.ProfilerServer", false, ClassLoader.getSystemClassLoader()); // NO18N
210
                reason = "running under profiler";   // NOI18N
211
                runMode = false;
212
            } catch (ClassNotFoundException ex) {
213
            }
214
        }
215
        if (!runMode && !reason.equals(lastReason)) {
216
            LOGGER.log(Level.INFO, "Slowness detector disabled - {0}", reason); // NOI18N
217
        }
218
        lastReason = reason;
219
        return runMode;
220
    }
221
    
222
    private static final class InternalSampler extends Sampler {
223
        private ProgressHandle progress;
224
        
225
        InternalSampler(String thread) {
226
            super(thread);
227
        }
228
229
        @Override
230
        protected void printStackTrace(Throwable ex) {
231
            Exceptions.printStackTrace(ex);
232
        }
233
234
        @Override
235
        protected void saveSnapshot(byte[] arr) throws IOException {
236
            // save snapshot
237
            File outFile = File.createTempFile("selfsampler", SamplesOutputStream.FILE_EXT); // NOI18N
238
            outFile = FileUtil.normalizeFile(outFile);
239
            writeToFile(outFile, arr);
240
            
241
            File gestures = new File(new File(new File(
242
                new File(System.getProperty("netbeans.user")), // NOI18N
243
                "var"), "log"), "uigestures"); // NOI18N
244
            
245
            SelfSampleVFS fs;
246
            if (gestures.exists()) {
247
                fs = new SelfSampleVFS(
248
                    new String[] { "selfsampler.npss", "selfsampler.log" }, 
249
                    new File[] { outFile, gestures }
250
                );
251
            } else {
252
                fs = new SelfSampleVFS(
253
                    new String[] { "selfsampler.npss" }, 
254
                    new File[] { outFile }
255
                );
256
            }
257
            
258
            // open snapshot
259
            FileObject fo = fs.findResource("selfsampler.npss");
260
            DataObject dobj = DataObject.find(fo);
261
            // ugly test for DefaultDataObject
262
            if (defaultDataObject.isAssignableFrom(dobj.getClass())) {
263
                String msg = MessageFormat.format(SelfSamplerAction.SAVE_MSG, outFile.getAbsolutePath());
264
                DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg));
265
            } else {
266
                dobj.getCookie(OpenCookie.class).open();
267
            }
268
        }
269
270
        private void writeToFile(File file, byte[] arr) {
271
            try {
272
                FileOutputStream fstream = new FileOutputStream(file);
273
                fstream.write(arr);
274
                fstream.close();
275
            } catch (IOException ex) {
276
                Exceptions.printStackTrace(ex);
277
            }
278
        }
279
280
        @Override
281
        protected ThreadMXBean getThreadMXBean() {
282
            return ManagementFactory.getThreadMXBean();
283
        }
284
        
285
        protected void openProgress(final int steps) {
286
            if (EventQueue.isDispatchThread()) {
287
                // log warnining
288
                return;
289
            }
290
            progress = ProgressHandleFactory.createHandle(NbBundle.getMessage(SelfSamplerAction.class, "Save_Progress"));
291
            progress.start(steps);
292
        }
293
        
294
        protected void closeProgress() {
295
            if (EventQueue.isDispatchThread()) {
296
                return;
297
            }
298
            progress.finish();
299
            progress = null;
300
        }
301
        
302
        protected void progress(int i) {
303
            if (EventQueue.isDispatchThread()) {
304
                return;
305
            }
306
            if (progress != null) {
307
                progress.progress(i);
308
            }
309
        }
310
    }
311
}
145
}
(-)a/editor.completion/nbproject/project.xml (+8 lines)
Lines 104-109 Link Here
104
                    </run-dependency>
104
                    </run-dependency>
105
                </dependency>
105
                </dependency>
106
                <dependency>
106
                <dependency>
107
                    <code-name-base>org.netbeans.modules.sampler</code-name-base>
108
                    <build-prerequisite/>
109
                    <compile-dependency/>
110
                    <run-dependency>
111
                        <specification-version>1.0</specification-version>
112
                    </run-dependency>
113
                </dependency>
114
                <dependency>
107
                    <code-name-base>org.openide.awt</code-name-base>
115
                    <code-name-base>org.openide.awt</code-name-base>
108
                    <build-prerequisite/>
116
                    <build-prerequisite/>
109
                    <compile-dependency/>
117
                    <compile-dependency/>
(-)a/editor.completion/src/org/netbeans/modules/editor/completion/CompletionImplProfile.java (-24 / +10 lines)
Lines 43-57 Link Here
43
 */
43
 */
44
package org.netbeans.modules.editor.completion;
44
package org.netbeans.modules.editor.completion;
45
45
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
48
import java.io.ByteArrayOutputStream;
46
import java.io.ByteArrayOutputStream;
49
import java.io.DataOutputStream;
47
import java.io.DataOutputStream;
50
import java.util.logging.Level;
48
import java.util.logging.Level;
51
import java.util.logging.Logger;
49
import java.util.logging.Logger;
52
import javax.swing.Action;
50
import org.netbeans.modules.sampler.Sampler;
53
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileUtil;
55
import org.openide.util.Exceptions;
51
import org.openide.util.Exceptions;
56
import org.openide.util.RequestProcessor;
52
import org.openide.util.RequestProcessor;
57
53
Lines 59-85 Link Here
59
    private static final Logger LOG = Logger.getLogger(CompletionImplProfile.class.getName());
55
    private static final Logger LOG = Logger.getLogger(CompletionImplProfile.class.getName());
60
    static final RequestProcessor RP = new RequestProcessor("Completion Slowness"); // NOI18N
56
    static final RequestProcessor RP = new RequestProcessor("Completion Slowness"); // NOI18N
61
57
62
    private final Object profiler;
58
    private final Sampler profiler;
63
    private boolean profiling;
59
    private boolean profiling;
64
    private final long time;
60
    private final long time;
65
61
66
    CompletionImplProfile(long when) {
62
    CompletionImplProfile(long when) {
67
        time = when;
63
        time = when;
68
64
69
        Object p = null;
65
        this.profiler = Sampler.getSampler("logger-completion");  // NOI18N
70
        FileObject fo = FileUtil.getConfigFile("Actions/Profile/org-netbeans-modules-profiler-actions-SelfSamplerAction.instance"); // NOI18N
71
        if (fo != null) {
72
            Action a = (Action) fo.getAttribute("delegate"); // NOI18N
73
            if (a != null) {
74
                p = a.getValue("logger-completion"); // NOI18N
75
            }
76
        }
77
        this.profiler = p;
78
        this.profiling = true;
66
        this.profiling = true;
79
        
67
        
80
        if (profiler instanceof Runnable) {
68
        if (profiler != null) {
81
            Runnable r = (Runnable) profiler;
69
            profiler.start();
82
            r.run();
83
            LOG.log(Level.FINE, "Profiling started {0} at {1}", new Object[] { profiler, time });
70
            LOG.log(Level.FINE, "Profiling started {0} at {1}", new Object[] { profiler, time });
84
        }
71
        }
85
    }
72
    }
Lines 106-117 Link Here
106
    private void stopImpl(long now) throws Exception {
93
    private void stopImpl(long now) throws Exception {
107
        long delta = now - time;
94
        long delta = now - time;
108
        LOG.log(Level.FINE, "Profiling stopped at {0}", now);
95
        LOG.log(Level.FINE, "Profiling stopped at {0}", now);
109
        ActionListener ss = (ActionListener) profiler;
110
        int report = Integer.getInteger("org.netbeans.modules.editor.completion.slowness.report", 2000); // NOI18N
96
        int report = Integer.getInteger("org.netbeans.modules.editor.completion.slowness.report", 2000); // NOI18N
111
        if (delta < report) {
97
        if (delta < report) {
112
            LOG.log(Level.FINE, "Cancel profiling of {0}. Profiling {1}. Time {2} ms.", new Object[] { ss, profiling, delta });
98
            LOG.log(Level.FINE, "Cancel profiling of {0}. Profiling {1}. Time {2} ms.", new Object[] { profiler, profiling, delta });
113
            if (ss != null) {
99
            if (profiler != null) {
114
                ss.actionPerformed(new ActionEvent(this, 0, "cancel"));
100
                profiler.cancel();
115
            }
101
            }
116
            return;
102
            return;
117
        }
103
        }
Lines 119-126 Link Here
119
            LOG.log(Level.FINE, "Obtaining snapshot for {0} ms.", delta);
105
            LOG.log(Level.FINE, "Obtaining snapshot for {0} ms.", delta);
120
            ByteArrayOutputStream out = new ByteArrayOutputStream();
106
            ByteArrayOutputStream out = new ByteArrayOutputStream();
121
            DataOutputStream dos = new DataOutputStream(out);
107
            DataOutputStream dos = new DataOutputStream(out);
122
            if (ss != null) {
108
            if (profiler != null) {
123
                ss.actionPerformed(new ActionEvent(dos, 0, "write")); // NOI18N
109
                profiler.stopAndWriteTo(dos);
124
            }
110
            }
125
            dos.close();
111
            dos.close();
126
            if (dos.size() > 0) {
112
            if (dos.size() > 0) {
(-)a/ide.kit/nbproject/project.xml (-4 / +5 lines)
Lines 230-239 Link Here
230
                        <compile-dependency/>
230
                        <compile-dependency/>
231
                    </test-dependency>
231
                    </test-dependency>
232
                    <test-dependency>
232
                    <test-dependency>
233
                        <code-name-base>org.netbeans.core.ui</code-name-base>
234
                        <compile-dependency/>
235
                    </test-dependency>
236
                    <test-dependency>
237
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
233
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
238
                        <compile-dependency/>
234
                        <compile-dependency/>
239
                    </test-dependency>
235
                    </test-dependency>
Lines 264-269 Link Here
264
                        <compile-dependency/>
260
                        <compile-dependency/>
265
                    </test-dependency>
261
                    </test-dependency>
266
                    <test-dependency>
262
                    <test-dependency>
263
                        <code-name-base>org.netbeans.modules.sampler</code-name-base>
264
                        <compile-dependency/>
265
                        <test/>
266
                    </test-dependency>
267
                    <test-dependency>
267
                        <code-name-base>org.openide.modules</code-name-base>
268
                        <code-name-base>org.openide.modules</code-name-base>
268
                        <compile-dependency/>
269
                        <compile-dependency/>
269
                    </test-dependency>
270
                    </test-dependency>
(-)a/ide.kit/test/qa-functional/src/org/netbeans/test/ide/BlacklistedClassesHandlerSingleton.java (-3 / +3 lines)
Lines 77-83 Link Here
77
import java.util.logging.Level;
77
import java.util.logging.Level;
78
import java.util.logging.LogRecord;
78
import java.util.logging.LogRecord;
79
import java.util.logging.Logger;
79
import java.util.logging.Logger;
80
import org.netbeans.core.ui.sampler.SamplesOutputStream;
80
import org.netbeans.modules.sampler.CustomSamplesStream;
81
import org.openide.util.Exceptions;
81
import org.openide.util.Exceptions;
82
82
83
/**
83
/**
Lines 114-120 Link Here
114
    private String newWhitelistFileName;
114
    private String newWhitelistFileName;
115
    private String previousWhitelistFileName = null;
115
    private String previousWhitelistFileName = null;
116
    private File whitelistStorageDir = null;
116
    private File whitelistStorageDir = null;
117
    private SamplesOutputStream samples;
117
    private CustomSamplesStream samples;
118
    private ByteArrayOutputStream stream;
118
    private ByteArrayOutputStream stream;
119
    private ThreadMXBean threadBean;
119
    private ThreadMXBean threadBean;
120
    private long start;
120
    private long start;
Lines 176-182 Link Here
176
        start = System.currentTimeMillis();
176
        start = System.currentTimeMillis();
177
        stream = new ByteArrayOutputStream();
177
        stream = new ByteArrayOutputStream();
178
        try {
178
        try {
179
            samples = new SamplesOutputStream(stream, null, 5000);
179
            samples = new CustomSamplesStream(stream, 5000);
180
        } catch (IOException ex) {
180
        } catch (IOException ex) {
181
            throw new RuntimeException(ex);
181
            throw new RuntimeException(ex);
182
        }
182
        }
(-)a/jumpto/nbproject/project.xml (+8 lines)
Lines 104-109 Link Here
104
                    </run-dependency>
104
                    </run-dependency>
105
                </dependency>
105
                </dependency>
106
                <dependency>
106
                <dependency>
107
                    <code-name-base>org.netbeans.modules.sampler</code-name-base>
108
                    <build-prerequisite/>
109
                    <compile-dependency/>
110
                    <run-dependency>
111
                        <specification-version>1.0</specification-version>
112
                    </run-dependency>
113
                </dependency>
114
                <dependency>
107
                    <code-name-base>org.netbeans.spi.quicksearch</code-name-base>
115
                    <code-name-base>org.netbeans.spi.quicksearch</code-name-base>
108
                    <build-prerequisite/>
116
                    <build-prerequisite/>
109
                    <compile-dependency/>
117
                    <compile-dependency/>
(-)a/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java (-18 / +7 lines)
Lines 71-77 Link Here
71
import java.util.logging.Logger;
71
import java.util.logging.Logger;
72
import java.util.regex.Pattern;
72
import java.util.regex.Pattern;
73
import javax.swing.AbstractAction;
73
import javax.swing.AbstractAction;
74
import javax.swing.Action;
75
import javax.swing.DefaultListModel;
74
import javax.swing.DefaultListModel;
76
import javax.swing.JButton;
75
import javax.swing.JButton;
77
import javax.swing.ListCellRenderer;
76
import javax.swing.ListCellRenderer;
Lines 87-92 Link Here
87
import org.netbeans.api.project.ui.OpenProjects;
86
import org.netbeans.api.project.ui.OpenProjects;
88
import org.netbeans.modules.jumpto.EntitiesListCellRenderer;
87
import org.netbeans.modules.jumpto.EntitiesListCellRenderer;
89
import org.netbeans.modules.jumpto.file.LazyListModel;
88
import org.netbeans.modules.jumpto.file.LazyListModel;
89
import org.netbeans.modules.sampler.Sampler;
90
import org.openide.DialogDescriptor;
90
import org.openide.DialogDescriptor;
91
import org.openide.DialogDisplayer;
91
import org.openide.DialogDisplayer;
92
import org.openide.ErrorManager;
92
import org.openide.ErrorManager;
Lines 774-788 Link Here
774
            return null;
774
            return null;
775
        }
775
        }
776
776
777
        FileObject fo = FileUtil.getConfigFile("Actions/Profile/org-netbeans-modules-profiler-actions-SelfSamplerAction.instance");     //NOI18N
777
        Sampler profiler = Sampler.getSampler("logger-jumpto"); //NOI18N
778
        if (fo == null) {
779
            return null;
780
        }
781
        Action a = (Action)fo.getAttribute("delegate"); // NOI18N
782
        if (a == null) {
783
            return null;
784
        }
785
        Object profiler = a.getValue("logger-jumpto"); //NOI18N
786
        if (profiler == null) {
778
        if (profiler == null) {
787
            return null;
779
            return null;
788
        }
780
        }
Lines 791-800 Link Here
791
783
792
    private class Profile implements Runnable {
784
    private class Profile implements Runnable {
793
        private final long time;
785
        private final long time;
794
        private volatile  Object profiler;
786
        private volatile  Sampler profiler;
795
        private volatile boolean profiling;
787
        private volatile boolean profiling;
796
788
797
        public Profile(Object profiler) {
789
        public Profile(Sampler profiler) {
798
            time = System.currentTimeMillis();
790
            time = System.currentTimeMillis();
799
            this.profiler = profiler;
791
            this.profiler = profiler;
800
        }
792
        }
Lines 807-822 Link Here
807
        @Override
799
        @Override
808
        public synchronized void run() {
800
        public synchronized void run() {
809
            profiling = true;
801
            profiling = true;
810
            if (profiler instanceof Runnable) {
802
            profiler.start();
811
                Runnable r = (Runnable)profiler;
812
                r.run();
813
            }
814
        }
803
        }
815
804
816
        private synchronized void stop() throws Exception {
805
        private synchronized void stop() throws Exception {
817
            long delta = System.currentTimeMillis() - time;
806
            long delta = System.currentTimeMillis() - time;
818
807
819
            ActionListener ss = (ActionListener)profiler;
808
            Sampler ss = profiler;
820
            profiler = null;
809
            profiler = null;
821
            if (!profiling) {
810
            if (!profiling) {
822
                return;
811
                return;
Lines 824-830 Link Here
824
            try {
813
            try {
825
                ByteArrayOutputStream out = new ByteArrayOutputStream();
814
                ByteArrayOutputStream out = new ByteArrayOutputStream();
826
                DataOutputStream dos = new DataOutputStream(out);
815
                DataOutputStream dos = new DataOutputStream(out);
827
                ss.actionPerformed(new ActionEvent(dos, 0, "write")); // NOI18N
816
                ss.stopAndWriteTo(dos);
828
                dos.close();
817
                dos.close();
829
                if (dos.size() > 0) {
818
                if (dos.size() > 0) {
830
                    Object[] params = new Object[]{out.toByteArray(), delta, "GoToType" };      //NOI18N
819
                    Object[] params = new Object[]{out.toByteArray(), delta, "GoToType" };      //NOI18N
(-)a/nbbuild/cluster.properties (+1 lines)
Lines 209-214 Link Here
209
        print,\
209
        print,\
210
        progress.ui,\
210
        progress.ui,\
211
        queries,\
211
        queries,\
212
        sampler,\
212
        sendopts,\
213
        sendopts,\
213
        settings,\
214
        settings,\
214
        spi.actions,\
215
        spi.actions,\
(-)a/o.n.core/nbproject/project.xml (+8 lines)
Lines 76-81 Link Here
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
79
                    <code-name-base>org.netbeans.modules.sampler</code-name-base>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
82
                    <run-dependency>
83
                        <specification-version>1.0</specification-version>
84
                    </run-dependency>
85
                </dependency>
86
                <dependency>
79
                    <code-name-base>org.netbeans.swing.plaf</code-name-base>
87
                    <code-name-base>org.netbeans.swing.plaf</code-name-base>
80
                    <build-prerequisite/>
88
                    <build-prerequisite/>
81
                    <compile-dependency/>
89
                    <compile-dependency/>
(-)a/o.n.core/src/org/netbeans/core/TimableEventQueue.java (-23 / +11 lines)
Lines 50-67 Link Here
50
import java.awt.KeyboardFocusManager;
50
import java.awt.KeyboardFocusManager;
51
import java.awt.Toolkit;
51
import java.awt.Toolkit;
52
import java.awt.Window;
52
import java.awt.Window;
53
import java.awt.event.ActionEvent;
54
import java.awt.event.ActionListener;
55
import java.io.ByteArrayOutputStream;
53
import java.io.ByteArrayOutputStream;
56
import java.io.DataOutputStream;
54
import java.io.DataOutputStream;
57
import java.util.logging.Level;
55
import java.util.logging.Level;
58
import java.util.logging.Logger;
56
import java.util.logging.Logger;
59
import javax.swing.Action;
60
import javax.swing.JFrame;
57
import javax.swing.JFrame;
61
import javax.swing.JRootPane;
58
import javax.swing.JRootPane;
62
import javax.swing.SwingUtilities;
59
import javax.swing.SwingUtilities;
63
import org.openide.filesystems.FileObject;
60
import org.netbeans.modules.sampler.Sampler;
64
import org.openide.filesystems.FileUtil;
65
import org.openide.util.Exceptions;
61
import org.openide.util.Exceptions;
66
import org.openide.util.Lookup;
62
import org.openide.util.Lookup;
67
import org.openide.util.Mutex;
63
import org.openide.util.Mutex;
Lines 97-103 Link Here
97
    private final RequestProcessor.Task WAIT_CURSOR_CHECKER;
93
    private final RequestProcessor.Task WAIT_CURSOR_CHECKER;
98
    private volatile long ignoreTill;
94
    private volatile long ignoreTill;
99
    private volatile long start;
95
    private volatile long start;
100
    private volatile ActionListener stoppable;
96
    private volatile Sampler stoppable;
101
    private volatile boolean isWaitCursor;
97
    private volatile boolean isWaitCursor;
102
    static volatile Thread eq;
98
    static volatile Thread eq;
103
    private final Frame mainWindow;
99
    private final Frame mainWindow;
Lines 197-205 Link Here
197
        } else {
193
        } else {
198
            LOG.log(Level.FINEST, "done, timer stopped, took {0}", time);
194
            LOG.log(Level.FINEST, "done, timer stopped, took {0}", time);
199
        }
195
        }
200
        ActionListener ss = stoppable;
196
        Sampler ss = stoppable;
201
        if (ss != null) {
197
        if (ss != null) {
202
            ss.actionPerformed(new ActionEvent(this, 0, "cancel")); // NOI18N
198
            ss.cancel();
203
            stoppable = null;
199
            stoppable = null;
204
        }
200
        }
205
        return;
201
        return;
Lines 225-234 Link Here
225
            LOG.log(Level.WARNING, "Still previous controller {0}", stoppable);
221
            LOG.log(Level.WARNING, "Still previous controller {0}", stoppable);
226
            return;
222
            return;
227
        }
223
        }
228
        Runnable selfSampler = (Runnable)createSelfSampler();
224
        Sampler selfSampler = createSelfSampler();
229
        if (selfSampler != null) {
225
        if (selfSampler != null) {
230
            selfSampler.run();
226
            selfSampler.start();
231
            stoppable = (ActionListener)selfSampler;
227
            stoppable = selfSampler;
232
        }
228
        }
233
        isWaitCursor |= isWaitCursor();
229
        isWaitCursor |= isWaitCursor();
234
        if (!isWaitCursor) {
230
        if (!isWaitCursor) {
Lines 236-242 Link Here
236
        }
232
        }
237
    }
233
    }
238
234
239
    private static void report(final ActionListener ss, final long time) {
235
    private static void report(final Sampler ss, final long time) {
240
        if (ss == null) {
236
        if (ss == null) {
241
            return;
237
            return;
242
        }
238
        }
Lines 246-252 Link Here
246
                try {
242
                try {
247
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
243
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
248
                    DataOutputStream dos = new DataOutputStream(out);
244
                    DataOutputStream dos = new DataOutputStream(out);
249
                    ss.actionPerformed(new ActionEvent(dos, 0, "write")); // NOI18N
245
                    ss.stopAndWriteTo(dos);
250
                    dos.close();
246
                    dos.close();
251
                    if (dos.size() > 0) {
247
                    if (dos.size() > 0) {
252
                        Object[] params = new Object[]{out.toByteArray(), time};
248
                        Object[] params = new Object[]{out.toByteArray(), time};
Lines 262-277 Link Here
262
        RP.post(new R());
258
        RP.post(new R());
263
    }
259
    }
264
260
265
    private static Object createSelfSampler() {
261
    private static Sampler createSelfSampler() {
266
        FileObject fo = FileUtil.getConfigFile("Actions/Profile/org-netbeans-modules-profiler-actions-SelfSamplerAction.instance");
262
        return Sampler.getSampler("logger-awt"); // NOI18N
267
        if (fo == null) {
268
            return null;
269
        }
270
        Action a = (Action)fo.getAttribute("delegate"); // NOI18N
271
        if (a == null) {
272
            return null;
273
        }
274
        return a.getValue("logger-awt"); // NOI18N
275
    }
263
    }
276
264
277
    private static boolean isWaitCursor() {
265
    private static boolean isWaitCursor() {
(-)a/parsing.api/nbproject/project.xml (+8 lines)
Lines 141-146 Link Here
141
                    </run-dependency>
141
                    </run-dependency>
142
                </dependency>
142
                </dependency>
143
                <dependency>
143
                <dependency>
144
                    <code-name-base>org.netbeans.modules.sampler</code-name-base>
145
                    <build-prerequisite/>
146
                    <compile-dependency/>
147
                    <run-dependency>
148
                        <specification-version>1.0</specification-version>
149
                    </run-dependency>
150
                </dependency>
151
                <dependency>
144
                    <code-name-base>org.netbeans.spi.tasklist</code-name-base>
152
                    <code-name-base>org.netbeans.spi.tasklist</code-name-base>
145
                    <build-prerequisite/>
153
                    <build-prerequisite/>
146
                    <compile-dependency/>
154
                    <compile-dependency/>
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/SelfProfile.java (-29 / +12 lines)
Lines 41-55 Link Here
41
 */
41
 */
42
package org.netbeans.modules.parsing.impl;
42
package org.netbeans.modules.parsing.impl;
43
43
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.io.ByteArrayOutputStream;
44
import java.io.ByteArrayOutputStream;
47
import java.io.DataOutputStream;
45
import java.io.DataOutputStream;
48
import java.util.logging.Level;
46
import java.util.logging.Level;
49
import java.util.logging.Logger;
47
import java.util.logging.Logger;
50
import javax.swing.Action;
48
import org.netbeans.modules.sampler.Sampler;
51
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileUtil;
53
import org.openide.util.Exceptions;
49
import org.openide.util.Exceptions;
54
50
55
/**
51
/**
Lines 58-85 Link Here
58
 */
54
 */
59
final class SelfProfile {
55
final class SelfProfile {
60
    private static final Logger LOG = Logger.getLogger(SelfProfile.class.getName());
56
    private static final Logger LOG = Logger.getLogger(SelfProfile.class.getName());
61
57
    
62
    private final Object profiler;
58
    private final Sampler profiler;
63
    private final long time;
59
    private final long time;
64
    private volatile boolean profiling;
60
    private volatile boolean profiling;
65
61
66
    SelfProfile (long when) {
62
    SelfProfile (long when) {
67
        time = when;
63
        time = when;
68
        Object p = null;
64
        this.profiler = Sampler.getSampler("logger-taskcancel"); // NOI18N;
69
        final FileObject fo = FileUtil.getConfigFile("Actions/Profile/org-netbeans-modules-profiler-actions-SelfSamplerAction.instance"); // NOI18N
70
        if (fo != null) {
71
            final Action a = (Action) fo.getAttribute("delegate"); // NOI18N
72
            if (a != null) {
73
                p = a.getValue("logger-taskcancel"); // NOI18N
74
            }
75
        }
76
        this.profiler = p;
77
        this.profiling = true;
65
        this.profiling = true;
78
66
79
        LOG.finest("STARTED");  //NOI18N
67
        if (profiler != null) {
80
        if (profiler instanceof Runnable) {
68
            profiler.start();
81
            final Runnable r = (Runnable) profiler;
82
            r.run();
83
            LOG.log(Level.FINE, "Profiling started {0} at {1}", new Object[] { profiler, time });   //NOI18N
69
            LOG.log(Level.FINE, "Profiling started {0} at {1}", new Object[] { profiler, time });   //NOI18N
84
        }
70
        }
85
    }
71
    }
Lines 101-123 Link Here
101
        final long now = System.currentTimeMillis();
87
        final long now = System.currentTimeMillis();
102
        long delta = now - time;
88
        long delta = now - time;
103
        LOG.log(Level.FINE, "Profiling stopped at {0}", now);
89
        LOG.log(Level.FINE, "Profiling stopped at {0}", now);
104
        ActionListener ss = (ActionListener) profiler;
105
        int report = Integer.getInteger("org.netbeans.modules.parsing.api.taskcancel.slowness.report", 1000); // NOI18N
90
        int report = Integer.getInteger("org.netbeans.modules.parsing.api.taskcancel.slowness.report", 1000); // NOI18N
106
        if (delta < report) {
91
        if (delta < report) {
107
            LOG.finest("CANCEL");  //NOI18N
92
            LOG.log(Level.FINE, "Cancel profiling of {0}. Profiling {1}. Time {2} ms.", new Object[] { profiler, profiling, delta });
108
            if (ss != null) {
93
            if (profiler != null) {
109
                ss.actionPerformed(new ActionEvent(this, 0, "cancel"));
94
                profiler.cancel();
110
                LOG.log(Level.FINE, "Cancel profiling of {0}. Profiling {1}. Time {2} ms.", new Object[] { ss, profiling, delta });
111
            }
95
            }
112
            return;
96
            return;
113
        }
97
        }
114
        try {
98
        try {
99
            LOG.log(Level.FINE, "Obtaining snapshot for {0} ms.", delta);
115
            ByteArrayOutputStream out = new ByteArrayOutputStream();
100
            ByteArrayOutputStream out = new ByteArrayOutputStream();
116
            DataOutputStream dos = new DataOutputStream(out);
101
            DataOutputStream dos = new DataOutputStream(out);
117
            LOG.finest("LOGGED");  //NOI18N
102
            if (profiler != null) {
118
            if (ss != null) {
103
                profiler.stopAndWriteTo(dos);
119
                ss.actionPerformed(new ActionEvent(dos, 0, "write")); // NOI18N
120
                LOG.log(Level.FINE, "Obtaining snapshot for {0} ms.", delta);   //NOI18N
121
            }
104
            }
122
            dos.close();
105
            dos.close();
123
            if (dos.size() > 0) {
106
            if (dos.size() > 0) {
(-)a/sampler/apichanges.xml (+80 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
11
The contents of this file are subject to the terms of either the GNU
12
General Public License Version 2 only ("GPL") or the Common
13
Development and Distribution License("CDDL") (collectively, the
14
"License"). You may not use this file except in compliance with the
15
License. You can obtain a copy of the License at
16
http://www.netbeans.org/cddl-gplv2.html
17
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
specific language governing permissions and limitations under the
19
License.  When distributing the software, include this License Header
20
Notice in each file and include the License file at
21
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
particular file as subject to the "Classpath" exception as provided
23
by Oracle in the GPL Version 2 section of the License file that
24
accompanied this code. If applicable, add the following below the
25
License Header, with the fields enclosed by brackets [] replaced by
26
your own identifying information:
27
"Portions Copyrighted [year] [name of copyright owner]"
28
29
Contributor(s):
30
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
33
Microsystems, Inc. All Rights Reserved.
34
35
If you wish your version of this file to be governed by only the CDDL
36
or only the GPL Version 2, indicate your decision by adding
37
"[Contributor] elects to include this software in this distribution
38
under the [CDDL or GPL Version 2] license." If you do not indicate a
39
single choice of license, a recipient has the option to distribute
40
your version of this file under either the CDDL, the GPL Version 2 or
41
to extend the choice of license to its licensees as provided above.
42
However, if you add GPL Version 2 code and therefore, elected the GPL
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
45
-->
46
47
<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.0//EN" "../nbbuild/javadoctools/apichanges.dtd">
48
49
<apichanges>
50
<apidefs>
51
    <apidef name="sampler">Sampler API</apidef>
52
</apidefs>
53
<changes>
54
</changes>
55
<htmlcontents>
56
<head>
57
<title>Change History for the Sampler API</title>
58
<link rel="stylesheet" href="prose.css" type="text/css"/>
59
</head>
60
<body>
61
<p class="overviewlink">
62
<a href="overview-summary.html">Overview</a>
63
</p>
64
<h1>Introduction</h1>
65
<h2>What do the Dates Mean?</h2>
66
<p>The supplied dates indicate when the API change was made, on the HG 
67
default branch. From this you can generally tell whether the change should be
68
present in a given build or not; for trunk builds, simply whether it
69
was made before or after the change; for builds on a stabilization
70
branch, whether the branch was made before or after the given date. In
71
some cases corresponding API changes have been made both in the trunk
72
and in an in-progress stabilization branch, if they were needed for a
73
bug fix; this ought to be marked in this list.</p>
74
<hr/>
75
<standard-changelists module-code-name="$codebase"/>
76
<hr/>
77
<p>@FOOTER@</p>
78
</body>
79
</htmlcontents>
80
</apichanges>
(-)a/sampler/arch.xml (+1068 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
11
The contents of this file are subject to the terms of either the GNU
12
General Public License Version 2 only ("GPL") or the Common
13
Development and Distribution License("CDDL") (collectively, the
14
"License"). You may not use this file except in compliance with the
15
License. You can obtain a copy of the License at
16
http://www.netbeans.org/cddl-gplv2.html
17
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
specific language governing permissions and limitations under the
19
License.  When distributing the software, include this License Header
20
Notice in each file and include the License file at
21
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
particular file as subject to the "Classpath" exception as provided
23
by Oracle in the GPL Version 2 section of the License file that
24
accompanied this code. If applicable, add the following below the
25
License Header, with the fields enclosed by brackets [] replaced by
26
your own identifying information:
27
"Portions Copyrighted [year] [name of copyright owner]"
28
29
Contributor(s):
30
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
33
Microsystems, Inc. All Rights Reserved.
34
35
If you wish your version of this file to be governed by only the CDDL
36
or only the GPL Version 2, indicate your decision by adding
37
"[Contributor] elects to include this software in this distribution
38
under the [CDDL or GPL Version 2] license." If you do not indicate a
39
single choice of license, a recipient has the option to distribute
40
your version of this file under either the CDDL, the GPL Version 2 or
41
to extend the choice of license to its licensees as provided above.
42
However, if you add GPL Version 2 code and therefore, elected the GPL
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
45
-->
46
<!DOCTYPE api-answers PUBLIC "-//NetBeans//DTD Arch Answers//EN" "../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd" [
47
  <!ENTITY api-questions SYSTEM "../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml">
48
]>
49
50
<api-answers
51
  question-version="1.28"
52
  module="Sampling API"
53
  author="thurka@netbeans.org"
54
>
55
56
  &api-questions;
57
58
59
<!--
60
        <question id="arch-overall" when="init">
61
            Describe the overall architecture.
62
            <hint>
63
            What will be API for 
64
            <a href="http://openide.netbeans.org/tutorial/api-design.html#design.apiandspi">
65
                clients and what support API</a>? 
66
            What parts will be pluggable?
67
            How will plug-ins be registered? Please use <code>&lt;api type="export"/&gt;</code>
68
            to describe your general APIs.
69
            If possible please provide 
70
            simple diagrams. 
71
            </hint>
72
        </question>
73
-->
74
 <answer id="arch-overall">
75
  <p>
76
   <api name="SamplerAPI" category="official" group="java" type="export" url="@TOP@/org/netbeans/modules/sampler/package-summary.html"/>
77
   allows anyone to self-sample NetBeans Platform based application. 
78
  </p>
79
  
80
 </answer>
81
82
83
84
<!--
85
        <question id="arch-quality" when="init">
86
            How will the <a href="http://www.netbeans.org/community/guidelines/q-evangelism.html">quality</a>
87
            of your code be tested and 
88
            how are future regressions going to be prevented?
89
            <hint>
90
            What kind of testing do
91
            you want to use? How much functionality, in which areas,
92
            should be covered by the tests? 
93
            </hint>
94
        </question>
95
-->
96
 <answer id="arch-quality">
97
  <p>
98
   There will be tests to verify that the API works
99
   as advertised.
100
  </p>
101
 </answer>
102
103
104
105
<!--
106
        <question id="arch-time" when="init">
107
            What are the time estimates of the work?
108
            <hint>
109
            Please express your estimates of how long the design, implementation,
110
            stabilization are likely to last. How many people will be needed to
111
            implement this and what is the expected milestone by which the work should be 
112
            ready?
113
            </hint>
114
        </question>
115
-->
116
 <answer id="arch-time">
117
  <p>
118
   Currently NetBeans has sampling code part of core.ui module. There is
119
   semi-API used by other modules like core, jumpto, editor.completion, 
120
   but it would be desirable to have real API in separate module. 
121
   So let's target this for inclusion in NetBeans 7.2 releases.
122
  </p>
123
 </answer>
124
125
126
127
<!--
128
        <question id="arch-usecases" when="init">
129
            <hint>
130
                Content of this answer will be displayed as part of page at
131
                http://www.netbeans.org/download/dev/javadoc/usecases.html 
132
                You can use tags &lt;usecase name="name&gt; regular html description &lt;/usecase&gt;
133
                and if you want to use an URL you can prefix if with @TOP@ to begin
134
                at the root of your javadoc
135
            </hint>
136
        
137
            Describe the main <a href="http://openide.netbeans.org/tutorial/api-design.html#usecase">
138
            use cases</a> of the new API. Who will use it under
139
            what circumstances? What kind of code would typically need to be written
140
            to use the module?
141
        </question>
142
-->
143
 <answer id="arch-usecases">
144
  <p>
145
   <usecase id="user-sampling" name="User controlled sampling" >
146
       There needs to be a simple API for someone who wants to create simple user 
147
       action which starts and stops self-sampling and presents user with sampled
148
       results.
149
       <p></p>
150
       The correct way to achieve this is to call 
151
        <code><a href="@TOP@/org/netbeans/modules/sampler/Sampler.html">Sampler</a>.getGenericSampler()</code>,
152
        followed by
153
        <code><a href="@TOP@/org/netbeans/modules/sampler/Sampler.html">Sampler</a>.start()</code> and
154
        <code><a href="@TOP@/org/netbeans/modules/sampler/Sampler.html">Sampler</a>.stop()</code>.
155
        
156
   </usecase>
157
   <usecase id="code-sampling" name="Sampling of the slow operation" >
158
       Second major use-case of the Sampling API is sampling of the slow operation.
159
       
160
       <p></p>
161
       The correct way to achieve this is to call 
162
        <code><a href="@TOP@/org/netbeans/modules/sampler/Sampler.html">Sampler</a>.getSampler()</code>,
163
        followed by
164
        <code><a href="@TOP@/org/netbeans/modules/sampler/Sampler.html">Sampler</a>.start()</code> and
165
        <code><a href="@TOP@/org/netbeans/modules/sampler/Sampler.html">Sampler</a>.stopAndWriteTo(DataOutputStream dos)</code>.
166
   </usecase>
167
  </p>
168
 </answer>
169
170
171
172
<!--
173
        <question id="arch-what" when="init">
174
            What is this project good for?
175
            <hint>
176
            Please provide here a few lines describing the project, 
177
            what problem it should solve, provide links to documentation, 
178
            specifications, etc.
179
            </hint>
180
        </question>
181
-->
182
 <answer id="arch-what">
183
  <p>
184
   It allows NetBeans Platform developer to self-sample their application,
185
   which should provide them with a valuable information about CPU 
186
   performance problems.
187
  </p>
188
 </answer>
189
190
191
192
<!--
193
        <question id="arch-where" when="init">
194
            Where one can find sources for your module?
195
            <hint>
196
                Please provide link to the CVS web client at
197
                http://www.netbeans.org/download/source_browse.html
198
                or just use tag defaultanswer generate='here'
199
            </hint>
200
        </question>
201
-->
202
 <answer id="arch-where">
203
  <defaultanswer generate='here' />
204
 </answer>
205
206
207
208
<!--
209
        <question id="compat-i18n" when="impl">
210
            Is your module correctly internationalized?
211
            <hint>
212
            Correct internationalization means that it obeys instructions 
213
            at <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/i18n-branding.html">
214
            NetBeans I18N pages</a>.
215
            </hint>
216
        </question>
217
-->
218
 <answer id="compat-i18n">
219
  <p>
220
   Yes, it is.
221
  </p>
222
 </answer>
223
224
<answer id="compat-deprecation">
225
  <p>
226
   This module replaces the previous semi-API
227
   offered by <code>core.ui</code> module. Modules are now adviced
228
   to depend just on the API exported by this module. 
229
  </p>
230
 </answer>
231
232
233
<!--
234
        <question id="compat-standards" when="init">
235
            Does the module implement or define any standards? Is the 
236
            implementation exact or does it deviate somehow?
237
        </question>
238
-->
239
 <answer id="compat-standards">
240
  <p>
241
   No standard is implemented by this module.
242
  </p>
243
 </answer>
244
245
246
247
<!--
248
        <question id="compat-version" when="impl">
249
            Can your module coexist with earlier and future
250
            versions of itself? Can you correctly read all old settings? Will future
251
            versions be able to read your current settings? Can you read
252
            or politely ignore settings stored by a future version?
253
            
254
            <hint>
255
            Very helpful for reading settings is to store version number
256
            there, so future versions can decide whether how to read/convert
257
            the settings and older versions can ignore the new ones.
258
            </hint>
259
        </question>
260
-->
261
 <answer id="compat-version">
262
  <p>
263
   XXX no answer for compat-version
264
  </p>
265
 </answer>
266
267
268
269
<!--
270
        <question id="dep-jre" when="final">
271
            Which version of JRE do you need (1.2, 1.3, 1.4, etc.)?
272
            <hint>
273
            It is expected that if your module runs on 1.x that it will run 
274
            on 1.x+1 if no, state that please. Also describe here cases where
275
            you run different code on different versions of JRE and why.
276
            </hint>
277
        </question>
278
-->
279
 <answer id="dep-jre">
280
  <p>
281
   XXX no answer for dep-jre
282
  </p>
283
 </answer>
284
285
286
287
<!--
288
        <question id="dep-jrejdk" when="final">
289
            Do you require the JDK or is the JRE enough?
290
        </question>
291
-->
292
 <answer id="dep-jrejdk">
293
  <p>
294
   XXX no answer for dep-jrejdk
295
  </p>
296
 </answer>
297
298
299
300
<!--
301
        <question id="dep-nb" when="init">
302
            What other NetBeans projects and modules does this one depend on?
303
            <hint>
304
            If you want, describe such projects as imported APIs using
305
            the <code>&lt;api name="identification" type="import or export" category="stable" url="where is the description" /&gt;</code>
306
            </hint>
307
        </question>
308
-->
309
 <answer id="dep-nb">
310
  <defaultanswer generate='here' />
311
 </answer>
312
313
314
315
<!--
316
        <question id="dep-non-nb" when="init">
317
            What other projects outside NetBeans does this one depend on?
318
            
319
            <hint>
320
            Some non-NetBeans projects are packaged as NetBeans modules
321
            (see <a href="http://libs.netbeans.org/">libraries</a>) and
322
            it is preferred to use this approach when more modules may
323
            depend on such third-party library.
324
            </hint>
325
        </question>
326
-->
327
 <answer id="dep-non-nb">
328
  <p>
329
   None.
330
  </p>
331
 </answer>
332
333
334
335
<!--
336
        <question id="dep-platform" when="init">
337
            On which platforms does your module run? Does it run in the same
338
            way on each?
339
            <hint>
340
            If your module is using JNI or deals with special differences of
341
            OSes like filesystems, etc. please describe here what they are.
342
            </hint>
343
        </question>
344
-->
345
 <answer id="dep-platform">
346
  <p>
347
   There is no platform dependency.
348
  </p>
349
 </answer>
350
351
352
353
 <answer id="deploy-dependencies">
354
  <p>
355
   Nothing.
356
  </p>
357
 </answer>
358
359
360
361
<!--
362
        <question id="deploy-jar" when="impl">
363
            Do you deploy just module JAR file(s) or other files as well?
364
            <hint>
365
            Usually a module consist of one JAR file (perhaps with Class-Path
366
            extensions) and also a configuration file that enables it. If you
367
            have any other files, use
368
            &lt;api group="java.io.File" name="yourname" type="export" category="friend"&gt;...&lt;/api&gt;
369
            to define the location, name and stability of your files (of course
370
            changing "yourname" and "friend" to suit your needs).
371
            
372
            If it uses more than one JAR, describe where they are located, how
373
            they refer to each other. 
374
            If it consist of module JAR(s) and other files, please describe
375
            what is their purpose, why other files are necessary. Please 
376
            make sure that installation/uninstallation leaves the system 
377
            in state as it was before installation.
378
            </hint>
379
        </question>
380
-->
381
 <answer id="deploy-jar">
382
  <p>
383
   XXX no answer for deploy-jar
384
  </p>
385
 </answer>
386
387
388
389
<!--
390
        <question id="deploy-nbm" when="impl">
391
            Can you deploy an NBM via the Update Center?
392
            <hint>
393
            If not why?
394
            </hint>
395
        </question>
396
-->
397
 <answer id="deploy-nbm">
398
  <p>
399
   Yes, it can be deployed as NBM.
400
  </p>
401
 </answer>
402
403
404
405
<!--
406
        <question id="deploy-packages" when="init">
407
            Are packages of your module made inaccessible by not declaring them
408
            public?
409
            
410
            <hint>
411
            NetBeans module system allows restriction of access rights to
412
            public classes of your module from other modules. This prevents
413
            unwanted dependencies of others on your code and should be used
414
            whenever possible (<a href="http://www.netbeans.org/download/javadoc/OpenAPIs/org/openide/doc-files/upgrade.html#3.4-public-packages">
415
            public packages
416
            </a>). If you do not restrict access to your classes you are
417
            making it too easy for other people to misuse your implementation
418
            details, that is why you should have good reason for not 
419
            restricting package access.
420
            </hint>
421
        </question>
422
-->
423
 <answer id="deploy-packages">
424
  <p>
425
   XXX no answer for deploy-packages
426
  </p>
427
 </answer>
428
429
430
431
<!--
432
        <question id="deploy-shared" when="final">
433
            Do you need to be installed in the shared location only, or in the user directory only,
434
            or can your module be installed anywhere?
435
            <hint>
436
            Installation location shall not matter, if it does explain why.
437
            Consider also whether <code>InstalledFileLocator</code> can help.
438
            </hint>
439
        </question>
440
-->
441
 <answer id="deploy-shared">
442
  <p>
443
   XXX no answer for deploy-shared
444
  </p>
445
 </answer>
446
447
448
449
<!--
450
        <question id="exec-ant-tasks" when="impl">
451
            Do you define or register any ant tasks that other can use?
452
            
453
            <hint>
454
            If you provide an ant task that users can use, you need to be very
455
            careful about its syntax and behaviour, as it most likely forms an
456
	          API for end users and as there is a lot of end users, their reaction
457
            when such API gets broken can be pretty strong.
458
            </hint>
459
        </question>
460
-->
461
 <answer id="exec-ant-tasks">
462
  <p>
463
   XXX no answer for exec-ant-tasks
464
  </p>
465
 </answer>
466
467
468
469
<!--
470
        <question id="exec-classloader" when="impl">
471
            Does your code create its own class loader(s)?
472
            <hint>
473
            A bit unusual. Please explain why and what for.
474
            </hint>
475
        </question>
476
-->
477
 <answer id="exec-classloader">
478
  <p>
479
   XXX no answer for exec-classloader
480
  </p>
481
 </answer>
482
483
484
485
<!--
486
        <question id="exec-component" when="impl">
487
            Is execution of your code influenced by any (string) property
488
            of any of your components?
489
            
490
            <hint>
491
            Often <code>JComponent.getClientProperty</code>, <code>Action.getValue</code>
492
            or <code>PropertyDescriptor.getValue</code>, etc. are used to influence
493
            a behavior of some code. This of course forms an interface that should
494
            be documented. Also if one depends on some interface that an object
495
            implements (<code>component instanceof Runnable</code>) that forms an
496
            API as well.
497
            </hint>
498
        </question>
499
-->
500
 <answer id="exec-component">
501
  <p>
502
   XXX no answer for exec-component
503
  </p>
504
 </answer>
505
506
507
508
<!--
509
        <question id="exec-introspection" when="impl">
510
            Does your module use any kind of runtime type information (<code>instanceof</code>,
511
            work with <code>java.lang.Class</code>, etc.)?
512
            <hint>
513
            Check for cases when you have an object of type A and you also
514
            expect it to (possibly) be of type B and do some special action. That
515
            should be documented. The same applies on operations in meta-level
516
            (Class.isInstance(...), Class.isAssignableFrom(...), etc.).
517
            </hint>
518
        </question>
519
-->
520
 <answer id="exec-introspection">
521
  <p>
522
   XXX no answer for exec-introspection
523
  </p>
524
 </answer>
525
526
527
528
<!--
529
        <question id="exec-privateaccess" when="final">
530
            Are you aware of any other parts of the system calling some of 
531
            your methods by reflection?
532
            <hint>
533
            If so, describe the "contract" as an API. Likely private or friend one, but
534
            still API and consider rewrite of it.
535
            </hint>
536
        </question>
537
-->
538
 <answer id="exec-privateaccess">
539
  <p>
540
   XXX no answer for exec-privateaccess
541
  </p>
542
 </answer>
543
544
545
546
<!--
547
        <question id="exec-process" when="impl">
548
            Do you execute an external process from your module? How do you ensure
549
            that the result is the same on different platforms? Do you parse output?
550
            Do you depend on result code?
551
            <hint>
552
            If you feed an input, parse the output please declare that as an API.
553
            </hint>
554
        </question>
555
-->
556
 <answer id="exec-process">
557
  <p>
558
   XXX no answer for exec-process
559
  </p>
560
 </answer>
561
562
563
564
<!--
565
        <question id="exec-property" when="impl">
566
            Is execution of your code influenced by any environment or
567
            Java system (<code>System.getProperty</code>) property?
568
            
569
            <hint>
570
            If there is a property that can change the behavior of your 
571
            code, somebody will likely use it. You should describe what it does 
572
            and the <a href="http://openide.netbeans.org/tutorial/api-design.html#life">stability category</a>
573
            of this API. You may use
574
            <pre>
575
                &lt;api type="export" group="property" name="id" category="private" url="http://..."&gt;
576
                    description of the property, where it is used, what it influence, etc.
577
                &lt;/api&gt;            
578
            </pre>
579
            </hint>
580
        </question>
581
-->
582
 <answer id="exec-property">
583
  <p>
584
   XXX no answer for exec-property
585
  </p>
586
 </answer>
587
588
589
590
<!--
591
        <question id="exec-reflection" when="impl">
592
            Does your code use Java Reflection to execute other code?
593
            <hint>
594
            This usually indicates a missing or insufficient API in the other
595
            part of the system. If the other side is not aware of your dependency
596
            this contract can be easily broken.
597
            </hint>
598
        </question>
599
-->
600
 <answer id="exec-reflection">
601
  <p>
602
   XXX no answer for exec-reflection
603
  </p>
604
 </answer>
605
606
607
608
<!--
609
        <question id="exec-threading" when="impl">
610
            What threading models, if any, does your module adhere to?
611
            <hint>
612
                If your module calls foreign APIs which have a specific threading model,
613
                indicate how you comply with the requirements for multithreaded access
614
                (synchronization, mutexes, etc.) applicable to those APIs.
615
                If your module defines any APIs, or has complex internal structures
616
                that might be used from multiple threads, declare how you protect
617
                data against concurrent access, race conditions, deadlocks, etc.,
618
                and whether such rules are enforced by runtime warnings, errors, assertions, etc.
619
                Examples: a class might be non-thread-safe (like Java Collections); might
620
                be fully thread-safe (internal locking); might require access through a mutex
621
                (and may or may not automatically acquire that mutex on behalf of a client method);
622
                might be able to run only in the event queue; etc.
623
                Also describe when any events are fired: synchronously, asynchronously, etc.
624
                Ideas: <a href="http://core.netbeans.org/proposals/threading/index.html#recommendations">Threading Recommendations</a> (in progress)
625
            </hint>
626
        </question>
627
-->
628
 <answer id="exec-threading">
629
  <p>
630
   XXX no answer for exec-threading
631
  </p>
632
 </answer>
633
634
635
636
<!--
637
        <question id="format-clipboard" when="impl">
638
            Which data flavors (if any) does your code read from or insert to
639
            the clipboard (by access to clipboard on means calling methods on <code>java.awt.datatransfer.Transferable</code>?
640
            
641
            <hint>
642
            Often Node's deal with clipboard by usage of <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
643
            Check your code for overriding these methods.
644
            </hint>
645
        </question>
646
-->
647
 <answer id="format-clipboard">
648
  <p>
649
   XXX no answer for format-clipboard
650
  </p>
651
 </answer>
652
653
654
655
<!--
656
        <question id="format-dnd" when="impl">
657
            Which protocols (if any) does your code understand during Drag &amp; Drop?
658
            <hint>
659
            Often Node's deal with clipboard by usage of <code>Node.drag, Node.getDropType</code>. 
660
            Check your code for overriding these methods. Btw. if they are not overridden, they
661
            by default delegate to <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
662
            </hint>
663
        </question>
664
-->
665
 <answer id="format-dnd">
666
  <p>
667
   XXX no answer for format-dnd
668
  </p>
669
 </answer>
670
671
672
673
<!--
674
        <question id="format-types" when="impl">
675
            Which protocols and file formats (if any) does your module read or write on disk,
676
            or transmit or receive over the network? Do you generate an ant build script?
677
            Can it be edited and modified? 
678
            
679
            <hint>
680
            <p>
681
            Files can be read and written by other programs, modules and users. If they influence
682
            your behaviour, make sure you either document the format or claim that it is a private
683
            api (using the &lt;api&gt; tag). 
684
            </p>
685
            
686
            <p>
687
            If you generate an ant build file, this is very likely going to be seen by end users and
688
            they will be attempted to edit it. You should be ready for that and provide here a link
689
            to documentation that you have for such purposes and also describe how you are going to
690
            understand such files during next release, when you (very likely) slightly change the 
691
            format.
692
            </p>
693
            </hint>
694
        </question>
695
-->
696
 <answer id="format-types">
697
  <p>
698
   XXX no answer for format-types
699
  </p>
700
 </answer>
701
702
703
704
<!--
705
        <question id="lookup-lookup" when="init">
706
            Does your module use <code>org.openide.util.Lookup</code>
707
            or any similar technology to find any components to communicate with? Which ones?
708
            
709
            <hint>
710
            Please describe the interfaces you are searching for, where 
711
            are defined, whether you are searching for just one or more of them,
712
            if the order is important, etc. Also classify the stability of such
713
            API contract. For that use &lt;api group=&amp;lookup&amp; /&gt; tag.
714
            </hint>
715
        </question>
716
-->
717
 <answer id="lookup-lookup">
718
  <p>
719
   XXX no answer for format-types
720
  </p>
721
 </answer>
722
723
724
725
<!--
726
        <question id="lookup-register" when="final">
727
            Do you register anything into lookup for other code to find?
728
            <hint>
729
            Do you register using layer file or using <code>META-INF/services</code>?
730
            Who is supposed to find your component?
731
            </hint>
732
        </question>
733
-->
734
 <answer id="lookup-register">
735
  <p>
736
   XXX no answer for lookup-register
737
  </p>
738
 </answer>
739
740
741
742
<!--
743
        <question id="lookup-remove" when="final">
744
            Do you remove entries of other modules from lookup?
745
            <hint>
746
            Why? Of course, that is possible, but it can be dangerous. Is the module
747
            your are masking resource from aware of what you are doing?
748
            </hint>
749
        </question>
750
-->
751
 <answer id="lookup-remove">
752
  <p>
753
   XXX no answer for lookup-remove
754
  </p>
755
 </answer>
756
757
758
759
<!--
760
        <question id="perf-exit" when="final">
761
            Does your module run any code on exit?
762
        </question>
763
-->
764
 <answer id="perf-exit">
765
  <p>
766
   XXX no answer for perf-exit
767
  </p>
768
 </answer>
769
770
771
772
<!--
773
        <question id="perf-huge_dialogs" when="final">
774
            Does your module contain any dialogs or wizards with a large number of
775
            GUI controls such as combo boxes, lists, trees, or text areas?
776
        </question>
777
-->
778
 <answer id="perf-huge_dialogs">
779
  <p>
780
   XXX no answer for perf-huge_dialogs
781
  </p>
782
 </answer>
783
784
785
786
<!--
787
        <question id="perf-limit" when="init">
788
            Are there any hard-coded or practical limits in the number or size of
789
            elements your code can handle?
790
        </question>
791
-->
792
 <answer id="perf-limit">
793
  <p>
794
   XXX no answer for perf-limit
795
  </p>
796
 </answer>
797
798
799
800
<!--
801
        <question id="perf-mem" when="final">
802
            How much memory does your component consume? Estimate
803
            with a relation to the number of windows, etc.
804
        </question>
805
-->
806
 <answer id="perf-mem">
807
  <p>
808
   XXX no answer for perf-mem
809
  </p>
810
 </answer>
811
812
813
814
<!--
815
        <question id="perf-menus" when="final">
816
            Does your module use dynamically updated context menus, or
817
            context-sensitive actions with complicated and slow enablement logic?
818
            <hint>
819
                If you do a lot of tricks when adding actions to regular or context menus, you can significantly
820
                slow down display of the menu, even when the user is not using your action. Pay attention to
821
                actions you add to the main menu bar, and to context menus of foreign nodes or components. If
822
                the action is conditionally enabled, or changes its display dynamically, you need to check the
823
                impact on performance. In some cases it may be more appropriate to make a simple action that is
824
                always enabled but does more detailed checks in a dialog if it is actually run.
825
            </hint>
826
        </question>
827
-->
828
 <answer id="perf-menus">
829
  <p>
830
   XXX no answer for perf-menus
831
  </p>
832
 </answer>
833
834
835
836
<!--
837
        <question id="perf-progress" when="final">
838
            Does your module execute any long-running tasks?
839
            
840
            <hint>Long running tasks should never block 
841
            AWT thread as it badly hurts the UI
842
            <a href="http://performance.netbeans.org/responsiveness/issues.html">
843
            responsiveness</a>.
844
            Tasks like connecting over
845
            network, computing huge amount of data, compilation
846
            be done asynchronously (for example
847
            using <code>RequestProcessor</code>), definitively it should 
848
            not block AWT thread.
849
            </hint>
850
        </question>
851
-->
852
 <answer id="perf-progress">
853
  <p>
854
   XXX no answer for perf-progress
855
  </p>
856
 </answer>
857
858
859
860
<!--
861
        <question id="perf-scale" when="init">
862
            Which external criteria influence the performance of your
863
            program (size of file in editor, number of files in menu, 
864
            in source directory, etc.) and how well your code scales?
865
            <hint>
866
            Please include some estimates, there are other more detailed 
867
            questions to answer in later phases of implementation. 
868
            </hint>
869
        </question>
870
-->
871
 <answer id="perf-scale">
872
  <p>
873
   XXX no answer for perf-scale
874
  </p>
875
 </answer>
876
877
878
879
<!--
880
        <question id="perf-spi" when="init">
881
            How the performance of the plugged in code will be enforced?
882
            <hint>
883
            If you allow foreign code to be plugged into your own module, how
884
            do you enforce that it will behave correctly and quickly and will not
885
            negatively influence the performance of your own module?
886
            </hint>
887
        </question>
888
-->
889
 <answer id="perf-spi">
890
  <p>
891
   XXX no answer for perf-spi
892
  </p>
893
 </answer>
894
895
896
897
<!--
898
        <question id="perf-startup" when="final">
899
            Does your module run any code on startup?
900
        </question>
901
-->
902
 <answer id="perf-startup">
903
  <p>
904
   XXX no answer for perf-startup
905
  </p>
906
 </answer>
907
908
909
910
<!--
911
        <question id="perf-wakeup" when="final">
912
            Does any piece of your code wake up periodically and do something
913
            even when the system is otherwise idle (no user interaction)?
914
        </question>
915
-->
916
 <answer id="perf-wakeup">
917
  <p>
918
   XXX no answer for perf-wakeup
919
  </p>
920
 </answer>
921
922
923
924
<!--
925
        <question id="resources-file" when="final">
926
            Does your module use <code>java.io.File</code> directly?
927
            
928
            <hint>
929
            NetBeans provide a logical wrapper over plain files called 
930
            <code>org.openide.filesystems.FileObject</code> that
931
            provides uniform access to such resources and is the preferred
932
            way that should be used. But of course there can be situations when
933
            this is not suitable.
934
            </hint>
935
        </question>
936
-->
937
 <answer id="resources-file">
938
  <p>
939
   XXX no answer for resources-file
940
  </p>
941
 </answer>
942
943
944
945
<!--
946
        <question id="resources-layer" when="final">
947
            Does your module provide own layer? Does it create any files or
948
            folders in it? What it is trying to communicate by that and with which 
949
            components?
950
            
951
            <hint>
952
            NetBeans allows automatic and declarative installation of resources 
953
            by module layers. Module register files into appropriate places
954
            and other components use that information to perform their task
955
            (build menu, toolbar, window layout, list of templates, set of
956
            options, etc.). 
957
            </hint>
958
        </question>
959
-->
960
 <answer id="resources-layer">
961
  <p>
962
   XXX no answer for resources-layer
963
  </p>
964
 </answer>
965
966
967
968
<!--
969
        <question id="resources-mask" when="final">
970
            Does your module mask/hide/override any resources provided by other modules in
971
            their layers?
972
            
973
            <hint>
974
            If you mask a file provided by another module, you probably depend
975
            on that and do not want the other module to (for example) change
976
            the file's name. That module shall thus make that file available as an API
977
            of some stability category.
978
            </hint>
979
        </question>
980
-->
981
 <answer id="resources-mask">
982
  <p>
983
   XXX no answer for resources-mask
984
  </p>
985
 </answer>
986
987
988
989
<!--
990
        <question id="resources-read" when="final">
991
            Does your module read any resources from layers? For what purpose?
992
            
993
            <hint>
994
            As this is some kind of intermodule dependency, it is a kind of API.
995
            Please describe it and classify according to 
996
            <a href="http://openide.netbeans.org/tutorial/api-design.html#categories">
997
            common stability categories</a>.
998
            </hint>
999
        </question>
1000
-->
1001
 <answer id="resources-read">
1002
  <p>
1003
   XXX no answer for resources-read
1004
  </p>
1005
 </answer>
1006
1007
1008
1009
<!--
1010
        <question id="security-grant" when="final">
1011
            Does your code grant additional rights to some other code?
1012
            <hint>Avoid using a class loader that adds extra
1013
            permissions to loaded code unless really necessary.
1014
            Also note that your API implementation
1015
            can also expose unneeded permissions to enemy code by
1016
            calling AccessController.doPrivileged().</hint>
1017
        </question>
1018
-->
1019
 <answer id="security-grant">
1020
  <p>
1021
   XXX no answer for security-grant
1022
  </p>
1023
 </answer>
1024
1025
1026
1027
<!--
1028
        <question id="security-policy" when="final">
1029
            Does your functionality require modifications to the standard policy file?
1030
            <hint>Your code might pass control to third-party code not
1031
            coming from trusted domains. This could be code downloaded over the
1032
            network or code coming from libraries that are not bundled
1033
            with NetBeans. Which permissions need to be granted to which domains?</hint>
1034
        </question>
1035
-->
1036
 <answer id="security-policy">
1037
  <p>
1038
   XXX no answer for security-policy
1039
  </p>
1040
 </answer>
1041
1042
1043
1044
1045
<!--
1046
        <question id="resources-preferences" when="final">
1047
            Does your module uses preferences via Preferences API? Does your module use NbPreferences or
1048
            or regular JDK Preferences ? Does it read, write or both ? 
1049
            Does it share preferences with other modules ? If so, then why ?
1050
            <hint>
1051
                You may use
1052
                    &lt;api type="export" group="preferences"
1053
                    name="preference node name" category="private"&gt;
1054
                    description of individual keys, where it is used, what it
1055
                    influences, whether the module reads/write it, etc.
1056
                    &lt;/api&gt;
1057
                Due to XML ID restrictions, rather than /org/netbeans/modules/foo give the "name" as org.netbeans.modules.foo.
1058
                Note that if you use NbPreferences this name will then be the same as the code name base of the module.
1059
            </hint>
1060
        </question>
1061
-->
1062
 <answer id="resources-preferences">
1063
  <p>
1064
   XXX no answer for resources-preferences
1065
  </p>
1066
 </answer>
1067
1068
</api-answers>
(-)a/sampler/build.xml (+5 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="sampler">
3
    <description>Builds, tests, and runs the project org.netbeans.modules.sampler</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)a/sampler/manifest.mf (+5 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.sampler
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/sampler/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.0
5
(-)a/sampler/nbproject/project.properties (+4 lines)
Line 0 Link Here
1
is.autoload=true
2
javac.source=1.6
3
javac.compilerargs=-Xlint -Xlint:-serial
4
javadoc.arch=${basedir}/arch.xml
(-)a/sampler/nbproject/project.xml (+109 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.apisupport.project</type>
4
    <configuration>
5
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
6
            <code-name-base>org.netbeans.modules.sampler</code-name-base>
7
            <module-dependencies>
8
                <dependency>
9
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>1</release-version>
14
                        <specification-version>1.13</specification-version>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
18
                    <code-name-base>org.netbeans.api.progress</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <release-version>1</release-version>
23
                        <specification-version>1.27</specification-version>
24
                    </run-dependency>
25
                </dependency>
26
                <dependency>
27
                    <code-name-base>org.openide.awt</code-name-base>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
30
                    <run-dependency>
31
                        <specification-version>7.40</specification-version>
32
                    </run-dependency>
33
                </dependency>
34
                <dependency>
35
                    <code-name-base>org.openide.dialogs</code-name-base>
36
                    <build-prerequisite/>
37
                    <compile-dependency/>
38
                    <run-dependency>
39
                        <specification-version>7.24</specification-version>
40
                    </run-dependency>
41
                </dependency>
42
                <dependency>
43
                    <code-name-base>org.openide.filesystems</code-name-base>
44
                    <build-prerequisite/>
45
                    <compile-dependency/>
46
                    <run-dependency>
47
                        <specification-version>7.55</specification-version>
48
                    </run-dependency>
49
                </dependency>
50
                <dependency>
51
                    <code-name-base>org.openide.loaders</code-name-base>
52
                    <build-prerequisite/>
53
                    <compile-dependency/>
54
                    <run-dependency>
55
                        <specification-version>7.33</specification-version>
56
                    </run-dependency>
57
                </dependency>
58
                <dependency>
59
                    <code-name-base>org.openide.nodes</code-name-base>
60
                    <build-prerequisite/>
61
                    <compile-dependency/>
62
                    <run-dependency>
63
                        <specification-version>7.26</specification-version>
64
                    </run-dependency>
65
                </dependency>
66
                <dependency>
67
                    <code-name-base>org.openide.util</code-name-base>
68
                    <build-prerequisite/>
69
                    <compile-dependency/>
70
                    <run-dependency>
71
                        <specification-version>8.20</specification-version>
72
                    </run-dependency>
73
                </dependency>
74
                <dependency>
75
                    <code-name-base>org.openide.util.lookup</code-name-base>
76
                    <build-prerequisite/>
77
                    <compile-dependency/>
78
                    <run-dependency>
79
                        <specification-version>8.12</specification-version>
80
                    </run-dependency>
81
                </dependency>
82
            </module-dependencies>
83
            <test-dependencies>
84
                <test-type>
85
                    <name>unit</name>
86
                    <test-dependency>
87
                        <code-name-base>org.netbeans.insane</code-name-base>
88
                        <compile-dependency/>
89
                    </test-dependency>
90
                    <test-dependency>
91
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
92
                        <compile-dependency/>
93
                    </test-dependency>
94
                    <test-dependency>
95
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
96
                        <compile-dependency/>
97
                    </test-dependency>
98
                    <test-dependency>
99
                        <code-name-base>org.openide.dialogs</code-name-base>
100
                        <compile-dependency/>
101
                    </test-dependency>
102
                </test-type>
103
            </test-dependencies>
104
            <public-packages>
105
                <package>org.netbeans.modules.sampler</package>
106
            </public-packages>
107
        </data>
108
    </configuration>
109
</project>
(-)a/sampler/src/org/netbeans/modules/sampler/Bundle.properties (+3 lines)
Line 0 Link Here
1
OpenIDE-Module-Name=Sampler
2
SelfSamplerAction_SavedFile=Snapshot was saved to {0}
3
Save_Progress=Saving snapshot
(-)a/sampler/src/org/netbeans/modules/sampler/CLISampler.java (+161 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.sampler;
43
44
import java.io.File;
45
import java.io.FileOutputStream;
46
import java.io.IOException;
47
import java.lang.management.ManagementFactory;
48
import java.lang.management.ThreadMXBean;
49
import javax.management.MBeanServerConnection;
50
import javax.management.remote.JMXConnector;
51
import javax.management.remote.JMXConnectorFactory;
52
import javax.management.remote.JMXServiceURL;
53
54
/**
55
 * Support for sampling from command line
56
 *
57
 * @author Tomas Hurka, Jaroslav Tulach
58
 *
59
 */
60
class CLISampler extends Sampler {
61
    
62
    private final ThreadMXBean threadMXBean;
63
    private final File output;
64
65
    public static void main(String... args) throws Exception {
66
        if (args.length != 2) {
67
            System.out.println("Usage: <port> <snapshot.npss>");
68
            System.out.println();
69
            System.out.println("First of all start your application with following parameters:");
70
            System.out.println("  -Dcom.sun.management.jmxremote.authenticate=false");
71
            System.out.println("  -Dcom.sun.management.jmxremote.ssl=false");
72
            System.out.println("  -Dcom.sun.management.jmxremote.port=<port>");
73
            System.out.println("Then you can start this sampler with correct port and file to write snapshot to.");
74
            System.exit(1);
75
        }
76
        if (!SamplesOutputStream.isSupported()) {
77
            System.err.println("Sampling is not supported by JVM");
78
            System.exit(2);
79
        }
80
81
        String u = args[0];
82
        try {
83
            u = "service:jmx:rmi:///jndi/rmi://localhost:" + Integer.parseInt(args[0]) + "/jmxrmi";
84
        } catch (NumberFormatException ex) {
85
            // OK, use args[0]
86
        }
87
88
        System.err.println("Connecting to " + u);
89
        JMXServiceURL url = new JMXServiceURL(u);
90
        JMXConnector jmxc = null;
91
        Exception ex = null;
92
        for (int i = 0; i < 100; i++) {
93
            try {
94
                jmxc = JMXConnectorFactory.connect(url, null);
95
                break;
96
            } catch (IOException e) {
97
                ex = e;
98
                System.err.println("Connection failed. Will retry in 300ms.");
99
                Thread.sleep(300);
100
            }
101
        }
102
        if (jmxc == null) {
103
            ex.printStackTrace();
104
            System.err.println("Cannot connect to " + u);
105
            System.exit(3);
106
        }
107
        MBeanServerConnection server = jmxc.getMBeanServerConnection();
108
109
        final ThreadMXBean threadMXBean = ManagementFactory.newPlatformMXBeanProxy(
110
                server, ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class);
111
        final File output = new File(args[1]);
112
113
114
        CLISampler s = new CLISampler(threadMXBean, output);
115
        s.start();
116
        System.out.println("Press enter to generate sample into " + output);
117
        System.in.read();
118
        s.stop();
119
        System.out.println();
120
        System.out.println("Sample written to " + output);
121
        System.exit(0);
122
    }
123
124
    private CLISampler(ThreadMXBean threadBean, File out) {
125
        super("CLISampler");
126
        threadMXBean = threadBean;
127
        output = out;
128
    }
129
130
    @Override
131
    protected ThreadMXBean getThreadMXBean() {
132
        return threadMXBean;
133
    }
134
135
    @Override
136
    protected void saveSnapshot(byte[] arr) throws IOException {
137
        FileOutputStream os = new FileOutputStream(output);
138
        os.write(arr);
139
        os.close();
140
    }
141
142
    @Override
143
    protected void printStackTrace(Throwable ex) {
144
        ex.printStackTrace();
145
        System.exit(2);
146
    }
147
148
    @Override
149
    protected void openProgress(int steps) {
150
    }
151
152
    @Override
153
    protected void closeProgress() {
154
    }
155
156
    @Override
157
    protected void progress(int i) {
158
        System.out.print("#");
159
        System.out.flush();
160
    }
161
}
(-)a/sampler/src/org/netbeans/modules/sampler/InternalSampler.java (+214 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.sampler;
43
44
import java.awt.EventQueue;
45
import java.io.File;
46
import java.io.FileOutputStream;
47
import java.io.IOException;
48
import java.lang.management.ManagementFactory;
49
import java.lang.management.RuntimeMXBean;
50
import java.lang.management.ThreadMXBean;
51
import java.text.MessageFormat;
52
import java.util.List;
53
import java.util.logging.Level;
54
import java.util.logging.Logger;
55
import org.netbeans.api.actions.Openable;
56
import org.netbeans.api.progress.ProgressHandle;
57
import org.netbeans.api.progress.ProgressHandleFactory;
58
import org.openide.DialogDisplayer;
59
import org.openide.NotifyDescriptor;
60
import org.openide.filesystems.FileObject;
61
import org.openide.filesystems.FileUtil;
62
import org.openide.loaders.DataObject;
63
import org.openide.util.Exceptions;
64
import org.openide.util.NbBundle;
65
66
/**
67
 *
68
 * @author Tomas Hurka
69
 */
70
final class InternalSampler extends Sampler {
71
    private static final String SAVE_MSG = NbBundle.getMessage(InternalSampler.class, "SelfSamplerAction_SavedFile");  // NOI18N
72
    private static Class defaultDataObject;
73
    private static final String DEBUG_ARG = "-Xdebug"; // NOI18N
74
    private static final Logger LOGGER = Logger.getLogger(InternalSampler.class.getName());
75
    private static Boolean debugMode;
76
    private static String lastReason;
77
78
    private ProgressHandle progress;
79
    static {
80
        try {
81
            defaultDataObject = Class.forName("org.openide.loaders.DefaultDataObject"); // NOI18N
82
        } catch (ClassNotFoundException ex) {
83
            Exceptions.printStackTrace(ex);
84
        }
85
    }
86
87
    static InternalSampler getInternalSampler(String key) {
88
        if (SamplesOutputStream.isSupported() && isRunMode()) {
89
            return new InternalSampler(key);
90
        }
91
        return null;
92
    }
93
94
    private static synchronized boolean isDebugged() {
95
        if (debugMode == null) {
96
            debugMode = Boolean.FALSE;
97
98
            // check if we are debugged
99
            RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
100
            List<String> args = runtime.getInputArguments();
101
            if (args.contains(DEBUG_ARG)) {
102
                debugMode = Boolean.TRUE;
103
            }
104
        }
105
        return debugMode.booleanValue();
106
    }
107
108
    private static boolean isRunMode() {
109
        boolean runMode = true;
110
        String reason = null;
111
112
        if (isDebugged()) {
113
            reason = "running in debug mode";   // NOI18N
114
            runMode = false;
115
        }
116
        if (runMode) {
117
            // check if netbeans is profiled
118
            try {
119
                Class.forName("org.netbeans.lib.profiler.server.ProfilerServer", false, ClassLoader.getSystemClassLoader()); // NO18N
120
                reason = "running under profiler";   // NOI18N
121
                runMode = false;
122
            } catch (ClassNotFoundException ex) {
123
            }
124
        }
125
        if (!runMode && !reason.equals(lastReason)) {
126
            LOGGER.log(Level.INFO, "Slowness detector disabled - {0}", reason); // NOI18N
127
        }
128
        lastReason = reason;
129
        return runMode;
130
    }
131
    
132
    InternalSampler(String thread) {
133
        super(thread);
134
    }
135
136
    @Override
137
    protected void printStackTrace(Throwable ex) {
138
        Exceptions.printStackTrace(ex);
139
    }
140
141
    @Override
142
    protected void saveSnapshot(byte[] arr) throws IOException { // save snapshot
143
        File outFile = File.createTempFile("selfsampler", SamplesOutputStream.FILE_EXT); // NOI18N
144
        String userDir = System.getProperty("netbeans.user");
145
        File gestures = null;
146
        SelfSampleVFS fs;
147
        
148
        outFile = FileUtil.normalizeFile(outFile);
149
        writeToFile(outFile, arr);
150
        if (userDir != null) {
151
            gestures = new File(new File(new File(new File(userDir), "var"), "log"), "uigestures"); // NOI18N
152
        }
153
        if (gestures != null && gestures.exists()) {
154
            fs = new SelfSampleVFS(new String[]{"selfsampler.npss", "selfsampler.log"}, new File[]{outFile, gestures});
155
        } else {
156
            fs = new SelfSampleVFS(new String[]{"selfsampler.npss"}, new File[]{outFile});
157
        }
158
        // open snapshot
159
        FileObject fo = fs.findResource("selfsampler.npss");
160
        DataObject dobj = DataObject.find(fo);
161
        // ugly test for DefaultDataObject
162
        if (defaultDataObject.isAssignableFrom(dobj.getClass())) {
163
            String msg = MessageFormat.format(SAVE_MSG, outFile.getAbsolutePath());
164
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg));
165
        } else {
166
            dobj.getLookup().lookup(Openable.class).open();
167
        }
168
    }
169
170
    private void writeToFile(File file, byte[] arr) {
171
        try {
172
            FileOutputStream fstream = new FileOutputStream(file);
173
            fstream.write(arr);
174
            fstream.close();
175
        } catch (IOException ex) {
176
            Exceptions.printStackTrace(ex);
177
        }
178
    }
179
180
    @Override
181
    ThreadMXBean getThreadMXBean() {
182
        return ManagementFactory.getThreadMXBean();
183
    }
184
185
    @Override
186
    void openProgress(final int steps) {
187
        if (EventQueue.isDispatchThread()) {
188
            // log warnining
189
            return;
190
        }
191
        progress = ProgressHandleFactory.createHandle(NbBundle.getMessage(InternalSampler.class, "Save_Progress"));
192
        progress.start(steps);
193
    }
194
195
    @Override
196
    void closeProgress() {
197
        if (EventQueue.isDispatchThread()) {
198
            return;
199
        }
200
        progress.finish();
201
        progress = null;
202
    }
203
204
    @Override
205
    void progress(int i) {
206
        if (EventQueue.isDispatchThread()) {
207
            return;
208
        }
209
        if (progress != null) {
210
            progress.progress(i);
211
        }
212
    }
213
    
214
}
(-)a/core.ui/src/org/netbeans/core/ui/sampler/Sampler.java (-126 / +92 lines)
Lines 39-70 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
package org.netbeans.core.ui.sampler;
42
package org.netbeans.modules.sampler;
43
43
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.io.ByteArrayOutputStream;
44
import java.io.ByteArrayOutputStream;
47
import java.io.DataOutputStream;
45
import java.io.DataOutputStream;
48
import java.io.File;
49
import java.io.FileOutputStream;
50
import java.io.IOException;
46
import java.io.IOException;
51
import java.lang.management.ManagementFactory;
52
import java.lang.management.ThreadInfo;
47
import java.lang.management.ThreadInfo;
53
import java.lang.management.ThreadMXBean;
48
import java.lang.management.ThreadMXBean;
54
import java.util.Timer;
49
import java.util.Timer;
55
import java.util.TimerTask;
50
import java.util.TimerTask;
56
import java.util.logging.Level;
51
import java.util.logging.Level;
57
import java.util.logging.Logger;
52
import java.util.logging.Logger;
58
import javax.management.MBeanServerConnection;
53
import javax.swing.SwingUtilities;
59
import javax.management.remote.JMXConnector;
54
import org.netbeans.api.annotations.common.CheckForNull;
60
import javax.management.remote.JMXConnectorFactory;
55
import org.netbeans.api.annotations.common.NonNull;
61
import javax.management.remote.JMXServiceURL;
62
56
63
/**
57
/**
64
 *
58
 * Sampler class provides API for self-sampling of NetBeans
59
 * platform application. The self-sampling should be used for
60
 * diagnostic purposes and should help NetBeans platform developers
61
 * with solving CPU related performance problems. Sampled data are
62
 * stored in NPSS file, which can be opened by NetBeans Profiler or
63
 * Java VisualVM for later analysis of sampled data.
64
 * 
65
 * @author Jaroslav Bachorik, Tomas Hurka, Jaroslav Tulach
65
 * @author Jaroslav Bachorik, Tomas Hurka, Jaroslav Tulach
66
 */
66
 */
67
abstract class Sampler implements Runnable, ActionListener {
67
public abstract class Sampler {
68
    private static final int SAMPLER_RATE = 10;
68
    private static final int SAMPLER_RATE = 10;
69
    private static final double MAX_AVERAGE = SAMPLER_RATE * 3;
69
    private static final double MAX_AVERAGE = SAMPLER_RATE * 3;
70
    private static final double MAX_STDDEVIATION = SAMPLER_RATE * 4;
70
    private static final double MAX_STDDEVIATION = SAMPLER_RATE * 4;
Lines 87-92 Link Here
87
    private volatile boolean stopped;
87
    private volatile boolean stopped;
88
    private volatile boolean running;
88
    private volatile boolean running;
89
89
90
    /**
91
     * Factory method for creating Sampler suitable for automatic reporting
92
     * of the slow operation (i.e. AWT blocked for some time). This method can
93
     * return <code>null</code> if the sampled application is in nonstandard mode
94
     * which will produce unrealistic data - for example application is  
95
     * running under debugger or profiler. 
96
     * @param name which identifies the sampler thread
97
     * @return instance of the {@link Sampler} or <code>null</code> if application
98
     * is in nonstandard mode.
99
     */
100
    public static @CheckForNull Sampler getSampler(@NonNull String name) {
101
        return InternalSampler.getInternalSampler(name);
102
    }
103
    
104
    /**
105
     * Factory method for creating Sampler suitable for manual or user invoked
106
     * scanning. This method can return <code>null</code> if it is running on 
107
     * some exotic variant of JDK, where sampling is not supported.
108
     * @param name which identifies the sampler thread 
109
     * @return instance of the {@link Sampler} or <code>null</code> if sampling 
110
     * is not supported.
111
     */
112
    public static @CheckForNull Sampler getGenericSampler(@NonNull String name) {
113
        if (SamplesOutputStream.isSupported()) {
114
            return new InternalSampler(name);
115
        }
116
        return null;
117
    }
118
    
90
    Sampler(String n) {
119
    Sampler(String n) {
91
        name = n;
120
        name = n;
92
    }
121
    }
Lines 94-118 Link Here
94
    /** Returns the bean to use for sampling.
123
    /** Returns the bean to use for sampling.
95
     * @return instance of the bean to take thread dumps from
124
     * @return instance of the bean to take thread dumps from
96
     */
125
     */
97
    protected abstract ThreadMXBean getThreadMXBean();
126
    abstract ThreadMXBean getThreadMXBean();
98
127
99
    /** Allows subclasses to handle created snapshot
128
    /** Allows subclasses to handle created snapshot
100
     * @param arr the content of the snapshot
129
     * @param arr the content of the snapshot
101
     * @throws IOException thrown in case of I/O error
130
     * @throws IOException thrown in case of I/O error
102
     */
131
     */
103
    protected abstract void saveSnapshot(byte[] arr) throws IOException;
132
    abstract void saveSnapshot(byte[] arr) throws IOException;
104
    
133
    
105
    /** How to report an exception.
134
    /** How to report an exception.
106
     * 
135
     * 
107
     * @param ex exception
136
     * @param ex exception
108
     */
137
     */
109
    protected abstract void printStackTrace(Throwable ex);
138
    abstract void printStackTrace(Throwable ex);
110
    
139
    
111
    /** Methods for displaying progress.
140
    /** Methods for displaying progress.
112
     */
141
     */
113
    protected abstract void openProgress(int steps);
142
    abstract void openProgress(int steps);
114
    protected abstract void closeProgress();
143
    abstract void closeProgress();
115
    protected abstract void progress(int i);
144
    abstract void progress(int i);
116
    
145
    
117
    private void updateStats(long timestamp) {
146
    private void updateStats(long timestamp) {
118
        if (laststamp != 0) {
147
        if (laststamp != 0) {
Lines 129-137 Link Here
129
        laststamp = timestamp;
158
        laststamp = timestamp;
130
    }
159
    }
131
160
132
    @Override
161
    /**
133
    public synchronized void run() {
162
     * Start self-sampling. This method starts timer identified by <code>name</code>
134
        assert !running;
163
     * for actual sampling and returns immediately.
164
     */
165
    public synchronized void start() {
166
        if (running) throw new IllegalStateException("sampling is already running");    // NOI18N
167
        if (stopped) throw new IllegalStateException("it is not possible to restart sampling");   // NOI18N
135
        running = true;
168
        running = true;
136
        final ThreadMXBean threadBean = getThreadMXBean();
169
        final ThreadMXBean threadBean = getThreadMXBean();
137
        out = new ByteArrayOutputStream(64 * 1024);
170
        out = new ByteArrayOutputStream(64 * 1024);
Lines 165-185 Link Here
165
        }, SAMPLER_RATE, SAMPLER_RATE);
198
        }, SAMPLER_RATE, SAMPLER_RATE);
166
    }
199
    }
167
200
168
    @Override
201
    /**
169
    public synchronized void actionPerformed(ActionEvent e) {
202
     * Cancels the self-sampling. All sampled data are discarded.
203
     */
204
    public void cancel() {
205
        stopSampling(true, null);
206
    }
207
    
208
    /**
209
     * Stop the self-sampling started by {@link #start()} method and writes the data to 
210
     * {@link DataOutputStream}. If the internal sampling logic detects that
211
     * the data are distorted for example due to heavy system I/O, collected 
212
     * samples are discarded and nothing is written to {@link DataOutputStream}.
213
     * <br>
214
     * This method can take a long time and should not be invoked from EDT.
215
     * @param dos {@link DataOutputStream} where sampled data is written to.
216
     */
217
    public void stopAndWriteTo(@NonNull DataOutputStream dos) {
218
        stopSampling(false, dos);
219
    }
220
    
221
    /**
222
     * Stop the self-sampling, save and open gathered data. If there is no
223
     * sampled data, this method does nothing and returns immediately.
224
     * <br>
225
     * This method can take a long time and should not be invoked from EDT.
226
     */
227
    public void stop() {
228
        stopSampling(false, null);
229
    }
230
    
231
    private synchronized void stopSampling(boolean cancel, DataOutputStream dos) {
170
        try {
232
        try {
171
            assert running;
233
            if (!running) throw new IllegalStateException("sampling was not started"); // NOI18N
172
            assert !stopped;
234
            if (stopped) throw new IllegalStateException("sampling is not running");    // NOI18N
173
            stopped = true;
235
            stopped = true;
174
            timer.cancel();
236
            timer.cancel();
175
            if ("cancel".equals(e.getActionCommand()) || samples < 1) {     // NOi18N
237
            if (cancel || samples < 1) {
176
                return;
238
                return;
177
            }
239
            }
240
            if (SwingUtilities.isEventDispatchThread()) throw new IllegalStateException("sampling cannot be stopped from EDT");
178
            double average = sum / samples;
241
            double average = sum / samples;
179
            double std_deviation = Math.sqrt(devSquaresSum / samples);
242
            double std_deviation = Math.sqrt(devSquaresSum / samples);
180
            boolean writeCommand = "write".equals(e.getActionCommand()); // NOI18N
243
            boolean writeCommand = dos != null;
181
            if (writeCommand) {
244
            if (writeCommand) {
182
                Object[] params = new Object[]{startTime, "Samples", samples, "Average", average, "Minimum", min, "Maximum", max, "Std. deviation", std_deviation};
245
                Object[] params = new Object[]{startTime, "Samples", samples, "Average", average, "Minimum", min, "Maximum", max, "Std. deviation", std_deviation};  // NOI18N
183
                Logger.getLogger("org.netbeans.ui.performance").log(Level.CONFIG, "Snapshot statistics", params); // NOI18N
246
                Logger.getLogger("org.netbeans.ui.performance").log(Level.CONFIG, "Snapshot statistics", params); // NOI18N
184
                if (average > MAX_AVERAGE || std_deviation > MAX_STDDEVIATION || samples < MIN_SAMPLES) {
247
                if (average > MAX_AVERAGE || std_deviation > MAX_STDDEVIATION || samples < MIN_SAMPLES) {
185
                    // do not take snapshot if the sampling was not regular enough
248
                    // do not take snapshot if the sampling was not regular enough
Lines 189-195 Link Here
189
            samplesStream.close();
252
            samplesStream.close();
190
            samplesStream = null;
253
            samplesStream = null;
191
            if (writeCommand) {
254
            if (writeCommand) {
192
                DataOutputStream dos = (DataOutputStream) e.getSource();
193
                dos.write(out.toByteArray());
255
                dos.write(out.toByteArray());
194
                dos.close();
256
                dos.close();
195
                return;
257
                return;
Lines 202-302 Link Here
202
            out = null;
264
            out = null;
203
            samplesStream = null;
265
            samplesStream = null;
204
        }
266
        }
205
    }
267
    }    
206
    
207
    //
208
    // Support for sampling from command line
209
    //
210
    
211
    public static void main(String... args) throws Exception {
212
        if (args.length != 2) {
213
            System.out.println("Usage: <port> <snapshot.npss>");
214
            System.out.println();
215
            System.out.println("First of all start your application with following parameters:");
216
            System.out.println("  -Dcom.sun.management.jmxremote.authenticate=false");
217
            System.out.println("  -Dcom.sun.management.jmxremote.ssl=false");
218
            System.out.println("  -Dcom.sun.management.jmxremote.port=<port>");
219
            System.out.println("Then you can start this sampler with correct port and file to write snapshot to.");
220
            System.exit(1);
221
        }
222
        
223
        String u = args[0];
224
        try {
225
            u = "service:jmx:rmi:///jndi/rmi://localhost:" + Integer.parseInt(args[0]) + "/jmxrmi";
226
        } catch (NumberFormatException ex) {
227
            // OK, use args[0]
228
        }
229
        
230
        System.err.println("Connecting to " + u);
231
        JMXServiceURL url = new JMXServiceURL(u);
232
        JMXConnector jmxc = null;
233
        Exception ex = null;
234
        for (int i = 0; i < 100; i++) {
235
            try {
236
                jmxc = JMXConnectorFactory.connect(url, null);
237
                break;
238
            } catch (IOException e) {
239
                ex = e;
240
                System.err.println("Connection failed. Will retry in 300ms.");
241
                Thread.sleep(300);
242
            }
243
        }
244
        if (jmxc == null) {
245
            ex.printStackTrace();
246
            System.err.println("Cannot connect to " + u);
247
            System.exit(3);
248
        }
249
        MBeanServerConnection server = jmxc.getMBeanServerConnection();
250
        
251
        final ThreadMXBean threadMXBean = ManagementFactory.newPlatformMXBeanProxy(
252
            server,ManagementFactory.THREAD_MXBEAN_NAME,ThreadMXBean.class
253
        );
254
        final File output = new File(args[1]);
255
        class CLISampler extends Sampler {
256
            CLISampler() {
257
                super("");
258
            }
259
            
260
            @Override
261
            protected ThreadMXBean getThreadMXBean() {
262
                return threadMXBean;
263
            }
264
265
            @Override
266
            protected void saveSnapshot(byte[] arr) throws IOException {
267
                FileOutputStream os = new FileOutputStream(output);
268
                os.write(arr);
269
                os.close();
270
            }
271
272
            @Override
273
            protected void printStackTrace(Throwable ex) {
274
                ex.printStackTrace();
275
                System.exit(2);
276
            }
277
278
            @Override
279
            protected void openProgress(int steps) {
280
            }
281
282
            @Override
283
            protected void closeProgress() {
284
            }
285
286
            @Override
287
            protected void progress(int i) {
288
                System.out.print("#");
289
                System.out.flush();
290
            }
291
        }
292
        
293
        CLISampler s = new CLISampler();
294
        s.run();
295
        System.out.println("Press enter to generate sample into " + output);
296
        System.in.read();
297
        s.actionPerformed(new ActionEvent(s, 0, ""));
298
        System.out.println();
299
        System.out.println("Sample written to " + output);
300
        System.exit(0);
301
    }
302
}
268
}
(-)a/core.ui/src/org/netbeans/core/ui/sampler/SamplesOutputStream.java (-7 / +7 lines)
Lines 40-46 Link Here
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.netbeans.core.ui.sampler;
43
package org.netbeans.modules.sampler;
44
44
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.io.ObjectOutputStream;
46
import java.io.ObjectOutputStream;
Lines 64-77 Link Here
64
 *
64
 *
65
 * @author Tomas Hurka
65
 * @author Tomas Hurka
66
 */
66
 */
67
public class SamplesOutputStream {
67
class SamplesOutputStream {
68
68
69
    private static final String[][] methods = new String[][]{
69
    private static final String[][] methods = new String[][]{
70
        {"sun.management.ThreadInfoCompositeData", "toCompositeData"}, // NOI18N Sun JVM
70
        {"sun.management.ThreadInfoCompositeData", "toCompositeData"}, // NOI18N Sun JVM
71
        {"com.ibm.lang.management.ManagementUtils", "toThreadInfoCompositeData"} // NOI18N IBM J9
71
        {"com.ibm.lang.management.ManagementUtils", "toThreadInfoCompositeData"} // NOI18N IBM J9
72
    };
72
    };
73
    static final String ID = "NPSS"; // NetBeans Profiler samples stream
73
    static final String ID = "NPSS"; // NetBeans Profiler samples stream
74
    static final String FILE_EXT = ".npss"; // NOI18N
74
    public static final String FILE_EXT = ".npss"; // NOI18N
75
    static final int RESET_THRESHOLD = 5000;
75
    static final int RESET_THRESHOLD = 5000;
76
    static final int STEPS = 1000;
76
    static final int STEPS = 1000;
77
    static byte version = 2;
77
    static byte version = 2;
Lines 101-111 Link Here
101
    int maxSamples;
101
    int maxSamples;
102
    int offset;
102
    int offset;
103
103
104
    static boolean isSupported() {
104
    public static boolean isSupported() {
105
        return toCompositeDataMethod != null;
105
        return toCompositeDataMethod != null;
106
    }
106
    }
107
107
108
    public SamplesOutputStream(OutputStream os, Sampler progress, int max) throws IOException {
108
    SamplesOutputStream(OutputStream os, Sampler progress, int max) throws IOException {
109
        maxSamples = max;
109
        maxSamples = max;
110
        this.progress = progress;
110
        this.progress = progress;
111
        outStream = os;
111
        outStream = os;
Lines 116-122 Link Here
116
        samples = new ArrayList(1024);
116
        samples = new ArrayList(1024);
117
    }
117
    }
118
118
119
    public void writeSample(ThreadInfo[] infos, long time, long selfThreadId) throws IOException {
119
    void writeSample(ThreadInfo[] infos, long time, long selfThreadId) throws IOException {
120
        List<Long> sameT = new ArrayList();
120
        List<Long> sameT = new ArrayList();
121
        List<ThreadInfo> newT = new ArrayList();
121
        List<ThreadInfo> newT = new ArrayList();
122
        List<Long> tids = new ArrayList();
122
        List<Long> tids = new ArrayList();
Lines 208-214 Link Here
208
        }
208
        }
209
    }
209
    }
210
210
211
    public void close() throws IOException {
211
    void close() throws IOException {
212
        steCache = null;
212
        steCache = null;
213
        GZIPOutputStream stream = new GZIPOutputStream(outStream, 64 * 1024);
213
        GZIPOutputStream stream = new GZIPOutputStream(outStream, 64 * 1024);
214
        ObjectOutputStream out = new ObjectOutputStream(stream);
214
        ObjectOutputStream out = new ObjectOutputStream(stream);
(-)a/core.ui/src/org/netbeans/core/ui/sampler/SelfSampleVFS.java (-1 / +1 lines)
Lines 40-46 Link Here
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.netbeans.core.ui.sampler;
43
package org.netbeans.modules.sampler;
44
44
45
import java.io.File;
45
import java.io.File;
46
import java.io.FileInputStream;
46
import java.io.FileInputStream;
(-)a/sampler/test/unit/src/org/netbeans/modules/sampler/CustomSamplesStream.java (+68 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.sampler;
43
44
import java.io.IOException;
45
import java.io.OutputStream;
46
import java.lang.management.ThreadInfo;
47
48
/**
49
 *
50
 * @author Tomas Hurka
51
 */
52
public class CustomSamplesStream extends SamplesOutputStream {
53
54
    public CustomSamplesStream(OutputStream os, int max) throws IOException {
55
        super(os, null, max);
56
    }
57
58
    @Override
59
    public void writeSample(ThreadInfo[] infos, long time, long selfThreadId) throws IOException {
60
        super.writeSample(infos, time, selfThreadId);
61
    }
62
    
63
    @Override
64
    public void close() throws IOException {
65
        super.close();
66
    }
67
68
}
(-)a/sampler/test/unit/src/org/netbeans/modules/sampler/SamplerTest.java (+189 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.sampler;
43
44
import java.awt.Dialog;
45
import java.io.ByteArrayOutputStream;
46
import java.io.DataOutputStream;
47
import java.io.IOException;
48
import org.junit.*;
49
import static org.junit.Assert.*;
50
import org.netbeans.junit.MockServices;
51
import org.netbeans.junit.NbTestCase;
52
import org.openide.DialogDescriptor;
53
import org.openide.DialogDisplayer;
54
import org.openide.NotifyDescriptor;
55
import org.openide.util.Exceptions;
56
57
/**
58
 *
59
 * @author Tomas Hurka
60
 */
61
public class SamplerTest {
62
63
    @BeforeClass
64
    public static void setUpClass() throws Exception {
65
        //register DialogDisplayer which "pushes" Yes option in the document save dialog
66
        MockServices.setServices(DD.class);
67
    }
68
69
    @AfterClass
70
    public static void tearDownClass() throws Exception {
71
    }
72
73
    @Before
74
    public void setUp() {
75
    }
76
    
77
    @After
78
    public void tearDown() {
79
    }
80
81
    /**
82
     * Test of getSampler method, of class Sampler.
83
     */
84
    @Test
85
    public void testGetSampler() {
86
        System.out.println("getSampler");
87
        String name = "test";
88
        Sampler result = Sampler.getSampler(name);
89
        assertNotNull(result);
90
    }
91
92
    /**
93
     * Test of getGenericSampler method, of class Sampler.
94
     */
95
    @Test
96
    public void testGetGenericSampler() {
97
        System.out.println("getGenericSampler");
98
        String name = "gentest";
99
        Sampler result = Sampler.getGenericSampler(name);
100
        assertNotNull(result);
101
    }
102
103
    /**
104
     * Test of cancel method, of class Sampler.
105
     */
106
    @Test
107
    public void testCancel() {
108
        System.out.println("cancel");
109
        Sampler instance = Sampler.getGenericSampler("cancel");
110
        instance.start();
111
        instance.cancel();
112
    }
113
114
    /**
115
     * Test of stopAndWriteTo method, of class Sampler.
116
     */
117
    @Test
118
    public void testStopAndWriteTo() throws IOException {
119
        System.out.println("stopAndWriteTo");
120
        ByteArrayOutputStream out = new ByteArrayOutputStream();
121
        DataOutputStream dos = new DataOutputStream(out);
122
        Sampler instance = Sampler.getSampler("cancel");
123
        instance.start();
124
        instance.stopAndWriteTo(dos);
125
        dos.close();
126
        // there should no data in out, since stopAndWriteTo is 
127
        // invoked immediately after start
128
        assertTrue(out.size() == 0);
129
    }
130
   /**
131
     * Test of stopAndWriteTo method, of class Sampler.
132
     */
133
    @Test
134
    public void testStopAndWriteTo1() throws IOException {
135
        System.out.println("stopAndWriteTo1");
136
        ByteArrayOutputStream out = new ByteArrayOutputStream();
137
        DataOutputStream dos = new DataOutputStream(out);
138
        Sampler instance = Sampler.getSampler("cancel");
139
        instance.start();
140
        longRunningMethod();
141
        instance.stopAndWriteTo(dos);
142
        dos.close();
143
        // make sure we have some sampling data
144
        assertTrue(out.size() > 0);
145
    }
146
147
    private void longRunningMethod() {
148
        for (int i=0; i<100;i++) {
149
            try {
150
                Thread.sleep(30);
151
            } catch (InterruptedException ex) {
152
                Exceptions.printStackTrace(ex);
153
            }
154
        }
155
    }
156
157
    /**
158
     * Test of stop method, of class Sampler.
159
     */
160
    @Test
161
    public void testStop() {
162
        System.out.println("stop");
163
        Sampler instance = Sampler.getGenericSampler("stop");
164
        DD.hasData = false;
165
        instance.start();
166
        longRunningMethod();
167
        instance.stop();
168
        assert(DD.hasData);
169
    }
170
171
    /** Our own dialog displayer.
172
     */
173
    public static final class DD extends DialogDisplayer {
174
        static boolean hasData;
175
        
176
        @Override
177
        public Dialog createDialog(DialogDescriptor descriptor) {
178
            throw new IllegalStateException ("Not implemented");
179
        }
180
        
181
        @Override
182
        public Object notify(NotifyDescriptor descriptor) {
183
           hasData = true;
184
           return null;
185
        }
186
        
187
    } // end of DD    
188
    
189
}
(-)a/core.ui/test/unit/src/org/netbeans/core/ui/sampler/SelfSampleVFSTest.java (-1 / +1 lines)
Lines 40-46 Link Here
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.netbeans.core.ui.sampler;
43
package org.netbeans.modules.sampler;
44
44
45
import java.io.File;
45
import java.io.File;
46
import java.io.FileOutputStream;
46
import java.io.FileOutputStream;

Return to bug 206859