问题
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