arthas icon indicating copy to clipboard operation
arthas copied to clipboard

使用trace如何查看lamda里面的调用时间

Open hjy30312 opened this issue 2 years ago • 1 comments


ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 50, 60, TimeUnit.SECONDS,
            new SynchronousQueue<>(),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.CallerRunsPolicy()
    );

@KafkaListener(topics = "writeData")
public void writeData(String message){
      executor.execute(() -> {
                 xxxxxx
                 xxxxxxx
              });
}

使用trace如何查看lamda里面的调用时间? trace writeData 不能打印内部具体的时间

hjy30312 avatar Jul 13 '22 03:07 hjy30312

同问,在调试过程中也发现了这个问题,trace 树中没有展示 lambda 表达式中的执行时间,不知道 Arthas 有没有解决方案?

public static void main(String[] args) throws IOException {
    System.in.read();
    method1();
}

private static void method1() {
    for (int i = 0; i < 100; i++) {
        Optional.ofNullable(i)
                .map(String::valueOf)
                .ifPresent(num -> {
                    try {
                        int sleep = (int) (Math.random() * 50);
                        System.out.printf("当前第%s次运行,休眠%dms%n", num, sleep);
                        TimeUnit.MILLISECONDS.sleep(sleep);
                    } catch (InterruptedException e) {
                        // do nothing
                    }
                });
    }
}

Arthas 命令

trace org.example.Main method1

执行效果: image

ghimi-g avatar Jul 14 '22 03:07 ghimi-g

jvm自身不支持增加 lambda类,arthas内部都是统一过滤掉。

hengyunabc avatar Nov 07 '22 07:11 hengyunabc