tracing: consolidate code between trace_output.c and trace_function_graph.c