[XRay] [compiler-rt] Write buffer length to FDR log before writing buffer.
authorDean Michael Berris <dberris@google.com>
Wed, 29 Mar 2017 05:56:37 +0000 (05:56 +0000)
committerDean Michael Berris <dberris@google.com>
Wed, 29 Mar 2017 05:56:37 +0000 (05:56 +0000)
commit9b57ca171dd05043ddca0e3d15fb9fc1a692144f
treefa9a72d3c835a7f47fc52d03bd11dadd0c6ea773
parent0676fb5ae65584389f7340d30d1c13148d778b6c
[XRay] [compiler-rt] Write buffer length to FDR log before writing buffer.

Summary:
Currently the FDR log writer, upon flushing, dumps a sequence of buffers from
its freelist to disk. A reader can read the first buffer up to an EOB record,
but then it is unclear how far ahead to scan to find the next threads traces.

There are a few ways to handle this problem.
1. The reader has externalized knowledge of the buffer size.
2. The size of buffers is in the file header or otherwise encoded in the log.
3. Only write out the portion of the buffer with records. When released, the
   buffers are marked with a size.
4. The reader looks for memory that matches a pattern and synchronizes on it.

2 and 3 seem the most flexible and 2 does not rule 3 out.

This is an implementation of 2.

In addition, the function handler for fdr more aggressively checks for
finalization and makes an attempt to release its buffer.

Reviewers: pelikan, dberris

Reviewed By: dberris

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D31384

llvm-svn: 298982
compiler-rt/include/xray/xray_records.h
compiler-rt/lib/xray/xray_buffer_queue.h
compiler-rt/lib/xray/xray_fdr_logging.cc
compiler-rt/lib/xray/xray_fdr_logging_impl.h