X86 build command execution count

Hello everyone. I have a code and I want to find the number of times each conveyor line runs. I do not care about whether through profiling or emulation, but I want to get high results. Once I came across a forum that gave code for writing scripts, but I lost the link. Can someone help me make some attempts? Relations

Edit : Okay, I think I'm halfway. I did some research on the BTS (Branch Trace Store) provided in Intel Manual 3A section 16.4.5, according to one post. This feature provides a history of branches. So now I need your help to find out if there are any open source scripts or tools for this. Awaiting review of your reviews

cheers =)!

+3
source share
3 answers

If your processor supports it, you can enable the Branch Trace Store (BTS). The BTS keeps a log of all received branches in a predefined memory area. Each entry contains a branch source and destination. Using this, you can calculate how many times you have been in each code segment.

See Volume 3A Intel Software Developer's Guide , Section 16.4.5 (in the current edition) for how to enable it.

+2
source

If you don't care about performance, you can do a little trick to count this. Raise one step exception and, going into your own seh handler, raise another and move on to the next command.

Perhaps some profiler tools, such as pin or valgrind, make this easier for you. I would advise you to take a look.

+1
source

One (albeit slow) method was to write your own debugger. Then it will stop the entry point of your program, and when it is deleted, it will set the trace flag in EFlags in context, so it will also be split into a debugger and the next instruction. Then you can use the hash table with EIP to count the number of hits in time. The only problem is that the overhead will be extreme and the application will run very slowly.

+1
source

Source: https://habr.com/ru/post/1333396/


All Articles