`
冽豹之姿
  • 浏览: 40299 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

JProfiler

    博客分类:
  • java
阅读更多

JProfiler是一个全功能的Java剖析工具(profiler),专用于分析J2SE和J2EE应用程序。

  它把CPU、执行绪和内存的剖析组合在一个强大的应用中。JProfiler可提供许多IDE整合和应用服务器整合用途。

  JProfiler直觉式的GUI让你可以找到效能瓶颈、抓出内存漏失(memory leaks)、并解决执行绪的问题。它让你得以对heap walker作资源回收器的root analysis,可以轻易找出内存漏失;heap快照(snapshot)模式让未被参照(reference)的对象、稍微被参照的对象、或在终结(finalization)队列的对象都会被移除;整合精灵以便剖析浏览器的Java外挂功能。


JProfiler安装

WEB服务总是莫名其妙的运行一段时间后JVM直接OutOfMemory错误,这个问题一直困扰着程序的正常运行。大概半个月时间一次,上网查了些资料,也做了不少优化,什么weblogic环境变量Xms,Xmx,MaxPermSize参数调整,可问题依旧,况且这也是治标不治本,问题也许发生在程序中,可能存在内存泄露,或spring和hibernate框架相关的问题。

在网上找到个大家说很好的工具叫Jprofiler,学着弄弄,down下来个最新版本。软件需要注册,注册后有十天的试用期。现在把安装过程记下来。

由于我要监控的程序是在远程的linux系统下的weblogic服务,所以这里记录的是远程监控的配置过程。

先介绍下环境:

系统服务器:

操作系统:linux redhat

web服务器:weblogic 8.1

java虚拟机版本:1.4.2

jprofiler版本:jprofiler_linux_5_1_2.tar.gz(安装包共三个版本 sh,exe,tar.gz)

客户端:

操作系统:Windows Xp SP2

jprofiler5.1.2 for windows(安装包:jprofiler_windows_5_1_2.zip)

安装:

一.客户端安装:
1 windows下直接解压zip包,运行jprofiler5.1.2的exe安装即可。
2 运行jprofiler并进行配置
1)Quick Start:
   选择 An application on a remote computer
   ->Next
2)Local or remote:
   The profiled application s located 选择 On a remote computer,
   Platform of the remote computer 下拉菜单选择“Linux X86/AMD64”
   ->Next
3)Remote address :填写被监控应用程序所在远程计算机的IP
4)Installation directory:解压路径:/var/jprofiler5
5) choose JVM :
    JVM Vendor: Sun jvm提供商
Version:1.4.2 版本
    Mode:hotspot 系统默认
6)jprofile port :8849
7)startup mode:
   Wait for …… 为了在开发环境中获取监控的信息,它将等待远程计算机上的Jprofile GUI 启动,并和本机建立连接,这种方式比较便于修改jprofiler的配置信息。
       Don't wait for …… 不必等待远程计算机的Jprofile GUI 先启动和建立连接,立即启动。但在启动远程应用程序前必须校验当前所配置会话的配置文件。虚拟机参数将参考Jprofile 的config 文件的路径。
这里选择Don't wait for ……
   ->Next
Config synchronization:
   Directory for config file in the remote computer:/opt (远程config文件的路径)
   同步方式:
Manual synchronization;copy to diretory;execute command:
   提供三种同步方式,这里我选择的是第一个手工同步。
    ->Next
9)Perform modifications:
    Integration type: [Generic application]
    Selected JVM: Sun 1.4.2 (hotspot)
Startup mode: Don't wait for JProfiler GUI, startup immediately

    Important: The local config file C:\Documents and Settings\Jan\.jprofiler5\config.xml must be copied manually to /opt on the remote computer when the profiling settings are changed.


(1) Please insert

      -Xrunjprofiler:port=8849,nowait,id=115,config=/opt/config.xml -Xbootclasspath/a:/var/jprofiler5/bin/agent.jar

   into the start command of your remote application right after the java command.

    (2) Please add

      /var/jprofiler5/bin/linux-x86

    to the environment variable LD_LIBRARY_PATH.

   A remote session named Remote application on 10.5.31.49 will be created that connects to a running instance of the remote application that is started with the modified start command.

   这里的黑体文字部分要保存下来,在服务器端安装时会用到。
   ->Next
10) Finished:
       选No,I will start the session later
   因为我们还没有配置服务器端。

二.服务器端安装
1 将jprofiler_linux_5_1_2.tar.gz上传到服务器上,/var/下建立jprofiler5目录,并将程序解压到/opt/jprofiler5下即可
2 修改用户环境变量.bash_profile。
加入export LD_LIBRARY_PATH=/var/jprofiler5/bin/linux-x86。如果是 64 位服务器,则选择linux-x64。
运行source .bash_profile 使环境变量立即生效
3 添加weblogic启动参数
将一.9).(1)中黑体的部分加到weblogic的启动文件startWebLogic.sh的参数中如:
${JAVA_HOME}/bin/java ${JAVA_VM} ${MEM_ARGS} ${JAVA_OPTIONS} -verbosegc
-Xrunjprofiler:port=8849,nowait,id=115,config=/opt/config.xml -Xbootclasspath/a:/var/jprofiler5/bin/agent.jar
-Dweblogic.Name=${SERVER_NAME} -Dweblogic.ProductionModeEnabled=${PRODUCTION_MODE} -Djava.security.policy="${WL_HOME}/server/lib/weblogic.policy" weblogic.Server
尽量让它在一行中。
4 把 C:\Documents and Settings\Jan\.jprofiler5\ 下的config.xml上传到服务器上,路径为一.中配置的Directory for config file in the remote computer:/opt
因为这里选择的同步方式是Manual synchronization,所以以后配置发生改变时,需要手工再次上传新的config.xml到这个路径。
三.启动weblogic服务:

**************************************************
* To start WebLogic Server, use a username and *
* password assigned to an admin-level user. For *
* server administration, use the WebLogic Server *
* console at http://[hostname]:[port]/console *
***************************************************
JProfiler> Protocol version 25
JProfiler> Using JVMPI
JProfiler> 32-bit library
JProfiler> Don't wait for frontend to connect.
JProfiler> Using config file /opt/config.xml (id: 114)
JProfiler> Listening on port: 8849.
[Full GC 114K->84K(520256K), 0.0063330 secs]
JProfiler> Native library initialized
JProfiler> If output stops here, please remove -Xdebug from the command line
JProfiler> Using dynamic instrumentation
JProfiler> Time measurement: elapsed time
JProfiler> CPU profiling enabled
JProfiler> Hotspot compiler enabled
JProfiler> Starting weblogic/Server ...

<Feb 5, 2008 11:41:31 AM CST> <Info> <WebLogicServer> <BEA-000377> <Starting WebLogic Server with Java HotSpot(TM) Client VM Version 1.4.2_09-b05 from Sun Microsystems Inc.>
<Feb 5, 2008 11:41:31 AM CST> <Info> <Configuration Management> <BEA-150016> <This server is being started as the administration server.>

启动本机的刚才配置好的Session,开始连接……进入监控界面。
参考链接  http://hi.baidu.com/ryanlicool/b ... 6d2340ac34dee1.html

 

java性能监控工具JProfiler的使用

 

来源:CSDN    作者:steven    发布时间:2007-7-19    人气:64
 
 
最近公司的项目很不稳定,经常莫名其妙的down机,而且响应速度感觉也很不理想。
 
于是怀疑产生了内存泄漏问题。在网上看了关于一些测试工具的介绍,认为
JProfiler比较合适,最新版本是4.x,但是找不到破解,只找到了3.3的破解,于是下载了3.3。下载地址是:

http://www.ej-technologies.com/download/jprofiler/version3.php

网上很多关于JProfiler的介绍都是被监控的应用程序(或web应用)和Jprofiler装在同一台机器上的情况。如果一定要这样,感觉意义就不大了,因为想要监控的往往就是远程的linux服务器的web应用,而监控结果当然希望在本地windows pc上以图形界面的方式看到。在本地windows上装了jprofiler3和破解后,发现确实有remote session的选项。于是开始干活:

第一步,除了下载windows版的jprofiler3并在本地安装外,在下载一个linux版。Linux版包括rpm安装版,.sh安装版和.tar.gz压缩版,我下的是.sh版,用./jprofiler3.sh –q安装后,在linux上,jprofile被安装在了/var/jprofiler3路径下(我没改任何配置文件直接执行的安装就是这个结果,目的只是使用它所以不想花时间研究)。

第二步,本地运行图形界面的jprofiler,在菜单中选择Session->Integration Wizard->New Remote Integration,如图:

      

 

然后选择“on a remote computer”,系统选Linux X86,如图:

 

 

后面几部就不帖图了,就是傻瓜操作,问啥填啥,直到看到这一步:

 

 

这个里面的提示是根据你填的东西不同而生成的个性信息,copy下来,待会要用到,然后下一步,选“No, I will start the session later.”。

 

第三步,就要在linux服务器上进行配置了,这就需要刚才生成的个性配置信息。其中 –Xint –Xrunjprofiler:port=8849 –Xbootclasspath/a:/opt/jprofiler3/bin/agent.jar是附加的启动java程序时跟在”java”后面的命令行参数,由于我用的是tomcat,那就在tomcat的启动脚本startup.sh中的JAVA_OPTS参数中添加入这一行东西。(其实还会遇到很多细节问题导致的失败,这都是后话了,比如这些命令行参数和原先的参数可能冲突,我开始做了好多次都失败,JVM都出了bug报告,开始不知道怎么回事,耽误了很多时间,其实就是参数冲突)。还有一个个性配置信息就是要有一个叫LD_LIBRARY_PATH的环境变量,那我就修改了catalina.sh,在里面加入export LD_LIBRARY_PATH=/opt/jprofiler3/bin/linux-x86

第四步,这时候就用修改过的startup.sh启动tomcat,可以在catalina.out日志中看到提示我们远程监控程序可以连接了。

第五步,我们在本地windows pc中运行的jprofiler的菜单中选择“Session -> Open Session”,选择刚才建立的remote session,然后狂点好几个OK就行了。

如果没有问题,监控程序就运行成功了!我们就可以看到好多可爱的监控结果,比如内存堆栈的分配和使用情况、对象建立的多少情况、cpu使用的情况,还可以针对每个类或每个对象或每个线程、或每个函数对内存、cpu的使用情况,还可以看java虚拟机中自动垃圾收集的运行情况,这一切都是可爱的图形界面!还可以生成静态报告,告诉你各种线程、类、对象的调用关系、运行堆栈和每个具体单元占用的资源和时间等等,功能还是非常super的,而且好多东西还没搞懂呢,反正给我的感觉就是它能告你的东西比你想知道的还要多好多,jprofiler是个好东东。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics