简体   繁体   English

Java Profilers如何在内部工作?

[英]How do Java profilers work, internally?

I'm in the process of investigating how profilers work internally. 我正在调查剖析器如何在内部工作。

It seems there is an old API named JVMPI , as well as a "new" API based on java.lang.instrument . 似乎有一个名为JVMPI的旧API,以及一个基于java.lang.instrument的“新”API。 I had the idea that profilers instrument all the classes' bytecode and insert hooks that call via sockets info to a given program's open-point, so establishing a communication with the profiler. 我有这样的想法,即分析器检测所有类的字节码并插入通过套接字信息调用的钩子到给定程序的开放点,因此建立与分析器的通信。 Is this the standard approach? 这是标准方法吗? Do they differ considerably in approach? 它们在方法上有很大不同吗?

Thanks 谢谢

For reference, " JVM TI was introduced at JDK 5.0. JVM TI replaces the Java Virtual Machine Profiler Interface (JVMPI) and the Java Virtual Machine Debug Interface (JVMDI)." 作为参考,“ JVM TI是在JDK 5.0中引入的.JVM TI取代了Java虚拟机概要分析器接口(JVMPI)和Java虚拟机调试接口(JVMDI)。” The standard profiler, jvisualvm , uses the API extensively, for example to perform and monitor garbage collection, as suggested here . 标准分析器jvisualvm广泛使用API​​,例如执行和监视垃圾收集,如此处所示 Java Management Extensions (JMX) is the common communications layer. Java Management Extensions (JMX)是常见的通信层。

I'm not an expert on this, but it seems that JVMPI and JVMTI work differently. 我不是这方面的专家,但似乎JVMPI和JVMTI的工作方式不同。

  • JVMPI seems to work by the agent processing "events" that the JVM emits when profiling is enabled. JVMPI似乎通过代理处理JVM在启用性能分析时发出的“事件”。 It seems the event emitting logic is built into the JVM. 似乎事件发射逻辑内置于JVM中。

  • JVMTI seems to work (for profiling) by having the agent inject bytecodes into the methods as they are loaded. JVMTI似乎可以通过让代理在加载方法时将字节码注入方法来工作(用于分析)。

(This is from a brief read of the respective specs, as linked above.) (这是对上述相关规范的简要介绍。)

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

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