在Java应用程序中分析内存使用情况的最佳方法? [英] Best way to profile memory usage in a Java application?

查看:112
本文介绍了在Java应用程序中分析内存使用情况的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此之前已经意识到类似的问题已经被问过了,但是让我准确描述一下我需要做什么:

I realize that similar questions have been asked about this before here on SO, but let me describe exactly what I need to do:

我有一组测试运行命令行java应用程序,我想添加内存分析。我看到的一个选项是向我的应用程序添加代码(可能使用第三方工具/库),这将提供内存快照。另一种选择是使用第三方工具来管理/检测我的应用程序和JVM(理想情况下不需要我更改我的代码)。我想的是像Valgrind这样的东西,但是对于Java来说。如果可能的话也是开源的。

I have a set of tests which run a command line java application and I'd like to add memory profiling to them. One option I see would be to add code (possibly using 3rd party tools/libraries) to my application that would provide a memory snapshot. Another option would be to use a third party tool which manages/instruments my application and the JVM for me (and ideally does not require me to change my code). I'm thinking of something like Valgrind but for Java. Also open source if at all possible.

我真正想做的是设置内存测试,以便定期监视我的内存使用情况,让我们看看说每一秒,并倾倒到一个文本文件。这样我就可以看到内存使用量是否会随着时间的推移而振荡/增加/减少。我还能够计算最大和最小峰值。

What I'd really like to do is set up the memory tests so that my memory usage is being monitored at regular intervals, let's say every second, and dumped to a text file. That way I'd be able to see if the memory usage oscillates/increases/decreases over time. I'll also be able to calculate the max and min peaks.

有人在这做过这样的事吗?

Has anyone here done anything like this?

提前致谢。

推荐答案

有了像JProfiler这样的东西你们需要做的是向JVM添加某些参数。它使用JVMTI。

With something like JProfiler all you need to do is add certain parameters to the JVM. It uses JVMTI.

我认为你应该阅读有关分析器以及他们能为你做些什么。我还建议阅读JVMTI。

I think you should be reading up on profilers and exactly what they can do for you. I also suggest reading up on JVMTI.

JVMTM工具接口(JVM TI)是一种新的本机编程接口,供工具使用。它提供了一种检查状态和控制Java虚拟机(JVM)中运行的应用程序执行的方法。 JVM TI支持需要访问JVM状态的全部工具,包括但不限于:分析,调试,监控,线程分析和覆盖率分析工具。

The JVMTM Tool Interface (JVM TI) is a new native programming interface for use by tools. It provides both a way to inspect the state and to control the execution of applications running in the Java virtual machine (JVM). JVM TI supports the full breadth of tools that need access to JVM state, including but not limited to: profiling, debugging, monitoring, thread analysis, and coverage analysis tools.

注意:JVM TI取代了Java虚拟机概要分析程序接口(JVMPI)和Java虚拟机调试接口(JVMDI)。 JVMPI和JVMDI将在J2SETM的下一个主要版本中删除。

Note: JVM TI replaces the Java Virtual Machine Profiler Interface (JVMPI) and the Java Virtual Machine Debug Interface (JVMDI). JVMPI and JVMDI will be removed in the next major release of J2SETM.

这篇关于在Java应用程序中分析内存使用情况的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆