Add self profiling support

Add simple library functions for self profiling of programs.