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 175999
Collapse All | Expand All

(-)a/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java (-32 / +101 lines)
Lines 56-61 Link Here
56
import java.awt.event.ActionListener;
56
import java.awt.event.ActionListener;
57
import java.awt.event.WindowAdapter;
57
import java.awt.event.WindowAdapter;
58
import java.awt.event.WindowEvent;
58
import java.awt.event.WindowEvent;
59
import java.io.ByteArrayOutputStream;
60
import java.io.DataOutputStream;
59
import java.io.IOException;
61
import java.io.IOException;
60
import java.util.ArrayList;
62
import java.util.ArrayList;
61
import java.util.Arrays;
63
import java.util.Arrays;
Lines 63-71 Link Here
63
import java.util.Collections;
65
import java.util.Collections;
64
import java.util.Comparator;
66
import java.util.Comparator;
65
import java.util.List;
67
import java.util.List;
68
import java.util.logging.Level;
66
import java.util.logging.Logger;
69
import java.util.logging.Logger;
67
import java.util.regex.Pattern;
70
import java.util.regex.Pattern;
68
import javax.swing.AbstractAction;
71
import javax.swing.AbstractAction;
72
import javax.swing.Action;
69
import javax.swing.DefaultListModel;
73
import javax.swing.DefaultListModel;
70
import javax.swing.JButton;
74
import javax.swing.JButton;
71
import javax.swing.ListCellRenderer;
75
import javax.swing.ListCellRenderer;
Lines 90-95 Link Here
90
import org.openide.filesystems.FileObject;
94
import org.openide.filesystems.FileObject;
91
import org.openide.filesystems.FileUtil;
95
import org.openide.filesystems.FileUtil;
92
import org.openide.nodes.Node;
96
import org.openide.nodes.Node;
97
import org.openide.util.Exceptions;
93
import org.openide.util.HelpCtx;
98
import org.openide.util.HelpCtx;
94
import org.openide.util.ImageUtilities;
99
import org.openide.util.ImageUtilities;
95
import org.openide.util.Lookup;
100
import org.openide.util.Lookup;
Lines 389-428 Link Here
389
            this.text = text;
394
            this.text = text;
390
            this.createTime = System.currentTimeMillis();
395
            this.createTime = System.currentTimeMillis();
391
            LOGGER.fine( "Worker for " + text + " - created after " + ( System.currentTimeMillis() - panel.time ) + " ms."  );                
396
            LOGGER.fine( "Worker for " + text + " - created after " + ( System.currentTimeMillis() - panel.time ) + " ms."  );                
392
       }
397
        }
393
        
398
394
        public void run() {
399
        public void run() {
395
            
400
            Profile profile = initializeProfiling();
396
            LOGGER.fine( "Worker for " + text + " - started " + ( System.currentTimeMillis() - createTime ) + " ms."  );                
401
            try {
397
            
402
                LOGGER.fine( "Worker for " + text + " - started " + ( System.currentTimeMillis() - createTime ) + " ms."  );
398
            final List<? extends TypeDescriptor> types = getTypeNames( text );
403
399
            if ( isCanceled ) {
404
                final List<? extends TypeDescriptor> types = getTypeNames( text );
400
                LOGGER.fine( "Worker for " + text + " exited after cancel " + ( System.currentTimeMillis() - createTime ) + " ms."  );                                
405
                if ( isCanceled ) {
401
                return;
406
                    LOGGER.fine( "Worker for " + text + " exited after cancel " + ( System.currentTimeMillis() - createTime ) + " ms."  );
407
                    return;
408
                }
409
                ListModel model = Models.fromList(types);
410
                if (typeFilter != null) {
411
                    model = LazyListModel.create(model, GoToTypeAction.this, 0.1, "Not computed yet");
412
                }
413
                final ListModel fmodel = model;
414
                if ( isCanceled ) {
415
                    LOGGER.fine( "Worker for " + text + " exited after cancel " + ( System.currentTimeMillis() - createTime ) + " ms."  );
416
                    return;
417
                }
418
419
                if ( !isCanceled && fmodel != null ) {
420
                    LOGGER.fine( "Worker for text " + text + " finished after " + ( System.currentTimeMillis() - createTime ) + " ms."  );
421
                    SwingUtilities.invokeLater(new Runnable() {
422
                        public void run() {
423
                            panel.setModel(fmodel);
424
                            if (okButton != null && !types.isEmpty()) {
425
                                okButton.setEnabled (true);
426
                            }
427
                        }
428
                    });
429
                }
430
            } finally {
431
                if (profile != null) {
432
                    try {
433
                        profile.stop();
434
                    } catch (Exception ex) {
435
                        LOGGER.log(Level.INFO, "Cannot stop profiling", ex);
436
                    }
437
                }
402
            }
438
            }
403
            ListModel model = Models.fromList(types);
404
            if (typeFilter != null) {
405
                model = LazyListModel.create(model, GoToTypeAction.this, 0.1, "Not computed yet");
406
            }
407
            final ListModel fmodel = model;
408
            if ( isCanceled ) {            
409
                LOGGER.fine( "Worker for " + text + " exited after cancel " + ( System.currentTimeMillis() - createTime ) + " ms."  );                                
410
                return;
411
            }
412
            
413
            if ( !isCanceled && fmodel != null ) {                
414
                LOGGER.fine( "Worker for text " + text + " finished after " + ( System.currentTimeMillis() - createTime ) + " ms."  );                
415
                SwingUtilities.invokeLater(new Runnable() {
416
                    public void run() {
417
                        panel.setModel(fmodel);
418
                        if (okButton != null && !types.isEmpty()) {
419
                            okButton.setEnabled (true);
420
                        }
421
                    }
422
                });
423
            }
424
            
425
            
426
        }
439
        }
427
        
440
        
428
        public void cancel() {
441
        public void cancel() {
Lines 716-720 Link Here
716
        return s1.compareTo( s2 );
729
        return s1.compareTo( s2 );
717
    }
730
    }
718
    
731
    
732
    private Profile initializeProfiling() {
733
        FileObject fo = FileUtil.getConfigFile("Actions/Profile/org-netbeans-modules-profiler-actions-SelfSamplerAction.instance");
734
        if (fo == null) {
735
            return null;
736
        }
737
        Action a = (Action)fo.getAttribute("delegate"); // NOI18N
738
        if (a == null) {
739
            return null;
740
        }
741
        return new Profile(a.getValue("logger-jumpto")); // NOI18N
742
    }
743
744
    private class Profile implements Runnable {
745
        Object profiler;
746
        boolean profiling;
747
        private final long time;
748
749
        public Profile(Object profiler) {
750
            time = System.currentTimeMillis();
751
            this.profiler = profiler;
752
            RequestProcessor.getDefault().post(this, 3000); // 3s
753
        }
754
755
        public synchronized void run() {
756
            profiling = true;
757
            if (profiler instanceof Runnable) {
758
                Runnable r = (Runnable)profiler;
759
                r.run();
760
            }
761
        }
762
763
        private synchronized void stop() throws Exception {
764
            long delta = System.currentTimeMillis() - time;
765
766
            ActionListener ss = (ActionListener)profiler;
767
            profiler = null;
768
            if (!profiling) {
769
                return;
770
            }
771
            try {
772
                ByteArrayOutputStream out = new ByteArrayOutputStream();
773
                DataOutputStream dos = new DataOutputStream(out);
774
                ss.actionPerformed(new ActionEvent(dos, 0, "write")); // NOI18N
775
                dos.close();
776
                if (dos.size() > 0) {
777
                    Object[] params = new Object[]{out.toByteArray(), delta };
778
                    Logger.getLogger("org.netbeans.ui.performance").log(Level.CONFIG, "Slowness detected", params);
779
                } else {
780
                    LOGGER.log(Level.WARNING, "no snapshot taken"); // NOI18N
781
                }
782
            } catch (Exception ex) {
783
                Exceptions.printStackTrace(ex);
784
            }
785
        }
786
787
    }
719
788
720
}
789
}

Return to bug 175999