Thread-local trace-event buffers

Previously we use a central trace-event buffer to store trace events
from all threads, which needs a lock. Measurement showed that on
Android the lock contributes over 50% of the total overhead of
trace event.

Use thread-local trace-event buffers so that in most times trace
events can be handled lock-free.

TraceLog::Flush() now may asynchronously call the callback.

TODO: Now for a message loop running a blocking task, async flush
doesn't work. The async flush will timeout and finish without
collecting the last batch of such thread if any.

On Nexus 4 this patch can reduce the average overhead of trace_event
from 15~20us to about 5~8us for a busy app. Note the numbers are not
very accurate because
- the time tick seems 30us on Android. The average number may be just
a result of increased percentage of trace events whose overhead < 30us.
- there are differences in the measurement method of the overhead
because of the change of the code structure.

BUG=264667
TEST=Updated existing tests: TraceEventTestFixture.DataCapturedOnThread
and TraceEventTestFixture.DataCapturedManyThreads. Existing unit/browser
tests using trace_event should still pass.
R=nduca, dsinclair
TBR=phajdan.jr (for base/test/trace_event_analyzer_unittest.cc)

Review URL: https://chromiumcodereview.appspot.com/22962004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221766 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 07b877310a5f4b7385968b96cb5ff2a07872f83c
4 files changed
tree: 533923e00f24231b2c5eafe2fa20d852c36cf1ea
  1. base/
  2. build/
  3. components/
  4. dbus/
  5. ipc/
  6. testing/
  7. third_party/
  8. ui/