[PATCH] D54292: [XRay] Fix enter function tracing for record unwriting

Dean Michael Berris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 8 22:51:39 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL346475: [XRay] Fix enter function tracing for record unwriting (authored by dberris, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D54292?vs=173269&id=173273#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D54292

Files:
  compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc
  compiler-rt/trunk/lib/xray/xray_fdr_controller.h


Index: compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc
===================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc
+++ compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc
@@ -222,6 +222,50 @@
   EXPECT_THAT_EXPECTED(TraceOrErr, HasValue(IsEmpty()));
 }
 
+TEST_F(FunctionSequenceTest, RewindingAfterMigration) {
+  C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 1000);
+
+  // First we construct an arbitrarily deep function enter/call stack.
+  // We also ensure that we are in the same CPU.
+  uint64_t TSC = 1;
+  uint16_t CPU = 1;
+  ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
+  ASSERT_TRUE(C->functionEnter(2, TSC++, CPU));
+  ASSERT_TRUE(C->functionEnter(3, TSC++, CPU));
+
+  // Next we tail-exit into a new function multiple times.
+  ASSERT_TRUE(C->functionTailExit(3, TSC++, CPU));
+  ASSERT_TRUE(C->functionEnter(4, TSC++, CPU));
+  ASSERT_TRUE(C->functionTailExit(4, TSC++, CPU));
+
+  // But before we enter the next function, we migrate to a different CPU.
+  CPU = 2;
+  ASSERT_TRUE(C->functionEnter(5, TSC++, CPU));
+  ASSERT_TRUE(C->functionTailExit(5, TSC++, CPU));
+  ASSERT_TRUE(C->functionEnter(6, TSC++, CPU));
+
+  // Then we exit them one at a time, in reverse order of entry.
+  ASSERT_TRUE(C->functionExit(6, TSC++, CPU));
+  ASSERT_TRUE(C->functionExit(2, TSC++, CPU));
+  ASSERT_TRUE(C->functionExit(1, TSC++, CPU));
+
+  ASSERT_TRUE(C->flush());
+  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
+
+  // Serialize buffers then test that we can find all the events that span the
+  // CPU migration.
+  std::string Serialized = serialize(*BQ, 3);
+  llvm::DataExtractor DE(Serialized, true, 8);
+  auto TraceOrErr = llvm::xray::loadTrace(DE);
+  EXPECT_THAT_EXPECTED(
+      TraceOrErr,
+      HasValue(ElementsAre(
+          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::ENTER)),
+          AllOf(FuncId(2), RecordType(llvm::xray::RecordTypes::ENTER)),
+          AllOf(FuncId(2), RecordType(llvm::xray::RecordTypes::EXIT)),
+          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::EXIT)))));
+}
+
 class BufferManagementTest : public ::testing::Test {
 protected:
   BufferQueue::Buffer B{};
Index: compiler-rt/trunk/lib/xray/xray_fdr_controller.h
===================================================================
--- compiler-rt/trunk/lib/xray/xray_fdr_controller.h
+++ compiler-rt/trunk/lib/xray/xray_fdr_controller.h
@@ -252,9 +252,13 @@
     if (PreambleStatus == PreambleResult::InvalidBuffer)
       return returnBuffer();
 
-    UndoableFunctionEnters = (PreambleStatus == PreambleResult::WroteMetadata)
-                                 ? 1
-                                 : UndoableFunctionEnters + 1;
+    if (PreambleStatus == PreambleResult::WroteMetadata) {
+      UndoableFunctionEnters = 1;
+      UndoableTailExits = 0;
+    } else {
+      ++UndoableFunctionEnters;
+    }
+
     auto Delta = TSC - LatestTSC;
     LastFunctionEntryTSC = TSC;
     LatestTSC = TSC;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54292.173273.patch
Type: text/x-patch
Size: 3062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181109/20d06548/attachment.bin>


More information about the llvm-commits mailing list