[llvm] r313514 - [XRay][tools] Support tail-call exits before we write them in the runtime

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 17 23:08:46 PDT 2017


Author: dberris
Date: Sun Sep 17 23:08:46 2017
New Revision: 313514

URL: http://llvm.org/viewvc/llvm-project?rev=313514&view=rev
Log:
[XRay][tools] Support tail-call exits before we write them in the runtime

Summary:
This change adds support for explicit tail-exit records to be written by
the XRay runtime. This lets us differentiate the tail exit
records/events in the log, and allows us to treat those exit events
especially in the future. For now we allow printing those out in YAML
(and reading them in).

Reviewers: kpw, pelikan

Subscribers: llvm-commits

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

Modified:
    llvm/trunk/docs/XRayFDRFormat.rst
    llvm/trunk/include/llvm/XRay/XRayRecord.h
    llvm/trunk/include/llvm/XRay/YAMLXRayRecord.h
    llvm/trunk/lib/XRay/Trace.cpp
    llvm/trunk/test/tools/llvm-xray/X86/convert-fdr-to-yaml.txt
    llvm/trunk/tools/llvm-xray/xray-account.cc
    llvm/trunk/tools/llvm-xray/xray-converter.cc
    llvm/trunk/tools/llvm-xray/xray-graph.cc
    llvm/trunk/tools/llvm-xray/xray-stacks.cc

Modified: llvm/trunk/docs/XRayFDRFormat.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/XRayFDRFormat.rst?rev=313514&r1=313513&r2=313514&view=diff
==============================================================================
--- llvm/trunk/docs/XRayFDRFormat.rst (original)
+++ llvm/trunk/docs/XRayFDRFormat.rst Sun Sep 17 23:08:46 2017
@@ -165,7 +165,7 @@ Function action types are as follows.
 +---------------+--------------+-----------------------------------------------+
 | Exit          | ``1``        | Typical function exit.                        |
 +---------------+--------------+-----------------------------------------------+
-| Tail_Exit     | ``2``        | An exit from a function due to Tail call      |
+| Tail_Exit     | ``2``        | An exit from a function due to tail call      |
 |               |              | optimization.                                 |
 +---------------+--------------+-----------------------------------------------+
 | Entry_Args    | ``3``        | A function entry that records arguments.      |

Modified: llvm/trunk/include/llvm/XRay/XRayRecord.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/XRay/XRayRecord.h?rev=313514&r1=313513&r2=313514&view=diff
==============================================================================
--- llvm/trunk/include/llvm/XRay/XRayRecord.h (original)
+++ llvm/trunk/include/llvm/XRay/XRayRecord.h Sun Sep 17 23:08:46 2017
@@ -53,7 +53,7 @@ struct XRayFileHeader {
 /// This may or may not correspond to actual record types in the raw trace (as
 /// the loader implementation may synthesize this information in the process of
 /// of loading).
-enum class RecordTypes { ENTER, EXIT };
+enum class RecordTypes { ENTER, EXIT, TAIL_EXIT };
 
 struct XRayRecord {
   /// The type of record.

Modified: llvm/trunk/include/llvm/XRay/YAMLXRayRecord.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/XRay/YAMLXRayRecord.h?rev=313514&r1=313513&r2=313514&view=diff
==============================================================================
--- llvm/trunk/include/llvm/XRay/YAMLXRayRecord.h (original)
+++ llvm/trunk/include/llvm/XRay/YAMLXRayRecord.h Sun Sep 17 23:08:46 2017
@@ -54,6 +54,7 @@ template <> struct ScalarEnumerationTrai
   static void enumeration(IO &IO, xray::RecordTypes &Type) {
     IO.enumCase(Type, "function-enter", xray::RecordTypes::ENTER);
     IO.enumCase(Type, "function-exit", xray::RecordTypes::EXIT);
+    IO.enumCase(Type, "function-tail-exit", xray::RecordTypes::TAIL_EXIT);
   }
 };
 

Modified: llvm/trunk/lib/XRay/Trace.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/XRay/Trace.cpp?rev=313514&r1=313513&r2=313514&view=diff
==============================================================================
--- llvm/trunk/lib/XRay/Trace.cpp (original)
+++ llvm/trunk/lib/XRay/Trace.cpp Sun Sep 17 23:08:46 2017
@@ -48,7 +48,7 @@ Error readBinaryFormatHeader(StringRef D
   FileHeader.NonstopTSC = Bitfield & 1uL << 1;
   FileHeader.CycleFrequency = HeaderExtractor.getU64(&OffsetPtr);
   std::memcpy(&FileHeader.FreeFormData, Data.bytes_begin() + OffsetPtr, 16);
-  if (FileHeader.Version != 1)
+  if (FileHeader.Version != 1 && FileHeader.Version != 2)
     return make_error<StringError>(
         Twine("Unsupported XRay file version: ") + Twine(FileHeader.Version),
         std::make_error_code(std::errc::invalid_argument));
@@ -94,6 +94,9 @@ Error loadNaiveFormatLog(StringRef Data,
     case 1:
       Record.Type = RecordTypes::EXIT;
       break;
+    case 2:
+      Record.Type = RecordTypes::TAIL_EXIT;
+      break;
     default:
       return make_error<StringError>(
           Twine("Unknown record type '") + Twine(int{Type}) + "'",
@@ -320,9 +323,11 @@ Error processFDRFunctionRecord(FDRState
       Record.Type = RecordTypes::ENTER;
       break;
     case static_cast<uint8_t>(RecordTypes::EXIT):
-    case 2: // TAIL_EXIT is not yet defined in RecordTypes.
       Record.Type = RecordTypes::EXIT;
       break;
+    case static_cast<uint8_t>(RecordTypes::TAIL_EXIT):
+      Record.Type = RecordTypes::TAIL_EXIT;
+      break;
     default:
       // Cast to an unsigned integer to not interpret the record type as a char.
       return make_error<StringError>(
@@ -443,7 +448,7 @@ Error loadFDRLog(StringRef Data, XRayFil
   // Having iterated over everything we've been given, we've either consumed
   // everything and ended up in the end state, or were told to skip the rest.
   bool Finished = State.Expects == FDRState::Token::SCAN_TO_END_OF_THREAD_BUF &&
-        State.CurrentBufferSize == State.CurrentBufferConsumed;
+                  State.CurrentBufferSize == State.CurrentBufferConsumed;
   if (State.Expects != FDRState::Token::NEW_BUFFER_RECORD_OR_EOF && !Finished)
     return make_error<StringError>(
         Twine("Encountered EOF with unexpected state expectation ") +
@@ -534,9 +539,8 @@ Expected<Trace> llvm::xray::loadTraceFil
   enum BinaryFormatType { NAIVE_FORMAT = 0, FLIGHT_DATA_RECORDER_FORMAT = 1 };
 
   Trace T;
-  if (Version == 1 && Type == NAIVE_FORMAT) {
-    if (auto E =
-            loadNaiveFormatLog(Data, T.FileHeader, T.Records))
+  if (Type == NAIVE_FORMAT && (Version == 1 || Version == 2)) {
+    if (auto E = loadNaiveFormatLog(Data, T.FileHeader, T.Records))
       return std::move(E);
   } else if (Version == 1 && Type == FLIGHT_DATA_RECORDER_FORMAT) {
     if (auto E = loadFDRLog(Data, T.FileHeader, T.Records))

Modified: llvm/trunk/test/tools/llvm-xray/X86/convert-fdr-to-yaml.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/convert-fdr-to-yaml.txt?rev=313514&r1=313513&r2=313514&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-xray/X86/convert-fdr-to-yaml.txt (original)
+++ llvm/trunk/test/tools/llvm-xray/X86/convert-fdr-to-yaml.txt Sun Sep 17 23:08:46 2017
@@ -16,7 +16,7 @@
 ; CHECK-NEXT:   - { type: 0, func-id: 2, function: '2', cpu: 5, thread: 5, kind: function-exit, tsc: 7238225556407467 }
 ; CHECK-NEXT:   - { type: 0, func-id: 4, function: '4', cpu: 5, thread: 5, kind: function-enter, tsc: 7238225556407492 }
 ; CHECK-NEXT:   - { type: 0, func-id: 5, function: '5', cpu: 5, thread: 5, kind: function-enter, tsc: 7238225556407517 }
-; CHECK-NEXT:   - { type: 0, func-id: 5, function: '5', cpu: 5, thread: 5, kind: function-exit, tsc: 7238225556407542 }
+; CHECK-NEXT:   - { type: 0, func-id: 5, function: '5', cpu: 5, thread: 5, kind: function-tail-exit, tsc: 7238225556407542 }
 ; CHECK-NEXT:   - { type: 0, func-id: 268435455, function: '268435455', cpu: 5, thread: 5, kind: function-enter, tsc: 7238225556407552 }
 ; CHECK-NEXT:   - { type: 0, func-id: 268435455, function: '268435455', cpu: 5, thread: 5, kind: function-exit, tsc: 7238225556407562 }
 ; CHECK-NEXT:   - { type: 0, func-id: 6, function: '6', cpu: 6, thread: 5, kind: function-enter, tsc: 7238225556407682 }

Modified: llvm/trunk/tools/llvm-xray/xray-account.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-account.cc?rev=313514&r1=313513&r2=313514&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/xray-account.cc (original)
+++ llvm/trunk/tools/llvm-xray/xray-account.cc Sun Sep 17 23:08:46 2017
@@ -150,7 +150,8 @@ bool LatencyAccountant::accountRecord(co
     ThreadStack.emplace_back(Record.FuncId, Record.TSC);
     break;
   }
-  case RecordTypes::EXIT: {
+  case RecordTypes::EXIT:
+  case RecordTypes::TAIL_EXIT: {
     if (ThreadStack.empty())
       return false;
 
@@ -419,6 +420,9 @@ template <> struct format_provider<llvm:
       case RecordTypes::EXIT:
         Stream << "exit";
         break;
+      case RecordTypes::TAIL_EXIT:
+        Stream << "tail-exit";
+        break;
     }
   }
 };

Modified: llvm/trunk/tools/llvm-xray/xray-converter.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-converter.cc?rev=313514&r1=313513&r2=313514&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/xray-converter.cc (original)
+++ llvm/trunk/tools/llvm-xray/xray-converter.cc Sun Sep 17 23:08:46 2017
@@ -128,6 +128,9 @@ void TraceConverter::exportAsRAWv1(const
     case RecordTypes::EXIT:
       Writer.write(uint8_t{1});
       break;
+    case RecordTypes::TAIL_EXIT:
+      Writer.write(uint8_t{2});
+      break;
     }
     Writer.write(R.FuncId);
     Writer.write(R.TSC);

Modified: llvm/trunk/tools/llvm-xray/xray-graph.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-graph.cc?rev=313514&r1=313513&r2=313514&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/xray-graph.cc (original)
+++ llvm/trunk/tools/llvm-xray/xray-graph.cc Sun Sep 17 23:08:46 2017
@@ -214,7 +214,8 @@ Error GraphRenderer::accountRecord(const
     ThreadStack.push_back({Record.FuncId, Record.TSC});
     break;
   }
-  case RecordTypes::EXIT: {
+  case RecordTypes::EXIT:
+  case RecordTypes::TAIL_EXIT: {
     // FIXME: Refactor this and the account subcommand to reduce code
     // duplication
     if (ThreadStack.size() == 0 || ThreadStack.back().FuncId != Record.FuncId) {

Modified: llvm/trunk/tools/llvm-xray/xray-stacks.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-stacks.cc?rev=313514&r1=313513&r2=313514&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/xray-stacks.cc (original)
+++ llvm/trunk/tools/llvm-xray/xray-stacks.cc Sun Sep 17 23:08:46 2017
@@ -352,7 +352,8 @@ public:
       }
       return AccountRecordStatus::OK;
     }
-    case RecordTypes::EXIT: {
+    case RecordTypes::EXIT:
+    case RecordTypes::TAIL_EXIT: {
       bool wasLastRecordExit = state->wasLastRecordExit;
       state->wasLastRecordExit = true;
       // The exit case is more interesting, since we want to be able to deduce




More information about the llvm-commits mailing list