简体   繁体   English

新启动的JVM的方法级别分析

[英]Method level profiling of newly launched JVM

In my application, a new JVM is launched when ever a new resource is created. 在我的应用程序中,一旦创建了新资源,就会启动一个新的JVM。 I am able to profile the newly launched JVM by connecting it in yourkit. 通过在您的套件中连接新启动的JVM,我可以对其进行概要分析。

Right now I am able to connect to JVM only after it is ready and after that I am able to profile it but i want to profile the JVM methods while is is coming up ie profile the methods calls of the JVM while it is initializing. 现在,我只能在准备好之后才能连接到JVM,之后才能对其进行概要分析,但是我想在即将到来时概要分析JVM方法,即在初始化时概要分析JVM的方法调用。

Is there any way i can achieve this? 我有什么办法可以做到这一点?

Reason for this is, some methods which are only invoked during initialization are causing some problem and those can't be profiled once the JVM is created and is ready. 原因是,某些在初始化期间调用的方法会引起一些问题,一旦创建并准备好JVM,就无法对其进行概要分析。

Thanks 谢谢

If under "JVM methdos" you mean Java method which are being called on JVM initialization, then you are able to do it with yourkit. 如果在“ JVM方法”下表示在JVM初始化时正在调用的Java方法,则可以使用yourkit来执行。 You have to: 你必须:

After that you should see "early" call in YourKit UI after connection. 之后,连接后,您应该在YourKit UI中看到“早期”调用。

You want to do a remote debugging session on code that runs in the initial few seconds of your app being launched. 您想对在启动应用程序的最初几秒钟内运行的代码进行远程调试会话。

A problem that you can run into when attempting to do this is that since the code runs right in the beginning, the JVM may rush past it before you have had a chance to attach a debugger via Eclipse and set your break points. 尝试执行此操作时可能遇到的问题是,由于代码从一开始就运行,因此JVM可能会在您有机会通过Eclipse附加调试器并设置断点之前冲过它。

The solution is to setup your JVM/debugging config so that it is set to suspend at startup. 解决方案是设置JVM /调试配置,以便将其设置为在启动时挂起。

A typical way to setup remote debugging is to use the following JVM argument in the code used to launch your application so that a debugger can later attach itself to port 8000. 设置远程调试的一种典型方法是在用于启动应用程序的代码中使用以下JVM参数,以便调试器以后可以将其自身附加到端口8000。

-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -Xrunjdwp:运输= dt_socket,服务器= Y,暂停= n时,地址= 8000

Infact this is what Eclipse does when you launch an app in debug mode rather than normal mode. 实际上,这就是当您以调试模式而不是普通模式启动应用程序时Eclipse所做的事情。 It adds this line in the JVM arguments used when launching your application. 它将在启动应用程序时使用的JVM参数中添加此行。

Note the suspend=n. 注意suspend = n。 If that is set to y, the JVM will suspend on startup. 如果将其设置为y,则JVM将在启动时挂起。 It will wait for a debugger to attach to it and release it before it will proceed. 它将等待调试器附加并释放它,然后再继续进行。

So using the suspend flag, our problem is solved. 因此,使用suspend标志可以解决我们的问题。

Source: http://www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/ 来源: http : //www.onkarjoshi.com/blog/224/how-to-suspend-vm-on-startup-when-remote-debugging-your-java-app/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM