Change when sampling thread is reset during shutdown to prevent races.

Also adds some extra argument checking and testing for tracing.

Bug: 17412385

(cherry picked from commit f8bdd4e783842577e49f418a0b5962ba49dfdd93)

Change-Id: Ifc4f1a296155d73255b29d264b5475024e6419da
4 files changed