<div dir="ltr">Oops, yes, that's right -- the id is only used in assertions. Let me fix that.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Apr 6, 2017 at 9:08 PM Alexander Kornienko <<a href="mailto:alexfh@google.com">alexfh@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">FYI, this patch introduces -Wunused-variable warning:<div class="gmail_msg"><div class="gmail_msg">llvm/projects/compiler-rt/lib/xray/xray_fdr_logging_impl.h:597:12: error: unused variable 'TailExitFuncId' [-Werror,-Wunused-variable]</div><div class="gmail_msg">      auto TailExitFuncId = ExpectedTailExit.FuncId;</div><div class="gmail_msg">           ^</div><div class="gmail_msg">1 error generated.</div></div></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Thu, Apr 6, 2017 at 9:14 AM, Dean Michael Berris via llvm-commits <span dir="ltr" class="gmail_msg"><<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dberris<br class="gmail_msg">
Date: Thu Apr  6 02:14:43 2017<br class="gmail_msg">
New Revision: 299629<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=299629&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=299629&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
[XRay] [compiler-rt] Unwriting FDR mode buffers when functions are short.<br class="gmail_msg">
<br class="gmail_msg">
Summary:<br class="gmail_msg">
"short" is defined as an xray flag, and buffer rewinding happens for both exits<br class="gmail_msg">
 and tail exits.<br class="gmail_msg">
<br class="gmail_msg">
 I've made the choice to seek backwards finding pairs of FunctionEntry, TailExit<br class="gmail_msg">
 record pairs and erasing them if the FunctionEntry occurred before exit from the<br class="gmail_msg">
 currently exiting function. This is a compromise so that we don't skip logging<br class="gmail_msg">
 tail calls if the function that they call into takes longer our duration.<br class="gmail_msg">
<br class="gmail_msg">
 This works by counting the consecutive function and function entry, tail exit<br class="gmail_msg">
 pairs that proceed the current point in the buffer. The buffer is rewound to<br class="gmail_msg">
 check whether these entry points happened recently enough to be erased.<br class="gmail_msg">
<br class="gmail_msg">
 It is still possible we will omit them if they call into a child function that<br class="gmail_msg">
 is not instrumented which calls a fast grandchild that is instrumented before<br class="gmail_msg">
 doing other processing.<br class="gmail_msg">
<br class="gmail_msg">
Reviewers: pelikan, dberris<br class="gmail_msg">
<br class="gmail_msg">
Reviewed By: dberris<br class="gmail_msg">
<br class="gmail_msg">
Subscribers: llvm-commits<br class="gmail_msg">
<br class="gmail_msg">
Differential Revision: <a href="https://reviews.llvm.org/D31345" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D31345</a><br class="gmail_msg">
<br class="gmail_msg">
Modified:<br class="gmail_msg">
    compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h<br class="gmail_msg">
    compiler-rt/trunk/lib/xray/xray_flags.inc<br class="gmail_msg">
    compiler-rt/trunk/test/xray/TestCases/Linux/fdr-mode.cc<br class="gmail_msg">
<br class="gmail_msg">
Modified: compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h?rev=299629&r1=299628&r2=299629&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h?rev=299629&r1=299628&r2=299629&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h (original)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/xray/xray_fdr_logging_impl.h Thu Apr  6 02:14:43 2017<br class="gmail_msg">
@@ -32,6 +32,8 @@<br class="gmail_msg">
 #include "xray_buffer_queue.h"<br class="gmail_msg">
 #include "xray_defs.h"<br class="gmail_msg">
 #include "xray_fdr_log_records.h"<br class="gmail_msg">
+#include "xray_flags.h"<br class="gmail_msg">
+#include "xray_tsc.h"<br class="gmail_msg">
<br class="gmail_msg">
 namespace __xray {<br class="gmail_msg">
<br class="gmail_msg">
@@ -108,9 +110,17 @@ static void processFunctionHook(int32_t<br class="gmail_msg">
 //-----------------------------------------------------------------------------|<br class="gmail_msg">
<br class="gmail_msg">
 namespace {<br class="gmail_msg">
+<br class="gmail_msg">
 thread_local BufferQueue::Buffer Buffer;<br class="gmail_msg">
 thread_local char *RecordPtr = nullptr;<br class="gmail_msg">
<br class="gmail_msg">
+// The number of FunctionEntry records immediately preceding RecordPtr.<br class="gmail_msg">
+thread_local uint8_t NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+<br class="gmail_msg">
+// The number of adjacent, consecutive pairs of FunctionEntry, Tail Exit<br class="gmail_msg">
+// records preceding RecordPtr.<br class="gmail_msg">
+thread_local uint8_t NumTailCalls = 0;<br class="gmail_msg">
+<br class="gmail_msg">
 constexpr auto MetadataRecSize = sizeof(MetadataRecord);<br class="gmail_msg">
 constexpr auto FunctionRecSize = sizeof(FunctionRecord);<br class="gmail_msg">
<br class="gmail_msg">
@@ -209,6 +219,8 @@ static inline void writeNewBufferPreambl<br class="gmail_msg">
   }<br class="gmail_msg">
   std::memcpy(MemPtr, Records, sizeof(MetadataRecord) * InitRecordsCount);<br class="gmail_msg">
   MemPtr += sizeof(MetadataRecord) * InitRecordsCount;<br class="gmail_msg">
+  NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+  NumTailCalls = 0;<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 static inline void setupNewBuffer(const BufferQueue::Buffer &Buffer,<br class="gmail_msg">
@@ -221,6 +233,8 @@ static inline void setupNewBuffer(const<br class="gmail_msg">
   // This is typically clock_gettime, but callers have injection ability.<br class="gmail_msg">
   wall_clock_reader(CLOCK_MONOTONIC, &TS);<br class="gmail_msg">
   writeNewBufferPreamble(Tid, TS, RecordPtr);<br class="gmail_msg">
+  NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+  NumTailCalls = 0;<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 static inline void writeNewCPUIdMetadata(uint16_t CPU, uint64_t TSC,<br class="gmail_msg">
@@ -237,6 +251,8 @@ static inline void writeNewCPUIdMetadata<br class="gmail_msg">
   std::memcpy(&NewCPUId.Data[sizeof(CPU)], &TSC, sizeof(TSC));<br class="gmail_msg">
   std::memcpy(MemPtr, &NewCPUId, sizeof(MetadataRecord));<br class="gmail_msg">
   MemPtr += sizeof(MetadataRecord);<br class="gmail_msg">
+  NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+  NumTailCalls = 0;<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 static inline void writeNewCPUIdMetadata(uint16_t CPU,<br class="gmail_msg">
@@ -251,6 +267,8 @@ static inline void writeEOBMetadata(char<br class="gmail_msg">
   // For now we don't write any bytes into the Data field.<br class="gmail_msg">
   std::memcpy(MemPtr, &EOBMeta, sizeof(MetadataRecord));<br class="gmail_msg">
   MemPtr += sizeof(MetadataRecord);<br class="gmail_msg">
+  NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+  NumTailCalls = 0;<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 static inline void writeEOBMetadata() XRAY_NEVER_INSTRUMENT {<br class="gmail_msg">
@@ -269,6 +287,8 @@ static inline void writeTSCWrapMetadata(<br class="gmail_msg">
   std::memcpy(&TSCWrap.Data, &TSC, sizeof(TSC));<br class="gmail_msg">
   std::memcpy(MemPtr, &TSCWrap, sizeof(MetadataRecord));<br class="gmail_msg">
   MemPtr += sizeof(MetadataRecord);<br class="gmail_msg">
+  NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+  NumTailCalls = 0;<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 static inline void writeTSCWrapMetadata(uint64_t TSC) XRAY_NEVER_INSTRUMENT {<br class="gmail_msg">
@@ -289,13 +309,35 @@ static inline void writeFunctionRecord(i<br class="gmail_msg">
<br class="gmail_msg">
   switch (EntryType) {<br class="gmail_msg">
   case XRayEntryType::ENTRY:<br class="gmail_msg">
+    ++NumConsecutiveFnEnters;<br class="gmail_msg">
+    FuncRecord.RecordKind = uint8_t(FunctionRecord::RecordKinds::FunctionEnter);<br class="gmail_msg">
+    break;<br class="gmail_msg">
   case XRayEntryType::LOG_ARGS_ENTRY:<br class="gmail_msg">
+    // We should not rewind functions with logged args.<br class="gmail_msg">
+    NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+    NumTailCalls = 0;<br class="gmail_msg">
     FuncRecord.RecordKind = uint8_t(FunctionRecord::RecordKinds::FunctionEnter);<br class="gmail_msg">
     break;<br class="gmail_msg">
   case XRayEntryType::EXIT:<br class="gmail_msg">
+    // If we've decided to log the function exit, we will never erase the log<br class="gmail_msg">
+    // before it.<br class="gmail_msg">
+    NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+    NumTailCalls = 0;<br class="gmail_msg">
     FuncRecord.RecordKind = uint8_t(FunctionRecord::RecordKinds::FunctionExit);<br class="gmail_msg">
     break;<br class="gmail_msg">
   case XRayEntryType::TAIL:<br class="gmail_msg">
+    // If we just entered the function we're tail exiting from or erased every<br class="gmail_msg">
+    // invocation since then, this function entry tail pair is a candidate to<br class="gmail_msg">
+    // be erased when the child function exits.<br class="gmail_msg">
+    if (NumConsecutiveFnEnters > 0) {<br class="gmail_msg">
+      ++NumTailCalls;<br class="gmail_msg">
+      NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+    } else {<br class="gmail_msg">
+      // We will never be able to erase this tail call since we have logged<br class="gmail_msg">
+      // something in between the function entry and tail exit.<br class="gmail_msg">
+      NumTailCalls = 0;<br class="gmail_msg">
+      NumConsecutiveFnEnters = 0;<br class="gmail_msg">
+    }<br class="gmail_msg">
     FuncRecord.RecordKind =<br class="gmail_msg">
         uint8_t(FunctionRecord::RecordKinds::FunctionTailExit);<br class="gmail_msg">
     break;<br class="gmail_msg">
@@ -337,6 +379,8 @@ static inline void processFunctionHook(<br class="gmail_msg">
   // We assume that we'll support only 65536 CPUs for x86_64.<br class="gmail_msg">
   thread_local uint16_t CurrentCPU = std::numeric_limits<uint16_t>::max();<br class="gmail_msg">
   thread_local uint64_t LastTSC = 0;<br class="gmail_msg">
+  thread_local uint64_t LastFunctionEntryTSC = 0;<br class="gmail_msg">
+  thread_local uint64_t NumberOfTicksThreshold = 0;<br class="gmail_msg">
<br class="gmail_msg">
   // Make sure a thread that's ever called handleArg0 has a thread-local<br class="gmail_msg">
   // live reference to the buffer queue for this particular instance of<br class="gmail_msg">
@@ -379,6 +423,10 @@ static inline void processFunctionHook(<br class="gmail_msg">
       return;<br class="gmail_msg">
     }<br class="gmail_msg">
<br class="gmail_msg">
+    uint64_t CycleFrequency = getTSCFrequency();<br class="gmail_msg">
+    NumberOfTicksThreshold = CycleFrequency *<br class="gmail_msg">
+                             flags()->xray_fdr_log_func_duration_threshold_us /<br class="gmail_msg">
+                             1000000;<br class="gmail_msg">
     setupNewBuffer(Buffer, wall_clock_reader);<br class="gmail_msg">
   }<br class="gmail_msg">
<br class="gmail_msg">
@@ -441,6 +489,10 @@ static inline void processFunctionHook(<br class="gmail_msg">
              BufferQueue::getErrorString(EC));<br class="gmail_msg">
       return;<br class="gmail_msg">
     }<br class="gmail_msg">
+    uint64_t CycleFrequency = getTSCFrequency();<br class="gmail_msg">
+    NumberOfTicksThreshold = CycleFrequency *<br class="gmail_msg">
+                             flags()->xray_fdr_log_func_duration_threshold_us /<br class="gmail_msg">
+                             1000000;<br class="gmail_msg">
     setupNewBuffer(Buffer, wall_clock_reader);<br class="gmail_msg">
   }<br class="gmail_msg">
<br class="gmail_msg">
@@ -486,10 +538,92 @@ static inline void processFunctionHook(<br class="gmail_msg">
       RecordTSCDelta = Delta;<br class="gmail_msg">
   }<br class="gmail_msg">
<br class="gmail_msg">
-  // We then update our "LastTSC" and "CurrentCPU" thread-local variables to aid<br class="gmail_msg">
-  // us in future computations of this TSC delta value.<br class="gmail_msg">
   LastTSC = TSC;<br class="gmail_msg">
   CurrentCPU = CPU;<br class="gmail_msg">
+  using AlignedFuncStorage =<br class="gmail_msg">
+      std::aligned_storage<sizeof(FunctionRecord),<br class="gmail_msg">
+                           alignof(FunctionRecord)>::type;<br class="gmail_msg">
+  switch (Entry) {<br class="gmail_msg">
+  case XRayEntryType::ENTRY:<br class="gmail_msg">
+  case XRayEntryType::LOG_ARGS_ENTRY:<br class="gmail_msg">
+    // Update the thread local state for the next invocation.<br class="gmail_msg">
+    LastFunctionEntryTSC = TSC;<br class="gmail_msg">
+    break;<br class="gmail_msg">
+  case XRayEntryType::TAIL:<br class="gmail_msg">
+    break;<br class="gmail_msg">
+  case XRayEntryType::EXIT:<br class="gmail_msg">
+    // Break out and write the exit record if we can't erase any functions.<br class="gmail_msg">
+    if (NumConsecutiveFnEnters == 0 ||<br class="gmail_msg">
+        (TSC - LastFunctionEntryTSC) >= NumberOfTicksThreshold)<br class="gmail_msg">
+      break;<br class="gmail_msg">
+    // Otherwise we unwind functions that are too short to log by decrementing<br class="gmail_msg">
+    // our view ptr into the buffer. We can erase a Function Entry record and<br class="gmail_msg">
+    // neglect to log our EXIT. We have to make sure to update some state like<br class="gmail_msg">
+    // the LastTSC and count of consecutive FunctionEntry records.<br class="gmail_msg">
+    RecordPtr -= FunctionRecSize;<br class="gmail_msg">
+    AlignedFuncStorage AlignedFuncRecordBuffer;<br class="gmail_msg">
+    const auto &FuncRecord = *reinterpret_cast<FunctionRecord *>(<br class="gmail_msg">
+        std::memcpy(&AlignedFuncRecordBuffer, RecordPtr, FunctionRecSize));<br class="gmail_msg">
+    assert(FuncRecord.RecordKind ==<br class="gmail_msg">
+               uint8_t(FunctionRecord::RecordKinds::FunctionEnter) &&<br class="gmail_msg">
+           "Expected to find function entry recording when rewinding.");<br class="gmail_msg">
+    assert(FuncRecord.FuncId == (FuncId & ~(0x0F << 28)) &&<br class="gmail_msg">
+           "Expected matching function id when rewinding Exit");<br class="gmail_msg">
+    --NumConsecutiveFnEnters;<br class="gmail_msg">
+    LastTSC -= FuncRecord.TSCDelta;<br class="gmail_msg">
+<br class="gmail_msg">
+    // We unwound one call. Update the state and return without writing a log.<br class="gmail_msg">
+    if (NumConsecutiveFnEnters != 0) {<br class="gmail_msg">
+      LastFunctionEntryTSC = LastFunctionEntryTSC - FuncRecord.TSCDelta;<br class="gmail_msg">
+      return;<br class="gmail_msg">
+    }<br class="gmail_msg">
+<br class="gmail_msg">
+    // Otherwise we've rewound the stack of all function entries, we might be<br class="gmail_msg">
+    // able to rewind further by erasing tail call functions that are being<br class="gmail_msg">
+    // exited from via this exit.<br class="gmail_msg">
+    LastFunctionEntryTSC = 0;<br class="gmail_msg">
+    auto RewindingTSC = LastTSC;<br class="gmail_msg">
+    auto RewindingRecordPtr = RecordPtr - FunctionRecSize;<br class="gmail_msg">
+    while (NumTailCalls > 0) {<br class="gmail_msg">
+      AlignedFuncStorage TailExitRecordBuffer;<br class="gmail_msg">
+      // Rewind the TSC back over the TAIL EXIT record.<br class="gmail_msg">
+      const auto &ExpectedTailExit =<br class="gmail_msg">
+          *reinterpret_cast<FunctionRecord *>(std::memcpy(<br class="gmail_msg">
+              &TailExitRecordBuffer, RewindingRecordPtr, FunctionRecSize));<br class="gmail_msg">
+<br class="gmail_msg">
+      assert(ExpectedTailExit.RecordKind ==<br class="gmail_msg">
+                 uint8_t(FunctionRecord::RecordKinds::FunctionTailExit) &&<br class="gmail_msg">
+             "Expected to find tail exit when rewinding.");<br class="gmail_msg">
+      auto TailExitFuncId = ExpectedTailExit.FuncId;<br class="gmail_msg">
+      RewindingRecordPtr -= FunctionRecSize;<br class="gmail_msg">
+      RewindingTSC -= ExpectedTailExit.TSCDelta;<br class="gmail_msg">
+      AlignedFuncStorage FunctionEntryBuffer;<br class="gmail_msg">
+      const auto &ExpectedFunctionEntry =<br class="gmail_msg">
+          *reinterpret_cast<FunctionRecord *>(std::memcpy(<br class="gmail_msg">
+              &FunctionEntryBuffer, RewindingRecordPtr, FunctionRecSize));<br class="gmail_msg">
+      assert(ExpectedFunctionEntry.RecordKind ==<br class="gmail_msg">
+                 uint8_t(FunctionRecord::RecordKinds::FunctionEnter) &&<br class="gmail_msg">
+             "Expected to find function entry when rewinding tail call.");<br class="gmail_msg">
+      assert(ExpectedFunctionEntry.FuncId == TailExitFuncId &&<br class="gmail_msg">
+             "Expected funcids to match when rewinding tail call.");<br class="gmail_msg">
+<br class="gmail_msg">
+      if ((TSC - RewindingTSC) < NumberOfTicksThreshold) {<br class="gmail_msg">
+        // We can erase a tail exit pair that we're exiting through since<br class="gmail_msg">
+        // its duration is under threshold.<br class="gmail_msg">
+        --NumTailCalls;<br class="gmail_msg">
+        RewindingRecordPtr -= FunctionRecSize;<br class="gmail_msg">
+        RewindingTSC -= ExpectedFunctionEntry.TSCDelta;<br class="gmail_msg">
+        RecordPtr -= 2 * FunctionRecSize;<br class="gmail_msg">
+        LastTSC = RewindingTSC;<br class="gmail_msg">
+      } else {<br class="gmail_msg">
+        // This tail call exceeded the threshold duration. It will not<br class="gmail_msg">
+        // be erased.<br class="gmail_msg">
+        NumTailCalls = 0;<br class="gmail_msg">
+        return;<br class="gmail_msg">
+      }<br class="gmail_msg">
+    }<br class="gmail_msg">
+    return; // without writing log.<br class="gmail_msg">
+  }<br class="gmail_msg">
<br class="gmail_msg">
   writeFunctionRecord(FuncId, RecordTSCDelta, Entry, RecordPtr);<br class="gmail_msg">
<br class="gmail_msg">
@@ -510,5 +644,4 @@ static inline void processFunctionHook(<br class="gmail_msg">
 } // namespace __xray_fdr_internal<br class="gmail_msg">
<br class="gmail_msg">
 } // namespace __xray<br class="gmail_msg">
-<br class="gmail_msg">
 #endif // XRAY_XRAY_FDR_LOGGING_IMPL_H<br class="gmail_msg">
<br class="gmail_msg">
Modified: compiler-rt/trunk/lib/xray/xray_flags.inc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_flags.inc?rev=299629&r1=299628&r2=299629&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_flags.inc?rev=299629&r1=299628&r2=299629&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/xray/xray_flags.inc (original)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/xray/xray_flags.inc Thu Apr  6 02:14:43 2017<br class="gmail_msg">
@@ -22,3 +22,6 @@ XRAY_FLAG(const char *, xray_logfile_bas<br class="gmail_msg">
           "Filename base for the xray logfile.")<br class="gmail_msg">
 XRAY_FLAG(bool, xray_fdr_log, false,<br class="gmail_msg">
           "Whether to install the flight data recorder logging implementation.")<br class="gmail_msg">
+XRAY_FLAG(int, xray_fdr_log_func_duration_threshold_us, 5,<br class="gmail_msg">
+          "FDR logging will try to skip functions that execute for fewer "<br class="gmail_msg">
+          "microseconds than this threshold.")<br class="gmail_msg">
<br class="gmail_msg">
Modified: compiler-rt/trunk/test/xray/TestCases/Linux/fdr-mode.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/xray/TestCases/Linux/fdr-mode.cc?rev=299629&r1=299628&r2=299629&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/xray/TestCases/Linux/fdr-mode.cc?rev=299629&r1=299628&r2=299629&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/test/xray/TestCases/Linux/fdr-mode.cc (original)<br class="gmail_msg">
+++ compiler-rt/trunk/test/xray/TestCases/Linux/fdr-mode.cc Thu Apr  6 02:14:43 2017<br class="gmail_msg">
@@ -1,7 +1,10 @@<br class="gmail_msg">
 // RUN: %clangxx_xray -g -std=c++11 %s -o %t<br class="gmail_msg">
-// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false xray_logfile_base=fdr-logging-test- xray_fdr_log=true verbosity=1" %run %t 2>&1 | FileCheck %s<br class="gmail_msg">
-// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t "`ls fdr-logging-test-* | head -1`" | FileCheck %s --check-prefix TRACE<br class="gmail_msg">
+// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false xray_logfile_base=fdr-logging-test- xray_fdr_log=true verbosity=1 xray_fdr_log_func_duration_threshold_us=0" %run %t 2>&1 | FileCheck %s<br class="gmail_msg">
+// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false xray_logfile_base=fdr-unwrite-test- xray_fdr_log=true verbosity=1 xray_fdr_log_func_duration_threshold_us=5000" %run %t 2>&1 | FileCheck %s<br class="gmail_msg">
+// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t "`ls fdr-logging-test-* | head -1`" | FileCheck %s --check-prefix=TRACE<br class="gmail_msg">
+// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t "`ls fdr-unwrite-test-* | head -1`" | FileCheck %s --check-prefix=UNWRITE<br class="gmail_msg">
 // RUN: rm fdr-logging-test-*<br class="gmail_msg">
+// RUN: rm fdr-unwrite-test-*<br class="gmail_msg">
 // FIXME: Make llvm-xray work on non-x86_64 as well.<br class="gmail_msg">
 // REQUIRES: x86_64-linux<br class="gmail_msg">
<br class="gmail_msg">
@@ -61,8 +64,6 @@ int main(int argc, char *argv[]) {<br class="gmail_msg">
   return 0;<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
-<br class="gmail_msg">
-<br class="gmail_msg">
 // Check that we're able to see two threads, each entering and exiting fA().<br class="gmail_msg">
 // TRACE-DAG: - { type: 0, func-id: [[FIDA:[0-9]+]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }<br class="gmail_msg">
 // TRACE:     - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD1]], kind: function-exit, tsc: {{[0-9]+}} }<br class="gmail_msg">
@@ -80,3 +81,9 @@ int main(int argc, char *argv[]) {<br class="gmail_msg">
 // TRACE:     - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD1]], kind: function-exit, tsc: {{[0-9]+}} }<br class="gmail_msg">
 // TRACE-DAG: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }<br class="gmail_msg">
 // TRACE:     - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD2]], kind: function-exit, tsc: {{[0-9]+}} }<br class="gmail_msg">
+<br class="gmail_msg">
+// Assert that when unwriting is enabled with a high threshold time, all the function records are erased. A CPU switch could erroneously fail this test, but<br class="gmail_msg">
+// is unlikely given the test program.<br class="gmail_msg">
+// UNWRITE: header<br class="gmail_msg">
+// UNWRITE-NOT: function-enter<br class="gmail_msg">
+// UNWRITE-NOT: function-exit<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div><br class="gmail_msg"></div>
</blockquote></div>