Some factorization in the profiling code