简体   繁体   English

Java(hotspot)verbose:gc输出在运行时在应用程序和进程中的使用

[英]Java (hotspot) verbose:gc output use in application and process on runtime

Any way to hook on stdout of JVM currently running process or redirect stdout of JVM process to non file location? 有什么方法可以挂接当前正在运行的JVM的stdout或将JVM进程的stdout重定向到非文件位置?

I need verbose:gc output of JVM for my application, currently i can see this output in console but unable to store it in database or process it by any means, it invisible to running java application. 我需要为我的应用程序提供JVM的verbose:gc输出,当前我可以在控制台中看到此输出,但是无法将其存储在数据库中或以任何方式对其进行处理,对于运行Java应用程序而言,它是不可见的。

System.err System.out System.err System.out

Both are wrappers over natives, internal JVM output not passes here. 两者都是本机的包装,内部JVM输出不在此处传递。 Both can't see this output (ever if redirected or set to null, gc output shows in console). 两者都看不到此输出(即使重定向或设置为null,gc输出也会显示在控制台中)。

Writing verbose:gc to file and then reading file not valid option due performance reasons and filesystem locks, checking hotspot sources not given any way to redirect output to nonfile location via JVM launch flags. 由于性能原因和文件系统锁定,将verbose:gc写入文件,然后读取文件无效选项,检查热点源(未通过JVM启动标志将输出重定向到非文件位置)。

Also i was unable to get Process object of running JVM, there are no methods for this, also i was unable to find native that expose Process object, soo still no valid way to read this data. 我也无法获取正在运行的JVM的Process对象,对此没有任何方法,也无法找到暴露Process对象的本机,因此仍然没有有效的方式来读取此数据。

Any clues about howto read verbose:gc in runtime? 关于如何在运行时中读取verbose:gc的任何线索?

Writing verbose:gc to file and then reading file not valid option due performance reasons and filesystem locks, 由于性能原因和文件系统锁定,将verbose:gc写入文件,然后读取文件无效选项,

The cost of doing this is trivial compared to the cost of actually GCing. 与实际GC的成本相比,这样做的成本微不足道。 Unless you have a system which should never GC normally, I wouldn't worry about it. 除非您拥有一个永远不会正常进行GC的系统,否则我不会担心。 If you concern is that you can't read the file due to windows locks, you may have a problem (or you could use an OS like Linux which doesn't do this) 如果您担心由于Windows锁定而无法读取文件,则可能有问题(或者您可以使用Linux这样的操作系统,但不能执行此操作)

You should note that the GC output to a file is buffered, so it is not real time (but close enough for most use cases) 您应该注意,GC输出到文件的内容是经过缓冲的,因此它不是实时的(但对于大多数用例来说足够接近)

Reading the output programmatically is very difficult esp as it is written by a multi-threaded GC ie you get strange re-ordering of information. 以编程方式读取输出是非常困难的,尤其是因为它是由多线程GC编写的,即您会得到奇怪的信息重新排序。

I would consider getting the output of jstat which is designed to be read by a program though doesn't get as much detail. 我会考虑获取jstat的输出,该输出旨在由程序读取,尽管没有得到太多细节。

You can get information GC pause information via JMX. 您可以通过JMX获取信息GC暂停信息。 It is not as full as GC logs, but will safe you from parsing. 它不像GC日志那么完整,但是可以使您免于解析。 SJK tool is a CLI tool which could track GC events of JVM running processes. SJK工具是一个CLI工具,可以跟踪JVM运行进程的GC事件。 You could use it or use its code to build customized solution. 您可以使用它或使用其代码来构建定制的解决方案。

jstat is another option, but it exposes less information compared to JMX and its formatting rather misleading in case of CMS collector. jstat是另一种选择,但是与JMX及其格式相比,它公开的信息较少,如果使用CMS收集器,则会产生误导。

Problematically using PerfCounter API is third option ( jstat is using this internally). 有问题的使用PerfCounter API是第三种选择( jstat在内部使用它)。 See sun.management.counter.perf.PerfInstrumentation class for details. 有关详细信息,请参见sun.management.counter.perf.PerfInstrumentation类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM