Easy Profiling Point Insertion

One really excellent feature of NetBeans IDE is its Profiler. What's especially cool is that you can analyze code fragments, that is, you can right-click in a Java file and then choose Profiling | Insert Profiling Point. When you do that, you're able to analyze code fragments, i.e., from one statement to another statement, e.g., how long a particular piece of code takes to execute:

https://netbeans.org/kb/docs/java/profiler-profilingpoints.html

However, right-clicking a Java file and then going all the way down a longish list of menu items, to find "Profiling", and then "Insert Profiling Point" is a lot less easy than right-clicking in the sidebar (known as the glyph gutter) and then setting a profiling point in exactly the same way as a breakpoint:

That's much easier and more intuitive and makes it far more likely that I'll use the Profiler at all. Once profiling points have been set then, as always, another menu item is added for managing the profiling point:

To achieve this, I added the following to the "layer.xml" file:

<folder name="Editors">
    <folder name="AnnotationTypes">
        <file name="profiler.xml" url="profiler.xml"/>
        <folder name="ProfilerActions">
            <file name="org-netbeans-modules-profiler-ppoints-ui-InsertProfilingPointAction.shadow">
             <attr name="originalFile" 
             stringvalue="Actions/Profile/org-netbeans-modules-profiler-ppoints-ui-InsertProfilingPointAction.instance"/>
             <attr name="position" intvalue="300"/>
            </file>
        </folder>
    </folder>
</folder>

Notice that a "profiler.xml" file is referred to in the above, in the same location as where the "layer.xml" file is found. Here is the content:

<!DOCTYPE type PUBLIC '-//NetBeans//DTD annotation type 1.1//EN' 
'http://www.netbeans.org/dtds/annotation-type-1_1.dtd'>

<type 
	name='editor-profiler'
	description_key='HINT_PROFILER'
	localizing_bundle='org.netbeans.eppi.Bundle'
	visible='true' 
	type='line'
        actions='ProfilerActions'
        severity='ok'
        browseable='false'/>

Only disadvantage is that this registers the profiling point insertion in the glyph gutter for all file types. But that's true for the debugger too, i.e., there's no MIME type specific glyph gutter, instead, it is shared by all MIME types. Little bit confusing that the profiler point insertion can now, in theory, be set for all MIME types, but that's also true for the debugger, even though it doesn't apply to all MIME types. That probably explains why the profiling point insertion can only be done, officially, from the right-click popup menu of Java files, i.e., the developers wanted to avoid confusion and make it available to Java files only. However, I think that, since I'm already aware that I can't set the Java debugger in an HTML file, I'm also aware that the Java profiler can't be set that way as well.

If you find this useful too, you can download and install the NBM from here:

http://plugins.netbeans.org/plugin/55002

A small bonus tip: how to cause the New Profiling Point dialog to appear in the same way as a breakpoint is set, i.e., by simply clicking in the glyph gutter on a particular line:

@ActionID(
        category = "Tools",
        id = "org.netbeans.eppi.GutterPPI"
)
@ActionRegistration(
        displayName = "Unused")
@ActionReference(
        path = "Editors/text/x-java/GlyphGutterActions", 
        position = 400)
public final class GutterPPI extends AbstractAction {
    public GutterPPI() {
        putValue("default-action", true);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        FileUtil.getConfigObject(
           "Actions/Profile/org-netbeans-modules-profiler-ppoints-ui-InsertProfilingPointAction.instance", 
           Action.class).actionPerformed(e);
    }
}

For details on the above trick:

https://netbeans.org/bugzilla/show_bug.cgi?id=105746

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« September 2015
SunMonTueWedThuFriSat
  
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today