rebased. passed TestTracing by removing timing dependency in testWriteTraceHooks.