---
title: "使用jprofile侦查你app的性能瓶颈"
author: "C_J"
date: "2011-06-01T16:01:27Z"
tags: []
categories: ["编程语言"]
slug: "jprofile-app"
draft: false
lastmod: "2011-06-02T15:08:53Z"
id: 1067355
url: "https://c-j.iteye.com/blog/1067355"
---

题记：

    最近的工作被focus到product的performance上，用jprofile统计了下消耗CPU的情况，或者说app运行时间的大致情况。

 

**安装和集成WAS容器**

刚开始jprofile把我现有的WAS环境给弄坏了，不得不重装。

 

WAS7.0版本

jprofile6.2.3（官网有体验版本）

windows XP

jprofile主要是在JVM启动的时候加入自己的agent，这个agent监控JVM的运行情况，并默认开启8849端口给jprofile client来显示数据。

 

与WAS7.0集成步骤：把WAS中wasprofile下的server.xml配置下（一时我还没找到在哪=.=），比如我的在：E:\\Program Files\\IBM\\SDP\\runtimes\\base\_v7\\profiles\\was70profile2\\config\\cells\\yangjunDesktopNode02Cell\\nodes\\yangjunDesktopNode02\\servers\\server1\\server.xml（修改前记得备份）

 

在server.xml中找到：

 

&lt;jvmEntries xmi:id="JavaVirtualMachine\_1183121908656" verboseModeClass="false" verboseModeGarbageCollection="false" verboseModeJNI="false" runHProf="false" debugMode="true" debugArgs="-Dcom.ibm.ws.classloader.j9enabled=true -agentlib:jdwp=transport=dt\_socket,server=y,suspend=n,address=7778" genericJvmArguments="-Xquickstart -agentpath:E:\\\\PROGRA~2\\\\jprofiler6\\\\bin\\\\windows\\\\jprofilerti.dll " disableJIT="false"&gt;

 

其中红色那段是我加上去的，然后重启WAS，打开jprofile进行connect就OK了。

 

除了以上方法，jprofile提供与eclipse的integer，不过这个我没弄成。

 

**Monitor你的app**

加入需要monitor的jar和class forder到jprofile，这样才能统计出你的项目中性能瓶颈在哪个方法上，并计算出每个方法所消耗的时间，Session设置如下：

 

![](http://dl.iteye.com/upload/attachment/492174/212459cb-2eb4-393f-a220-a3dce2645d62.jpg)

 

**CPU Views结果**

 

启动Record CPU后，你看到如下结果：

 

![](http://dl.iteye.com/upload/attachment/492178/55b022d8-3bc4-3814-9135-1a35331512cb.jpg)