简体   繁体   English

使用JVMTI测量Java的执行时间

[英]Measure execution time of Java with JVMTI

For the profiler which I implement using JVMTI I would like to start measuring the execution time of all Java methods. 对于我使用JVMTI实现的探查器,我想开始衡量所有Java方法的执行时间。 The JVMTI offers the events: JVMTI提供以下事件:

  • MethodEntry
  • MethodExit

So this would be quite easy to implement, however I came across this note in the API: 因此,这很容易实现,但是我在API中遇到了此注释

Enabling method entry or exit events will significantly degrade performance on many platforms and is thus not advised for performance critical usage (such as profiling). 启用方法进入或退出事件将显着降低许多平台上的性能,因此建议不要将其用于对性能有严格要求的应用程序(如性能分析)。 Bytecode instrumentation should be used in these cases. 在这些情况下,应使用字节码检测。

But my profiling agent works headless, which means the collected data is serialized and sent via socket to a server application displaying the results. 但是我的性能分析代理没有头绪,这意味着收集的数据将被序列化并通过套接字发送到显示结果的服务器应用程序。 How should I realize this using byte code instrumentation. 我应该如何使用字节码工具实现这一点。 I am kind of confused how to go on from here. 我对如何从这里继续感到困惑。 Could someone explain to me, if I have to switch the strategy or how can I approach this problem? 有人可以向我解释一下,如果我必须改变策略,或者如何解决这个问题?

I don't know about the Sun JVM but the IBM JVM goes into what we call FullSpeedDebug mode when you request the MethodEntry/Exit events.... FSD slows down execution quite a bit. 我不了解Sun JVM,但是当您请求MethodEntry / Exit事件时,IBM JVM进入了我们所谓的FullSpeedDebug模式。...FSD大大降低了执行速度。

As you say you can use BCI as my profiler does but unless you are selective about which methods you instrument you will also see a slow down. 就像您说的那样,您可以像我的探查器一样使用BCI,但是除非您有选择地选择使用哪种方法,否则还会看到速度变慢。 For example my profiler inserts a if(profiling) callProfilerHook() on every entry and all of the possible exits in a method all object creates and some other areas as well.... These additional checks can slow down execution by over 50%... 例如,我的探查器在每个条目和所有对象创建的方法以及其他一些区域的所有可能的出口上插入if(profiling)callProfilerHook(),...这些额外的检查可能会使执行速度降低50%以上。 ..

As for how to BCI... well I wrote my own C library to do it... it's technically not hard (hint just delete the StackMapTable) but I may take you a while.. Alternatively you can use ASM et. 至于如何BCI ...好吧,我写了我自己的C库来做...在技术上并不难(仅删除StackMapTable就可以了,但是我可能要花点时间。)或者,您也可以使用ASM等。 al.

Finally... you callBackHook will add overhead and on small methods render the reported CPU/Clock time meaningless unless you perform some sophisticated overhead calculation... even if you do this your callback code affects the shape of the processor L1 caches and the Java code becomes less efficient because it has less room.. 最终... callBackHook将增加开销,并且在小型方法上使报告的CPU /时钟时间变得毫无意义,除非您执行一些复杂的开销计算...即使执行此操作,您的回调代码也会影响处理器L1缓存和Java的形状代码的效率降低,因为它的空间较小。

My profiler basically ignores the reported times as I visualize the execution in an interesting way... I'm looking to understand the flow of all of the code, in fact in most cases what code is running (most Java projects have no idea of the millions on lines of third-party code running in their app) 当我以一种有趣的方式可视化执行时,我的探查器基本上会忽略报告的时间...我希望了解所有代码的流程,实际上在大多数情况下,正在运行什么代码(大多数Java项目都不知道在其应用中运行的数百万行第三方代码)

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

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