This tiny sample demonstrates how to use RDTSC processor instruction with Watcom C/C++ and CodeWarrior PDK for NetWare. It tells you how many processor ticks a single call to ThreadSwitch() spends on your system; you can use this approach to profile other system calls or parts of your application.
#include <nwthread.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __WATCOMC__
unsigned __int64 rdtsc( void);
#pragma aux rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory;
#else /* CW PDK */
static unsigned __int64 rdtsc( void) {
__asm rdtsc;
}
#endif
int main( void) {
unsigned __int64 start = rdtsc();
ThreadSwitch();
printf( "stop - start = %u\n", rdtsc() - start);
return EXIT_SUCCESS;
}
© 2008 Novell, Inc. All Rights Reserved.