Java count individual bytecode instructions executed

China☆狼群 提交于 2019-12-24 10:56:44

问题


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!


回答1:


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')



来源:https://stackoverflow.com/questions/42215583/java-count-individual-bytecode-instructions-executed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!