summaryrefslogtreecommitdiffstats
path: root/lldb/unittests/Core/TimerTest.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2017-05-15 13:02:37 +0000
committerPavel Labath <labath@google.com>2017-05-15 13:02:37 +0000
commitf9d16476573e16856bdb3250c817b0a2c631d2b1 (patch)
tree7cae9a3d7fb178078ab0e4990ebf991c93679c08 /lldb/unittests/Core/TimerTest.cpp
parent3030bf0c816b136c97d8c69ca8b38e394eefd5d2 (diff)
downloadbcm5719-llvm-f9d16476573e16856bdb3250c817b0a2c631d2b1.tar.gz
bcm5719-llvm-f9d16476573e16856bdb3250c817b0a2c631d2b1.zip
Remove an expensive lock from Timer
The Timer destructor would grab a global mutex in order to update execution time. Add a class to define a category once, statically; the class adds itself to an atomic singly linked list, and thus subsequent updates only need to use an atomic rather than grab a lock and perform a hashtable lookup. Differential Revision: https://reviews.llvm.org/D32823 Patch by Scott Smith <scott.smith@purestorage.com>. llvm-svn: 303058
Diffstat (limited to 'lldb/unittests/Core/TimerTest.cpp')
-rw-r--r--lldb/unittests/Core/TimerTest.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/lldb/unittests/Core/TimerTest.cpp b/lldb/unittests/Core/TimerTest.cpp
index 7e7eeef0a36..a35df0d49c8 100644
--- a/lldb/unittests/Core/TimerTest.cpp
+++ b/lldb/unittests/Core/TimerTest.cpp
@@ -18,7 +18,8 @@ using namespace lldb_private;
TEST(TimerTest, CategoryTimes) {
Timer::ResetCategoryTimes();
{
- Timer t("CAT1", "");
+ static Timer::Category tcat("CAT1");
+ Timer t(tcat, "");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
StreamString ss;
@@ -32,14 +33,18 @@ TEST(TimerTest, CategoryTimes) {
TEST(TimerTest, CategoryTimesNested) {
Timer::ResetCategoryTimes();
{
- Timer t1("CAT1", "");
+ static Timer::Category tcat1("CAT1");
+ Timer t1(tcat1, "");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
- Timer t2("CAT1", "");
+ // Explicitly testing the same category as above.
+ Timer t2(tcat1, "");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
StreamString ss;
Timer::DumpCategoryTimes(&ss);
double seconds;
+ // It should only appear once.
+ ASSERT_EQ(ss.GetString().count("CAT1"), 1U);
ASSERT_EQ(1, sscanf(ss.GetData(), "%lf sec for CAT1", &seconds));
EXPECT_LT(0.002, seconds);
EXPECT_GT(0.2, seconds);
@@ -48,9 +53,11 @@ TEST(TimerTest, CategoryTimesNested) {
TEST(TimerTest, CategoryTimes2) {
Timer::ResetCategoryTimes();
{
- Timer t1("CAT1", "");
+ static Timer::Category tcat1("CAT1");
+ Timer t1(tcat1, "");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
- Timer t2("CAT2", "");
+ static Timer::Category tcat2("CAT2");
+ Timer t2(tcat2, "");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
StreamString ss;
OpenPOWER on IntegriCloud