---
title: "jprofiler"
author: "sjuhui"
date: "2008-04-28T19:22:46Z"
tags: ["JVM", "Linux", "Weblogic", "Windows", "应用服务器"]
slug: "jprofiler"
draft: false
lastmod: "2008-04-28T19:22:46Z"
id: 187740
url: "https://sjuhui.iteye.com/blog/187740"
---

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  
       -&gt;Next  
**2）Local or remote:**  
       The profiled application s located 选择 On a remote computer,  
      Platform of the remote computer 下拉菜单选择“Linux X86/AMD64”  
      -&gt;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 ……  
      -&gt;Next  
**8) Config synchronization:**  
      Directory for config file in the remote computer:**/opt** (远程config文件的路径)  
      同步方式：  
    Manual synchronization；copy to diretory；execute command:  
      提供三种同步方式，这里我选择的是第一个手工同步。  
     -&gt;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.

      这里的黑体文字部分要保存下来，在服务器端安装时会用到。  
      -&gt;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上传到服务器上，路径为一.8)中配置的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](http://%5bhostname%5d/console)     *  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
JProfiler&gt; Protocol version 25  
JProfiler&gt; Using JVMPI  
JProfiler&gt; 32-bit library  
JProfiler&gt; Don't wait for frontend to connect.  
JProfiler&gt; Using config file /opt/config.xml (id: 114)  
JProfiler&gt; Listening on port: 8849.  
\[Full GC 114K-&gt;84K(520256K), 0.0063330 secs]  
JProfiler&gt; Native library initialized  
JProfiler&gt; If output stops here, please remove -Xdebug from the command line  
JProfiler&gt; Using dynamic instrumentation  
JProfiler&gt; Time measurement: elapsed time  
JProfiler&gt; CPU profiling enabled  
JProfiler&gt; Hotspot compiler enabled  
JProfiler&gt; Starting weblogic/Server ...

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

启动本机的刚才配置好的Session，开始连接……进入监控界面。