perf tools: Introduce trim function