Rework recording method information in the V2 format

In the new method trace format (V2), we record the method information
of all the loaded classes at the start of trace to avoid a lookup while
processing trace events. This was causing a long pause at the start of
the trace. There was also a bug where we didn't record the method
informations for non-streaming mode with the new format. This CL fixes
the bug and also improves the pause time from about a second to around
200ms. The changes include:
1. Also record method information for non-streaming mode. This was a bug
   introduced by aosp/2986229.
2. Use a buffer to aggregate the information across classes at the
   startup of the trace to avoid multiple small writes to the file
3. Enqueue a task to write the buffer to the file avoiding expensinve
   I/O on the main thread.
4. Install class prepare listeners only if the V2 trace format is
   requested. For the V1 class prepare was a nop.

Bug: 329498538, 259258187
Test: art/test.py -t 2246-trace-v2

Change-Id: I0749569cfc3be1bc0394950758f88c16ebf8fc81
2 files changed