本文内容节选自infoq上的此文章http://www.infoq.com/articles/java-profiling-with-open-source
If your application is experiencing unusually high memory load, frequent freezes or OOME, its often most useful to start by understanding just what kind of objects are present in memory. Luckily the JVM comes out-of-the-box with the ability to do so, with the built-in tool ‘jmap’.
JVM自带的工具jmap可以帮你理解内存现存的各种对象。
In order to run jmap, you need to know the PID of the application that you want to run jmap against. One easy way to obtain this is to use the JVM-provided tool jps, which will list out each and every JVM process running on your machine, along with each process’ PID. The output of jps will look like the following:
但在使用jmap之前,你需要先获取到该application的PID, 一个简单的方法是使用另一个jvm自带的命令jps,该命令会列出你机器上所有jvm进程,包括PID。
To print out a memory histogram, we will invoke the jmap console app passing in our application’s PID and the “-histo:live” option . So, if we wanted to retrieve a memory histogram for the “eureka.Proxy” application from the figure above, we invoke jmap as:
为了打印内存使用图,我们会使用一下命令。注:jmap 有不同的参数选项
jmap –histo:live 45417
The output of the above command might look something like the following:
原文后面还有几张图来对比在内存泄漏状况下使用jmap的情况,在此就省略啦。
Note that jmap isn’t a profiling tool, and that the JVM might halt during the histogram generation, so be sure its acceptable for your application to pause for the time it takes to generate the histogram. In my experience though, generating a histogram is something you do more often when debugging a serious bug, and so a few one minute pauses of the application is likely acceptable during such circumstances. This brings me nicely along to the next topic – the semi-automatic profiling tool VisualVM.
在使用jmap的时候,会导致你的应用暂停。根据作者的经验,一般在调试一个严重bug的情况下使用是可以接受的。下面介绍半自动的性能分析工具VisualVM.
在原文中作者只是给了个使用VisualVM的例子,并没有告知如何安装使用VisualVM,在http://visualvm.java.net/可以下载VisualVM,同时VisualVM入门指南在此http://visualvm.java.net/zh_CN/gettingstarted.html。具体的可以自己下载安装试用体验。
原文中最后一段话指出VisualVM不是一个全特性的优化工具,同时也不能一直运行于你生产环境的JVM,还不能存储获得的数据,以及不能设定警报值等。所以下面会介绍BTrace。
Understand that VisualVM is not a full-featured profiler, as its not capable of constantly running against your production JVM. It won’t persist its data, nor will it be able to specify thresholds and send alerts when these thresholds are breached. To be able to get closer to the goal of a full-featured profiler, let’s look next at BTrace, a full-featured open source Java agent.
看完了BTrace的介绍发现这个工具是需要写annotation到代码中的,同时还需要用它自带的一个编译器编译过,而且本身只输出文本,没有提供任何图形化的工具,MY GOD, 还是算了吧。
在试用VisualVM的过程中发现了一个有用的java命令,jstat - Java Virtual Machine Statistics Monitoring Tool,该命令可以查看当然jvm的一些统计信息。同使用jmap一样,先用jps获取到PID,然后使用jstat观察该PID对象的JVM信息。
例如: jstat -gc 24910
S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT
9152.0 12416.0 1464.2 0.0 92864.0 5874.1 352256.0 59318.4 65536.0 63847.1 34 1.098 0 0.000 1.098
显示的结果是GC的相关信息。每个column对应的信息如下
Column
Description
S0C |
Current survivor space 0 capacity (KB). |
S1C |
Current survivor space 1 capacity (KB). |
S0U |
Survivor space 0 utilization (KB). |
S1U |
Survivor space 1 utilization (KB). |
EC |
Current eden space capacity (KB). |
EU |
Eden space utilization (KB). |
OC |
Current old space capacity (KB). |
OU |
Old space utilization (KB). |
PC |
Current permanent space capacity (KB). |
PU |
Permanent space utilization (KB). |
YGC |
Number of young generation GC Events. |
YGCT |
Young generation garbage collection time. |
FGC |
Number of full GC events. |
FGCT |
Full garbage collection time. |
GCT |
Total garbage collection time. |
更多信息可参看此网页http://download.oracle.com/javase/6/docs/technotes/tools/share/jstat.html
分享到:
相关推荐
profiling:一个交互式 Python 性能分析工具
WPF 提供了一套性能分析工具,允许您分析应用程序的运行时行为并确定可以应用的性能优化类型。下表列出了 Windows SDK 工具 WPFPerf 中包含的五个性能分析工具: 本主题包含以下部分。 使用性能分析工具 事件追踪 ...
precise power delay profiling with commodity <PPT > mobicom2015.09
Eugene Chan (IBM Canada) Jonathan West(IBM Canada) 两个人作的TPTP平台配置步骤 英文文档
该项目的目标是使用 Java Virtual Machine Profiler Interface 开发 Java Profiling 工具。
目前市场上的 Java Profiler 工具种类繁多,本文将对目前比较常见的几种工具进行简要介绍,并从功能、性能等角度作比较,从而帮助 Java 程序员选择合适的 Java Profiler 工具。 本文主要分为三个部分:第一部分...
Deep Learning: Practical Neural Networks with Java by Yusuke Sugomori English | 8 Jun. 2017 | ASIN: B071GC77N9 | 1057 Pages | AZW3 | 20.28 MB Build and run intelligent applications by leveraging key ...
该工具正在开发高性能的集成数据管理平台,它将无缝地进行数据集成,数据分析,数据质量,数据准备,虚拟数据创建,元数据发现,异常发现,数据清理,报告和分析。 它还具有Hadoop(大数据)支持,可将文件移入...
Mysql自带profiling性能分析工具使用分享,需要的朋友可以参考下
google-perftools 是一款针对 C/C++ 程序的性能分析工具,它是一个遵守 BSD 协议的开源项目。使用该工具可以对 CPU 时间片、内存等系统资源的分配和使用进行分析,本文将重点介绍如何进行 CPU 时间片的剖析。 google...
This book is for Java developers with basic Java programming knowledge. No previous knowledge of neural networks is required as this book covers the concepts from scratch. What You Will Learn Get to ...
Using modern Java Virtual Machine (JVM) and OS observability tools to profile running systems, with almost no performance penalty Gaining “under the hood” knowledge of the Java HotSpot VM that can ...
Develop, debug, test, and troubleshoot Java EE 7 applications rapidly with Eclipse About This Book Go beyond simply learning Java EE APIs and explore the complete workflow of developing enterprise ...
Open source C++ Implementation of Customizable Route Planning (CRP) by Delling et al. This project was part of a practical course at Karlsruhe Institute of Technology (KIT). Requirements ===========...
不使用 Visual Studio 即可进行性能分析的独立命令行工具。(此下载为x64) 有关详细信息,请参阅...
Ascend Training Tools,昇腾训练工具链 针对训练&大模型场景,提供端到端...**集群分析工具**:提供多机多卡的集群分析能力(基于通信域的通信分析和迭代耗时分析), 当前需要配合Ascend Insight的集群分析功能使用。
Using modern Java Virtual Machine (JVM) and OS observability tools to profile running systems, with almost no performance penalty Gaining “under the hood” knowledge of the Java HotSpot VM that can ...
Title: Java EE 7 Performance Tuning and Optimization Author: Osama Oransa Length: 398 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2014-06-25 ISBN-10: 178217642X ...
Ø Using modern Java Virtual Machine (JVM) and OS observability tools to profile running systems, with almost no performance penalty Ø Gaining “under the hood” knowledge of the Java HotSpot VM that...
摘自:http://openjdk.java.net/projects/jdk/11/ 181: Nest-Based Access Control(基于嵌套的访问控制) 309: Dynamic Class-File ...336: Deprecate the Pack200 Tools and API(弃用 Pack200 工具及其 API)