pinpoint 文档_跟踪源码一步步解密Pinpoint插件加载过程

本文详细介绍了Pinpoint Agent的启动流程,从JVM启动到Pinpoint Agent加载plugins目录下的插件,再到通过Guice框架自动装配依赖,实现插件的注册和类的字节码修改。当目标应用启动,每次类加载时,Pinpoint Agent查找并调用已注册的ClassTransformListener,由其修改字节码并在方法调用时触发拦截器,记录追踪数据。插件开发关键在于选择合适的拦截方法并注入拦截器。文中还提及了Pinpoint的官方文档和插件定制参考实现。
摘要由CSDN通过智能技术生成
我们知道pinpoint插件是通过字节码注入的方式工作的,但是插件究竟是如何被加载的呢?官方文档中给出的执行过程描述如何:

ProfilerPlugin works in the order of following steps:

  1. Pinpoint Agent is started when the JVM starts.

  2. Pinpoint Agent loads all plugins under plugin directory.

  3. Pinpoint Agent invokes ProfilerPlugin.setup(ProfilerPluginSetupContext) for each loaded plugin.

  4. In the setup method, the plugin registers a TransformerCallback to all classes that are going to be transformed.

  5. Target application starts.

  6. Every time a class is loaded, Pinpoint Agent looks for the TransformerCallback registered to the class.

  7. If a TransformerCallback is registered, the Agent invokes it’s doInTransform method.

  8. TransformerCallback modifies the target class’ byte code. (e.g. add interceptors, add fields, etc.)

  9. The modified byte code is returned to the JVM, and the class is loaded with the returned byte code.

  10. Application continues running.

  11. When a modified method is invoked, the injected interceptor’s before and after methods are invoked.

  12. The interceptor records the trace data.

The most important points to consider when writing a plugin are 1) figuring out which methods are interesting enough to warrant tracing, and 2) injecting interceptors to actually trace these methods. These interceptors are used to extract, store, and pass trace data around before they are sent off to the Collector. Interceptors may even cooperate with each other, sharing context between them. Plugins may also aid in tracing by adding getters or even custom fields to the target class so that the interceptors may access them during execution. Pinpoint plugin sample shows you how the TransformerCallback modifies classes and what the injected interceptors do to trace a method.

熟悉pinpoint插件机制的同学对以上过程应该很熟悉了。小编今天想带大家学习的是为什么pinpoint的插件会生效?pinpoint agent加载机制是什么样的呢?

首先我们先来回顾下java agent机制。Agent分为两种,一种是在主程序之前运行的Agent(premain),一种是在主程序之后运行的Agent(agentmain),第二种方式可以理解为前者的升级版,jdk1.6以后提供。这两者的区别这里就不过多介绍。 我们来看下pinpoint-bootstrap-2.0.2.jar包中的MANIFEST.MF中是如何定义的:
Manifest-Version: 1.0Implementation-Title: pinpoint-bootstrapImplementation-Version: 2.0.2Built-By: irteamC
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值