Clean up profiler implementation and separate it from command handling, add periodic saving of profiling information to disk.

Signed-off-by: Ross Allan <rallanpcl@gmail.com>