V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
linxiaoziruo
V2EX  ›  Java

类 jprofiler 是怎么在 jvm 运行时获得 jvm 相关信息的

  •  
  •   linxiaoziruo · 2020-11-10 11:11:40 +08:00 · 1193 次点击
    这是一个创建于 1262 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Jvm 启动的时候可以通过启动参数加载 agent 相关代码,从而获得 JVM 相关信息。 但是我看到 jprofiler 可以用 attach 的方式,在 jvm 运行的时候获得 Jvm 相关信息。这是怎么实现的,怎么实现这种无侵入式的获得 JVM 相关信息的?

    senninha
        1
    senninha  
       2020-11-10 12:11:26 +08:00
    另起一个普通的 Jvm 进程,获取目标进程的 pid,传入 agent jar 的路径,目标进程就会 load 进定制的 agnet jar 包。
    ```
    VirtualMachine vm = VirtualMachine.attach(pid);
    try {
    vm.loadAgent(agentPath, agentServerPath);
    } finally {
    vm.detach();
    }
    ```
    fantastM
        2
    fantastM  
       2020-11-10 14:59:30 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1270 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:02 · PVG 02:02 · LAX 11:02 · JFK 14:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.