Bug 200771 - Profiling equivalent of jpda.listen=maven for jetty:run &c.
Profiling equivalent of jpda.listen=maven for jetty:run &c.
Status: RESOLVED INCOMPLETE
Product: profiler
Classification: Unclassified
Component: Ide
7.0.1
All All
: P3 (vote)
: TBD
Assigned To: issues@profiler
issues@profiler
jdk_bug_7077929
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-08-08 21:02 UTC by _ gtzabari
Modified: 2013-04-29 13:52 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ gtzabari 2011-08-08 21:02:06 UTC
I believe this issue has more to do with Maven than the Jetty web container. Feel free to reassign if you disagree.

1. I managed to successfully debug a Maven project using Jetty by changing the goal to: "jetty:run" and adding "jpda.listen=maven" to the Action properties.
2. When I attempted to do the same for the "Profile Project" action the project runs, a breakpoint is hit but Netbeans remains "Connecting to the target VM..."

I tried adding "-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}" to MAVEN_OPTS but this didn't help either.

What do I need to get this to work? Perhaps there is something wrong with "jetty:run"'s fork mode?
Comment 1 Jesse Glick 2011-08-10 20:47:35 UTC
jpda.listen=maven is a special mode distinct from regular application debugging; it allows you to debug the Maven process itself, useful for debugging mojos, and also for plugins like Jetty or Surefire which can run your code in the same JVM as Maven if you really want them to.

There is no equivalent for profiling. It could be added, but in the meantime it should be easy to do what you want: just run your app without doing anything special, then Profile > Attach Profiler to connect to it. (If it is running in a web container, none of your app's code should be run during startup so there is no rush to connect.)
Comment 2 _ gtzabari 2011-08-10 23:35:26 UTC
Actually in my case, something does run right at startup. Is there a way to make the application wait for the JPDA connection to establish before launching?
Comment 3 Jesse Glick 2011-08-11 14:02:58 UTC
(In reply to comment #2)
> Is there a way to
> make the application wait for the JPDA connection to establish before
> launching?

It does so already, but then immediately proceeds with running the app. If you want to step through startup code, the easiest thing would be to set a breakpoint in some method of interest you expect to run during startup, then run with jpda.listen=maven. The debugger will pause when that line is encountered.

The IDE does not pass suspend=n, and according to docs suspend=y is the default, but this does not seem to work. Passing it manually from the command line (with server=y thus attaching manually from the IDE) has no apparent effect either.

It is however possible to use jpda.stopclass=org.apache.maven.cli.MavenCli which will start listening from the IDE, launch Maven in the debugger, and cause the launched process to immediately suspend in MavenCli.<clinit>. I am not sure this is really any better than just setting a breakpoint somewhere "interesting".


You said "JPDA" so I responded to that, not profiling. If you want to pause a Maven build during launch so as to attach the profiler, I do not know of any straightforward technique; there is no apparent Maven option that would pause it at startup, or read from stdin. Perhaps you could run the app under JPDA and *also* attach the profiler, though the results might then be skewed. You could write a simple mojo which just paused for a few seconds or until a prompt on stdin was answered; I know archetype:generate does so, as does nbm:populate-repository, but neither is convenient. This mojo does it:

package pausemojo;
/**
 * @goal pause
 * @phase validate
 */
public class PauseMojo extends org.apache.maven.plugin.AbstractMojo {
    @Override public void execute() throws org.apache.maven.plugin.MojoExecutionException {
        System.out.print("Press ENTER to continue:");
        try {
            System.in.read();
        } catch (java.io.IOException x) {
            throw new org.apache.maven.plugin.MojoExecutionException("pausing", x);
        }
    }
}

built using:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>pausemojo</artifactId>
    <packaging>maven-plugin</packaging>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>2.0</version>
        </dependency>
    </dependencies>
</project>

and used via:

<plugin>
    <groupId>test</groupId>
    <artifactId>pausemojo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <executions>
        <execution>
            <goals>
                <goal>pause</goal>
            </goals>
        </execution>
    </executions>
</plugin>

though I am getting a JVM crash after this which I will report.
Comment 4 Milos Kleint 2013-04-29 12:02:20 UTC
I'm a bit lost here.

Are you trying to debug or profile the jetty:run execution? jpda.listen property is only available for debugging. For profiling, you only can attach profiler to your application (in this case maven build). I suppose [1] is applicable here even though quite old.

If you are looking for an equivalent of of jpda.listen=maven for profiling, named eg. profile.maven=true or profile.app=maven, then it's likely a task for maintainer of the maven.profiler module. It's unclear to me how the application execution gets passed the right parameters at startup to let profiler attach. nothing relevant in maven.profiler module that I could find.



[1] http://profiler.netbeans.org/docs/help/5.5/attach.html
Comment 5 Tomas Hurka 2013-04-29 12:13:39 UTC
Marking as incomplete until it is clear what is the problem.
Comment 6 _ gtzabari 2013-04-29 12:54:04 UTC
Milos,

I am asking for a way to have the application pause on startup until the profiler finishes attaching, at which point it should resume execution.
Comment 7 Tomas Hurka 2013-04-29 13:44:25 UTC
(In reply to comment #6)
> Milos,
> 
> I am asking for a way to have the application pause on startup until the
> profiler finishes attaching, at which point it should resume execution.
This is exactly the way, how the local attach works.
Comment 8 Milos Kleint 2013-04-29 13:52:19 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > Milos,
> > 
> > I am asking for a way to have the application pause on startup until the
> > profiler finishes attaching, at which point it should resume execution.
> This is exactly the way, how the local attach works.

Is it? for any user edited value of Profile action or only for the limited set of default behaviours? (run main class via exec:exec, tests via surefire:test, webapp deploy via netbeans's own deployment...)
At least there's a hardcoded limitation on packaging types supported that I know of.

The requirement here is to profile the maven build itself which I believe is not supported currently.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo