2016-11-03 17:14:09 +08:00
|
|
|
//===-- TimerTest.cpp -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-11-03 17:14:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2017-06-29 22:32:17 +08:00
|
|
|
#include "lldb/Utility/Timer.h"
|
|
|
|
#include "gtest/gtest.h"
|
2016-11-03 17:14:09 +08:00
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
TEST(TimerTest, CategoryTimes) {
|
|
|
|
Timer::ResetCategoryTimes();
|
|
|
|
{
|
2017-05-15 21:02:37 +08:00
|
|
|
static Timer::Category tcat("CAT1");
|
2019-02-27 04:14:07 +08:00
|
|
|
Timer t(tcat, ".");
|
2016-11-03 17:14:09 +08:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
}
|
|
|
|
StreamString ss;
|
|
|
|
Timer::DumpCategoryTimes(&ss);
|
|
|
|
double seconds;
|
|
|
|
ASSERT_EQ(1, sscanf(ss.GetData(), "%lf sec for CAT1", &seconds));
|
|
|
|
EXPECT_LT(0.001, seconds);
|
|
|
|
EXPECT_GT(0.1, seconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TimerTest, CategoryTimesNested) {
|
|
|
|
Timer::ResetCategoryTimes();
|
|
|
|
{
|
2017-05-15 21:02:37 +08:00
|
|
|
static Timer::Category tcat1("CAT1");
|
2019-02-27 04:14:07 +08:00
|
|
|
Timer t1(tcat1, ".");
|
2016-11-03 17:14:09 +08:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
2017-05-15 21:02:37 +08:00
|
|
|
// Explicitly testing the same category as above.
|
2019-02-27 04:14:07 +08:00
|
|
|
Timer t2(tcat1, ".");
|
2016-11-03 18:07:47 +08:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
2016-11-03 17:14:09 +08:00
|
|
|
}
|
|
|
|
StreamString ss;
|
|
|
|
Timer::DumpCategoryTimes(&ss);
|
|
|
|
double seconds;
|
2017-05-15 21:02:37 +08:00
|
|
|
// It should only appear once.
|
|
|
|
ASSERT_EQ(ss.GetString().count("CAT1"), 1U);
|
2016-11-03 17:14:09 +08:00
|
|
|
ASSERT_EQ(1, sscanf(ss.GetData(), "%lf sec for CAT1", &seconds));
|
|
|
|
EXPECT_LT(0.002, seconds);
|
|
|
|
EXPECT_GT(0.2, seconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TimerTest, CategoryTimes2) {
|
|
|
|
Timer::ResetCategoryTimes();
|
|
|
|
{
|
2017-05-15 21:02:37 +08:00
|
|
|
static Timer::Category tcat1("CAT1");
|
2019-02-27 04:14:07 +08:00
|
|
|
Timer t1(tcat1, ".");
|
2016-11-03 18:07:47 +08:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
2017-05-15 21:02:37 +08:00
|
|
|
static Timer::Category tcat2("CAT2");
|
2019-02-27 04:14:07 +08:00
|
|
|
Timer t2(tcat2, ".");
|
2016-11-03 17:14:09 +08:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
}
|
|
|
|
StreamString ss;
|
|
|
|
Timer::DumpCategoryTimes(&ss);
|
|
|
|
double seconds1, seconds2;
|
Add more information to the log timer dump
Summary:
The `log timer dump` is showing the time of the function itself minus any function that is called from this one that also happens to be timed. However, this is really not obvious and it also makes it hard to understand the time spent in total and also which children are actually taking the time.
To get a better reading of the timer dump I added the total, children (which I named child) and also the hit count. I used these timers to figure out a performance issue and only after adding this things were more clear to me.
It looks like this:
```
(lldb) log timer dump
35.447713617 sec (total: 35.449s; child: 0.001s; count: 1374) for void SymbolFileDWARF::Index()
29.717921481 sec (total: 29.718s; child: 0.000s; count: 8230500) for const lldb_private::ConstString &lldb_private::Mangled::GetDemangledName(lldb::LanguageType) const
21.049508865 sec (total: 24.683s; child: 3.633s; count: 1399) for void lldb_private::Symtab::InitNameIndexes()
...
```
Reviewers: clayborg, teemperor, labath, espindola, xiaobai
Reviewed By: labath, xiaobai
Subscribers: emaste, mgorny, arichardson, eraman, MaskRay, jdoerfert, labath, davide, teemperor, aprantl, erik.pilkington, jfb, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D61235
llvm-svn: 361987
2019-05-30 00:31:32 +08:00
|
|
|
ASSERT_EQ(2, sscanf(ss.GetData(),
|
2019-05-30 23:38:05 +08:00
|
|
|
"%lf sec (total: %*fs; child: %*fs; count: %*d) for "
|
Add more information to the log timer dump
Summary:
The `log timer dump` is showing the time of the function itself minus any function that is called from this one that also happens to be timed. However, this is really not obvious and it also makes it hard to understand the time spent in total and also which children are actually taking the time.
To get a better reading of the timer dump I added the total, children (which I named child) and also the hit count. I used these timers to figure out a performance issue and only after adding this things were more clear to me.
It looks like this:
```
(lldb) log timer dump
35.447713617 sec (total: 35.449s; child: 0.001s; count: 1374) for void SymbolFileDWARF::Index()
29.717921481 sec (total: 29.718s; child: 0.000s; count: 8230500) for const lldb_private::ConstString &lldb_private::Mangled::GetDemangledName(lldb::LanguageType) const
21.049508865 sec (total: 24.683s; child: 3.633s; count: 1399) for void lldb_private::Symtab::InitNameIndexes()
...
```
Reviewers: clayborg, teemperor, labath, espindola, xiaobai
Reviewed By: labath, xiaobai
Subscribers: emaste, mgorny, arichardson, eraman, MaskRay, jdoerfert, labath, davide, teemperor, aprantl, erik.pilkington, jfb, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D61235
llvm-svn: 361987
2019-05-30 00:31:32 +08:00
|
|
|
"CAT1%*[\n ]%lf sec for CAT2",
|
2016-11-03 18:07:47 +08:00
|
|
|
&seconds1, &seconds2))
|
2016-11-17 05:45:11 +08:00
|
|
|
<< "String: " << ss.GetData();
|
2016-11-03 18:07:47 +08:00
|
|
|
EXPECT_LT(0.01, seconds1);
|
|
|
|
EXPECT_GT(1, seconds1);
|
2016-11-03 17:14:09 +08:00
|
|
|
EXPECT_LT(0.001, seconds2);
|
|
|
|
EXPECT_GT(0.1, seconds2);
|
|
|
|
}
|
Add more information to the log timer dump
Summary:
The `log timer dump` is showing the time of the function itself minus any function that is called from this one that also happens to be timed. However, this is really not obvious and it also makes it hard to understand the time spent in total and also which children are actually taking the time.
To get a better reading of the timer dump I added the total, children (which I named child) and also the hit count. I used these timers to figure out a performance issue and only after adding this things were more clear to me.
It looks like this:
```
(lldb) log timer dump
35.447713617 sec (total: 35.449s; child: 0.001s; count: 1374) for void SymbolFileDWARF::Index()
29.717921481 sec (total: 29.718s; child: 0.000s; count: 8230500) for const lldb_private::ConstString &lldb_private::Mangled::GetDemangledName(lldb::LanguageType) const
21.049508865 sec (total: 24.683s; child: 3.633s; count: 1399) for void lldb_private::Symtab::InitNameIndexes()
...
```
Reviewers: clayborg, teemperor, labath, espindola, xiaobai
Reviewed By: labath, xiaobai
Subscribers: emaste, mgorny, arichardson, eraman, MaskRay, jdoerfert, labath, davide, teemperor, aprantl, erik.pilkington, jfb, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D61235
llvm-svn: 361987
2019-05-30 00:31:32 +08:00
|
|
|
|
|
|
|
TEST(TimerTest, CategoryTimesStats) {
|
|
|
|
Timer::ResetCategoryTimes();
|
|
|
|
{
|
|
|
|
static Timer::Category tcat1("CAT1");
|
|
|
|
Timer t1(tcat1, ".");
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
static Timer::Category tcat2("CAT2");
|
|
|
|
{
|
|
|
|
Timer t2(tcat2, ".");
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Timer t3(tcat2, ".");
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Example output:
|
|
|
|
// 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);
|
|
|
|
double seconds1, total1, child1, seconds2;
|
|
|
|
int count1, count2;
|
|
|
|
ASSERT_EQ(
|
|
|
|
6, sscanf(ss.GetData(),
|
|
|
|
"%lf sec (total: %lfs; child: %lfs; count: %d) for CAT1%*[\n ]"
|
2019-05-30 23:38:05 +08:00
|
|
|
"%lf sec (total: %*fs; child: %*fs; count: %d) for CAT2",
|
Add more information to the log timer dump
Summary:
The `log timer dump` is showing the time of the function itself minus any function that is called from this one that also happens to be timed. However, this is really not obvious and it also makes it hard to understand the time spent in total and also which children are actually taking the time.
To get a better reading of the timer dump I added the total, children (which I named child) and also the hit count. I used these timers to figure out a performance issue and only after adding this things were more clear to me.
It looks like this:
```
(lldb) log timer dump
35.447713617 sec (total: 35.449s; child: 0.001s; count: 1374) for void SymbolFileDWARF::Index()
29.717921481 sec (total: 29.718s; child: 0.000s; count: 8230500) for const lldb_private::ConstString &lldb_private::Mangled::GetDemangledName(lldb::LanguageType) const
21.049508865 sec (total: 24.683s; child: 3.633s; count: 1399) for void lldb_private::Symtab::InitNameIndexes()
...
```
Reviewers: clayborg, teemperor, labath, espindola, xiaobai
Reviewed By: labath, xiaobai
Subscribers: emaste, mgorny, arichardson, eraman, MaskRay, jdoerfert, labath, davide, teemperor, aprantl, erik.pilkington, jfb, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D61235
llvm-svn: 361987
2019-05-30 00:31:32 +08:00
|
|
|
&seconds1, &total1, &child1, &count1, &seconds2, &count2))
|
|
|
|
<< "String: " << ss.GetData();
|
|
|
|
EXPECT_NEAR(total1 - child1, seconds1, 0.002);
|
|
|
|
EXPECT_EQ(1, count1);
|
|
|
|
EXPECT_NEAR(child1, seconds2, 0.002);
|
|
|
|
EXPECT_EQ(2, count2);
|
|
|
|
}
|