Java计算执行的单个字节码指令 [英] Java count individual bytecode instructions executed

查看:85
本文介绍了Java计算执行的单个字节码指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用


I am trying to use ASM to count the individual bytecode instructions executed within a single function to build a histogram. I see there is a tool ByCounter that can do a similar task--but I do not have access to the source code.

My understanding is the Java asm bytecode library can instrument classes, fields, methods, but examples for instrumenting an individual bytecode instruction are not to be found (though from ByCounter--it is found to be possible).

If a tool like the JVMTI is better suited, then that is also useful information!

Thanks for your help!

解决方案

This is the kind of silly thing I made Jawa for. Example:

from collections import Counter
from jawa.cf import ClassFile
import pandas


with open('tests/data/HelloWorldDebug.class', 'rb') as fin:
    cf = ClassFile(fin)

    method = cf.methods.find_one(name='<init>')

    ins = Counter(i.mnemonic for i in method.code.disassemble())

    df = pandas.DataFrame.from_dict(ins, orient='index')
    fig = df.plot(kind='bar').get_figure()
    fig.savefig('example.png')

这篇关于Java计算执行的单个字节码指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆