最近我写了一些微型基准测试代码,所以我必须打印出JVM行为以及基准信息。我用如何重定向JVM输出而不撕裂应用程序的输出?
-XX:+PrintCompilation
-XX:+PrintGCDetails
和其他选项来获得JVM状态。对于基准信息,我只需使用System.out.print()
方法。因为我需要知道我打印的消息和JVM输出的顺序。
虽然JVM输出有时会撕掉我的消息,但是由于它们位于不同的线程中,所以我可以在控制台中将它们打印出来,但可以理解并且可以接受。
当我需要做一些批次的基准,我想redirect the output into a file
与pipe (> in Linux system)
,并使用Python从文件中获取结果,并进行分析。
这里的问题是:
The JVM output always overlapped with the messages I printed in the Java application.
它毁了消息的完成。
任何想法如何处理这种情况?我需要both the JVM output and application output in the same place in order to preserve the sequence because it is important. And they do not overlap on each other so I don't lose anything.
好主意,我试着在代理中重定向stdout和stderr,我可以重定向从我的java代码的输出,但JVM输出不重定向。在你提到的文章中介绍的方法 - 在加载类时修改字节码,我必须知道JVM在输出信息时调用了什么,然后我可以修改它,但是我没有那种信息,你有什么建议吗? – dawnstar