exploring the use of ptrace vs the x86 trapflag to step through every instruction of a program.
there are three small programs executing a certain number of instructions:
count-ptrace.c
uses ptrace to step through every instruction, executing~1e6
instructionscount-trapflag.c
uses the x86 trap flag and signal handlers to execute~1e7
instructionsloop.c
executes~1e9
instructions without any instrumentation
These are the execution times on my netbook (32-bit Intel Atom N450, 1.66GHz):
1e6
instructinos in61.7s
incount-ptrace.c
(16.2KHz)1e7
instructions in38.1s
incount-trapflag.c
(262.5KHz)1e9
instructions in0.61s
inloop.c
(1,639MHz)
This implies the following slow-downs of the different instrumentation schemes:
101,172x
slower with ptrace6,244x
slower with trapflag and x86
This implies using the trapflag+signal handlers is about 16x
faster than using ptrace.