Update method tracing to use per-thread buffer

Method tracing in streaming mode uses a global buffer to record method
entry / exit events and uses locks to synchronize across threads. Taking
a lock for each event is expensive and makes the method tracing slow.
This CL changes it to use a per-thread buffer so that each thread
accesses its own buffer. This also allows us to fast path method trace
events in JITed code in the future. The changes in this CL:
1. Add a per-thread buffer which is initialized lazily on the first
   method trace event.
2. When the per-thread buffer is initialized we record the information
   about the thread. This means we no longer need the bitmap we used
   to record the thread info when a new thread is seen.
3. The data from the buffer is flushed to file:
     1. When a thread detaches, so we can flush any recorded data
     2. When the buffer is full
     3. When we stop tracing.

The per-thread buffer is always accessed by the thread that owns it
except when we record the method enter events for on stack methods. It
is safe to access other thread's buffer since everything is suspended at
that point.

This CL also adds a test to check that the generated trace is in the
expected format.

Bug: 259258187
Test: art/testrunner.py -t 2246

Change-Id: I074bf2edb8c884dec0c9a7a9c37b4ef0ec7892a8
diff --git a/test/2246-trace-stream/run.py b/test/2246-trace-stream/run.py
new file mode 100644
index 0000000..6881d71
--- /dev/null
+++ b/test/2246-trace-stream/run.py
@@ -0,0 +1,22 @@
+#!/bin/bash
+#
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+def run(ctx, args):
+  # The expected output is different in debuggable and non debuggable. Just
+  # enable debuggable for now.
+  # TODO(mythria): Also add tests for non-debuggable mode.
+  ctx.default_run(args, Xcompiler_option=["--debuggable"])