No, you don't want buf to point to the code - you want buf to point to a chunk of memory with a size corresponding to the size of code you want to profile (e.g. that size * sizeof(u_short)) - for example, you can allocate it using malloc, or have a fixed size array of u_short buffer[2000] if you think 2000 bytes will cover your function).

Not sure how &thread can be 1. But &thread would be a good value for "offset".

--
Mats