perf_counter tools: Merge common code into perfcounters.h