Page MenuHomePhabricator

[XRay][compiler-rt] Add PID field to llvm-xray tool and add PID metadata record entry in FDR mode
ClosedPublic

Authored by Maknee on Jul 10 2018, 2:08 PM.

Details

Summary

llvm-xray changes:

  • account-mode - process-id {...} shows after thread-id
  • convert-mode - process {...} shows after thread
  • parses FDR and basic mode pid entries
  • Checks version number for FDR log parsing.

Basic logging changes:

  • Update header version from 2 -> 3

FDR logging changes:

  • Update header version from 2 -> 3
  • in writeBufferPreamble, there is an additional PID Metadata record (after thread id record and tsc record)

Test cases changes:

  • fdr-mode.cc, fdr-single-thread.cc, fdr-thread-order.cc modified to catch process id output in the log.

Diff Detail

Event Timeline

Maknee created this revision.Jul 10 2018, 2:08 PM
Herald added subscribers: Restricted Project, llvm-commits, hiraditya. · View Herald TranscriptJul 10 2018, 2:08 PM
dberris requested changes to this revision.Jul 10 2018, 4:27 PM

This is where we're going to need to update the log version, because the tool(s) need to handle older versions of the log which don't contain the PID records.

Do the tests pass when you do make check-all or ninja check-all?

llvm/lib/XRay/Trace.cpp
271 ↗(On Diff #154872)

This has to be conditional on the version of the log, otherwise older version logs can't be handled by the tool. We try to be backwards-compatible to a degree, until we explicitly drop support for older versions.

This revision now requires changes to proceed.Jul 10 2018, 4:27 PM
Maknee updated this revision to Diff 155061.EditedJul 11 2018, 2:08 PM
Maknee edited the summary of this revision. (Show Details)

FDR/Basic changes:

  • Updated header version 2 -> 3

llvm-xray changes:

  • Now parses basic logs
  • Accounts for version differences when parsing through FDR metadata
  • Updated testcases to expect a version 3 instead of 2
  • Updated fork_basic_logging.cc to expect the updated log format

Reran test cases and they passed.

dberris added inline comments.Jul 11 2018, 5:01 PM
llvm/lib/XRay/Trace.cpp
390–397 ↗(On Diff #155061)

You don't need the else branch because of the body of the first if already returns.

You also don't need the curly braces for one-line if statements.

llvm/tools/llvm-xray/xray-account.cpp
479–481 ↗(On Diff #155061)

Did clang-format do this?

Maknee updated this revision to Diff 155108.Jul 11 2018, 7:35 PM
Maknee marked an inline comment as done.

Addressed the changes to return statement and curly braces for one liner if statements

Ran clang-format

Thanks @Maknee -- now if you look in llvm/test/tools/llvm-xray/X86 you'll find some tests for the llvm-xray tool. Also, in the Inputs sub-directory, you'll find sample XRay traces of the old versions. It would be great if you can add version 3 sample binary traces there and add more tests to ensure that we are getting the expected data from the tools handling the newer version(s) of the traces.

Maknee marked 2 inline comments as done.Jul 11 2018, 8:09 PM

Thanks @Maknee -- now if you look in llvm/test/tools/llvm-xray/X86 you'll find some tests for the llvm-xray tool. Also, in the Inputs sub-directory, you'll find sample XRay traces of the old versions. It would be great if you can add version 3 sample binary traces there and add more tests to ensure that we are getting the expected data from the tools handling the newer version(s) of the traces.

Okay, will do.

llvm/lib/XRay/Trace.cpp
395 ↗(On Diff #155061)

Added check here to expect a PID_RECORD after WallTimeRecord if using version >= 3

llvm/tools/llvm-xray/xray-account.cpp
479–481 ↗(On Diff #155061)

Oops. Forgot to run clang-format.

Thanks @Maknee -- now if you look in llvm/test/tools/llvm-xray/X86 you'll find some tests for the llvm-xray tool. Also, in the Inputs sub-directory, you'll find sample XRay traces of the old versions. It would be great if you can add version 3 sample binary traces there and add more tests to ensure that we are getting the expected data from the tools handling the newer version(s) of the traces.

Okay, will do.

I realise that I may have been a little unclear here.

To be clear, the suggestion is to create a binary that's XRay-instrumented and get version 3 files generated from those (for FDR mode). We don't need to keep the binary in the Inputs directory, we just need the trace file generated from this binary.

Maknee updated this revision to Diff 155261.Jul 12 2018, 1:49 PM
Maknee marked an inline comment as done.

Changes llvm-xray:

  • convert mode checks for differences in header version numbers when parsing/outputting values (to make sure older traces won't generate errors)

Updates to test cases:

  • Added 4 xray outputs into Inputs directory for version 3 (basic with/without arg1, fdr with/without arg1)
  • Added 4 different test cases for version 3 that checks the output of convert mode

Made sure test cases with the older header versions and the newer header version passed.

dberris accepted this revision.Jul 12 2018, 4:29 PM

LGTM -- Thanks, @Maknee!

One style comment, and I'm happy to land after that.

You might also want to consider applying for commit access if you would like to continue working on parts of XRay moving forward.

https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

llvm/lib/XRay/Trace.cpp
128–135 ↗(On Diff #155261)

Minor/Style: We don't generally add curly braces for if statements that only have one statement in the branches.

This revision is now accepted and ready to land.Jul 12 2018, 4:29 PM
Maknee updated this revision to Diff 155320.Jul 12 2018, 10:05 PM

Fixed one liner if statement to not include curly braces

Maknee marked an inline comment as done.Jul 12 2018, 10:06 PM

LGTM -- Thanks, @Maknee!

One style comment, and I'm happy to land after that.

You might also want to consider applying for commit access if you would like to continue working on parts of XRay moving forward.

https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

I'll be happy to keep contributing to XRay!

Thanks

This revision was automatically updated to reflect the committed changes.