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

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

  •  
  •   linxiaoziruo · 2020 年 11 月 10 日 · 1547 次点击
    这是一个创建于 1907 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    senninha
        1
    senninha  
       2020 年 11 月 10 日
    另起一个普通的 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 日
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   4847 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 06:22 · PVG 14:22 · LAX 22:22 · JFK 01:22
    ♥ Do have faith in what you're doing.