Back porting Denis Pravdin changes to CPU Profiling code.
Make sure tests are passed.