分析 Java 应用程序内存使用情况的最佳方法?

发布于 2024-07-17 08:48:17 字数 380 浏览 4 评论 0原文

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

我有一组运行命令行 java 应用程序的测试,我想向它们添加内存分析。 我看到的一种选择是将代码(可能使用第三方工具/库)添加到我的应用程序中,以提供内存快照。 另一种选择是使用第三方工具来为我管理/检测我的应用程序和 JVM(理想情况下不需要我更改代码)。 我正在考虑类似 Valgrind 但针对 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:

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?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

悲喜皆因你 2024-07-24 08:48:17

使用像 JProfiler 这样的东西,您所需要做的就是向 JVM 添加某些参数。 它使用 JVMTI。

我认为您应该阅读分析器以及它们到底能为您做什么。 我还建议阅读 JVMTI。

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

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

With something like JProfiler all you need to do is add certain parameters to the JVM. It uses 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.

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.

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.

花开浅夏 2024-07-24 08:48:17

Yourkit 也有一个非常好的分析器

Yourkit also has a pretty good profiler

绅士风度i 2024-07-24 08:48:17

您检查过

VisualVMEclipse-Callisto

Have you checked

VisualVM and Eclipse-Callisto?

神爱温柔 2024-07-24 08:48:17

一个好的起点是查看您的 JVM 是否支持“java -Xrunhprof”,因为这可以生成堆分析信息,而不会让您的场景变得更加复杂。

请参阅 http://docs.oracle.com/javase/7 /docs/technotes/samples/hprof.html

您可能会发现这足以开始。

A good place to start is to see if your JVM supports "java -Xrunhprof" as this can generate heap profiling information without making your scenario more complex.

See http://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html

You might find that enough for you for starting.

红尘作伴 2024-07-24 08:48:17

一些探查器(例如 yourkit)具有用于跟踪内存分配的 API。 这里的另一个选择是监控工具,例如 jxinsight
glassboxjamon

用于分析堆转储的Eclipse Memory Analyzer是您可以获得的最好的工具。 它是免费且开源的,因此您可以根据需要自动分析堆转储。

Several profiler's such as yourkit have API's for tracing memory allocations. Another option here are monitoring tools such as jxinsight
or glassbox or jamon

For analyzing heap dumps theEclipse Memory Analyzer is the best tool you can get. It's free and open source, so you can automate the analysis of heap dumps as much as you want.

烟酉 2024-07-24 08:48:17

我在 Eclipse 中进行开发,但我有 Netbeans 来使用其优秀的 Profiler。 与一些商业产品相比,它是有限的,但仍然足以发现大多数瓶颈

I develop in Eclipse but I have Netbeans around to use its excellent Profiler. It is limited compared to some commercial ones but still good enough for spotting most bottlenecks

阪姬 2024-07-24 08:48:17

您可以使用jrcmd,它是 JRockit JVM 附带的命令行实用程序。 如果你知道 Java 进程的 pid,你可以这样做:

JROCKIt_HOME\bin\jrcmd <pid> print_object_summary

它会给你:

31.8% 3198k    41907   -137k [C
11.9% 1196k      300     +0k [B
11.4% 1151k    49118     +6k java/lang/String
 6.1% 612k     5604     +0k java/lang/Class
 4.3% 431k     2388     +0k [I
 3.5% 353k    15097     +0k java/util/HashMap$Entry
 ...

You can use jrcmd which is a command line utility that comes with the JRockit JVM. If you know the pid of the Java process you can just do:

JROCKIt_HOME\bin\jrcmd <pid> print_object_summary

and it will give you:

31.8% 3198k    41907   -137k [C
11.9% 1196k      300     +0k [B
11.4% 1151k    49118     +6k java/lang/String
 6.1% 612k     5604     +0k java/lang/Class
 4.3% 431k     2388     +0k [I
 3.5% 353k    15097     +0k java/util/HashMap$Entry
 ...
独夜无伴 2024-07-24 08:48:17

除了上述答案之外,几年前我还喜欢使用探查器。 不知道这是否有帮助。

In addition to the above answers I also enjoyed using profiler a couple of years ago. Don't know if that helps.

怎言笑 2024-07-24 08:48:17

我推荐 dynaTrace 生产版。 分析内存应用的神奇工具。 低开销和 100% 执行的事务。

I do recommend dynaTrace production edition. Amazing tool to profile memory application. Low overhead and 100% of executed transactions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文