[compiler-rt] r346475 - [XRay] Fix enter function tracing for record unwriting
Dean Michael Berris via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 8 22:49:00 PST 2018
Author: dberris
Date: Thu Nov 8 22:49:00 2018
New Revision: 346475
URL: http://llvm.org/viewvc/llvm-project?rev=346475&view=rev
Log:
[XRay] Fix enter function tracing for record unwriting
Summary:
Before this change, we could run into a situation where we may try to
undo tail exit records after writing metadata records before a function
enter event. This change rectifies that by resetting the tail exit
counter after writing the metadata records.
Reviewers: mboerger
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D54292
Modified:
compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc
compiler-rt/trunk/lib/xray/xray_fdr_controller.h
Modified: compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc?rev=346475&r1=346474&r2=346475&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc Thu Nov 8 22:49:00 2018
@@ -222,6 +222,50 @@ TEST_F(FunctionSequenceTest, RewindingIn
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{};
Modified: compiler-rt/trunk/lib/xray/xray_fdr_controller.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_fdr_controller.h?rev=346475&r1=346474&r2=346475&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/xray_fdr_controller.h (original)
+++ compiler-rt/trunk/lib/xray/xray_fdr_controller.h Thu Nov 8 22:49:00 2018
@@ -252,9 +252,13 @@ public:
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;
More information about the llvm-commits
mailing list