Author: Alex Langford Date: 2023-06-26T10:36:41-07:00 New Revision: 5f69e6682bf0806c13098f79cb5f1ee30f0f8c06
URL: https://github.com/llvm/llvm-project/commit/5f69e6682bf0806c13098f79cb5f1ee30f0f8c06 DIFF: https://github.com/llvm/llvm-project/commit/5f69e6682bf0806c13098f79cb5f1ee30f0f8c06.diff LOG: [lldb][NFCI] Timer::DumpCategoryTimes should take a reference instead of a pointer We are assuming that the pointer is always valid, might as well take a reference instead. Differential Revision: https://reviews.llvm.org/D153711 Added: Modified: lldb/include/lldb/Utility/Timer.h lldb/source/Commands/CommandObjectLog.cpp lldb/source/Utility/Timer.cpp lldb/unittests/Utility/TimerTest.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Utility/Timer.h b/lldb/include/lldb/Utility/Timer.h index 201378bbeb2cc..3ce93c25c66f3 100644 --- a/lldb/include/lldb/Utility/Timer.h +++ b/lldb/include/lldb/Utility/Timer.h @@ -56,7 +56,7 @@ class Timer { static void SetQuiet(bool value); - static void DumpCategoryTimes(Stream *s); + static void DumpCategoryTimes(Stream &s); static void ResetCategoryTimes(); diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index 8549d22e70f98..5dd6f89898372 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -504,7 +504,7 @@ class CommandObjectLogTimerDisable : public CommandObjectParsed { protected: bool DoExecute(Args &args, CommandReturnObject &result) override { - Timer::DumpCategoryTimes(&result.GetOutputStream()); + Timer::DumpCategoryTimes(result.GetOutputStream()); Timer::SetDisplayDepth(0); result.SetStatus(eReturnStatusSuccessFinishResult); @@ -527,7 +527,7 @@ class CommandObjectLogTimerDump : public CommandObjectParsed { protected: bool DoExecute(Args &args, CommandReturnObject &result) override { - Timer::DumpCategoryTimes(&result.GetOutputStream()); + Timer::DumpCategoryTimes(result.GetOutputStream()); result.SetStatus(eReturnStatusSuccessFinishResult); if (!result.Succeeded()) { diff --git a/lldb/source/Utility/Timer.cpp b/lldb/source/Utility/Timer.cpp index 477541d7bb3d1..a059f877e0236 100644 --- a/lldb/source/Utility/Timer.cpp +++ b/lldb/source/Utility/Timer.cpp @@ -135,7 +135,7 @@ void Timer::ResetCategoryTimes() { } } -void Timer::DumpCategoryTimes(Stream *s) { +void Timer::DumpCategoryTimes(Stream &s) { std::vector<Stats> sorted; for (Category *i = g_categories; i; i = i->m_next) { uint64_t nanos = i->m_nanos.load(std::memory_order_acquire); @@ -153,9 +153,9 @@ void Timer::DumpCategoryTimes(Stream *s) { llvm::sort(sorted, CategoryMapIteratorSortCriterion); for (const auto &stats : sorted) - s->Printf("%.9f sec (total: %.3fs; child: %.3fs; count: %" PRIu64 - ") for %s\n", - stats.nanos / 1000000000., stats.nanos_total / 1000000000., - (stats.nanos_total - stats.nanos) / 1000000000., stats.count, - stats.name); + s.Printf("%.9f sec (total: %.3fs; child: %.3fs; count: %" PRIu64 + ") for %s\n", + stats.nanos / 1000000000., stats.nanos_total / 1000000000., + (stats.nanos_total - stats.nanos) / 1000000000., stats.count, + stats.name); } diff --git a/lldb/unittests/Utility/TimerTest.cpp b/lldb/unittests/Utility/TimerTest.cpp index c6d1facdebbbc..b371ebff4fe77 100644 --- a/lldb/unittests/Utility/TimerTest.cpp +++ b/lldb/unittests/Utility/TimerTest.cpp @@ -21,7 +21,7 @@ TEST(TimerTest, CategoryTimes) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } StreamString ss; - Timer::DumpCategoryTimes(&ss); + Timer::DumpCategoryTimes(ss); double seconds; ASSERT_EQ(1, sscanf(ss.GetData(), "%lf sec for CAT1", &seconds)); EXPECT_LT(0.001, seconds); @@ -39,7 +39,7 @@ TEST(TimerTest, CategoryTimesNested) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } StreamString ss; - Timer::DumpCategoryTimes(&ss); + Timer::DumpCategoryTimes(ss); double seconds; // It should only appear once. ASSERT_EQ(ss.GetString().count("CAT1"), 1U); @@ -59,7 +59,7 @@ TEST(TimerTest, CategoryTimes2) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } StreamString ss; - Timer::DumpCategoryTimes(&ss); + Timer::DumpCategoryTimes(ss); double seconds1, seconds2; ASSERT_EQ(2, sscanf(ss.GetData(), "%lf sec (total: %*fs; child: %*fs; count: %*d) for " @@ -92,7 +92,7 @@ TEST(TimerTest, CategoryTimesStats) { // 0.105202764 sec (total: 0.132s; child: 0.027s; count: 1) for CAT1 // 0.026772798 sec (total: 0.027s; child: 0.000s; count: 2) for CAT2 StreamString ss; - Timer::DumpCategoryTimes(&ss); + Timer::DumpCategoryTimes(ss); double seconds1, total1, child1, seconds2; int count1, count2; ASSERT_EQ( _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits