isize: Measuring average dynamic instruction size

Mike Haertel and I had an interesting conversation today about the average size of an x86 instruction. Mike knew that the average instruction in the stream was about 3.5 bytes. We decided to measure. The resulting tool, isize, confirms this estimate: we observed average instruction sizes between 3.1 and 3.8 bytes per instruction on a variety of programs and workloads.

The tool operates by using ptrace(2), and measuring succesive instruction pointer values to compute instruction sizes. Jumps are inferred by too-large eip changes, or are partially decoded from the x86 stream. Jumps are ignored in the calculations, since there's no convenient way to measure their size. The measurement methodology is extremely slow: a couple of orders of magnitude slower than normal exectuion.

Hopefully, someone will eventually do the hard work of instrumenting an x86 emulator to get more accurate information much, much more quickly. In the meantime, enjoy...