perf tools: Factorize the thread code in a dedicated file