This is an archive of the discontinued LLVM Phabricator instance.

[XRay] [compiler-rt] Refactor logic for xray fdr logging. NFC.
ClosedPublic

Authored by kpw on Mar 10 2017, 2:31 PM.

Details

Summary

Separated the IO and the thread local storage state machine of logging
from the writing of log records once the contents are deterministic.

Finer granularity functions are provided as inline functions in the same
header such that stack does not grow due to the functions being separated.

An executable utility xray_fdr_log_printer is also implemented to use the
finest granularity functions to produce binary test data in the FDR format
with a relatively convenient text input.

For example, one can take a file with textual contents layed out in rows
and feed it to the binary to generate data that llvm-xray convert can then
read. This is a convenient way to build a test suite for llvm-xray convert
to ensure it's robust to the fdr format.

Example:

$cat myFile.txt
NewBuffer : { time = 2 , Tid=5}
NewCPU : { CPU =1 , TSC = 123}
Function : { FuncId = 5, TSCDelta = 3, EntryType = Entry }
Function : { FuncId = 5, TSCDelta = 5, EntryType = Exit}
TSCWrap : { TSC = 678 }
Function : { FuncId = 6, TSCDelta = 0, EntryType = Entry }
Function : { FuncId = 6, TSCDelta = 50, EntryType = Exit }
EOB : { }
$cat myFile.txt | ./bin/xray_fdr_log_printer > /tmp/binarydata.bin
$./bin/llvm-xray convert -output-format=yaml -output=- /tmp/binarydata.bin

yaml format comes out as expected.

Diff Detail

Repository
rL LLVM

Event Timeline

kpw created this revision.Mar 10 2017, 2:31 PM
dberris accepted this revision.Mar 14 2017, 8:11 PM

LGTM

Thanks @kpw -- I see that you have the tool that reads a file in some special format, but don't see tests that use it (yet). In future changes it would be great to see whether we can get the test suite grown incrementally.

This revision is now accepted and ready to land.Mar 14 2017, 8:11 PM
dberris retitled this revision from [XRay] [compiler-rt] Refactor logic for xray fdr logging. to [XRay] [compiler-rt] Refactor logic for xray fdr logging. NFC..Mar 14 2017, 8:16 PM
This revision was automatically updated to reflect the committed changes.
lonico77 added inline comments.
compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h
137

I'm seeing the following error when building with clang 3.9.1:

In file included from /x/eng/rtpbld01/scratch/laurentn/llvm-wss/sources/llvm_import_from_git_rtp2/llvm/projects/compiler-rt/lib/xray/tests/unit/xray_fdr_log_printer_tool.cc:15:
/x/eng/rtpbld01/scratch/laurentn/llvm-wss/sources/llvm_import_from_git_rtp2/llvm/projects/compiler-rt/lib/xray/tests/../xray_fdr_logging_impl.h:137:19: error: implicit instantiation of undefined template 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >'
               EC.message().c_str());
                  ^
/x/eng/btools/arch/x86_64-redhat-rhel6/compilers_n_tools/pkgs/llvm-3.9.1-p1/bin/../include/c++/v1/iosfwd:193:33: note: template is declared here
    class _LIBCPP_TYPE_VIS_ONLY basic_string;
                                ^

And the same error shows up in 5 other locations where EC.message() is used.

I was able to bypass the error by adding

 #include <mutex>
+#include <string>
 #include <system_error>

in llvm/projects/compiler-rt/lib/xray/xray_buffer_queue.h

but I'm not sure it's the best way to address this across platforms.