Skip to content

Commit

Permalink
[lldb] Abstract scoped timer logic behind LLDB_SCOPED_TIMER (NFC)
Browse files Browse the repository at this point in the history
This patch introduces a LLDB_SCOPED_TIMER macro to hide the needlessly
repetitive creation of scoped timers in LLDB. It's similar to the
LLDB_LOG(F) macro.

Differential revision: https://reviews.llvm.org/D93663
  • Loading branch information
JDevlieghere committed Dec 22, 2020
1 parent 8a58f21 commit 5c1c844
Show file tree
Hide file tree
Showing 30 changed files with 73 additions and 156 deletions.
7 changes: 7 additions & 0 deletions lldb/include/lldb/Utility/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@ class Timer {

} // namespace lldb_private

#define LLDB_SCOPED_TIMER() \
static ::lldb_private::Timer::Category _cat(LLVM_PRETTY_FUNCTION); \
::lldb_private::Timer _scoped_timer(_cat, LLVM_PRETTY_FUNCTION)
#define LLDB_SCOPED_TIMERF(...) \
static ::lldb_private::Timer::Category _cat(LLVM_PRETTY_FUNCTION); \
::lldb_private::Timer _scoped_timer(_cat, __VA_ARGS__)

#endif // LLDB_UTILITY_TIMER_H
3 changes: 0 additions & 3 deletions lldb/source/API/SystemInitializerFull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ llvm::Error SystemInitializerFull::Initialize() {
}

void SystemInitializerFull::Terminate() {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);

Debugger::SettingsTerminate();

// Terminate plug-ins in core LLDB
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Commands/CommandObjectTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
}

const char *file_path = command.GetArgumentAtIndex(0);
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "(lldb) target create '%s'", file_path);
LLDB_SCOPED_TIMERF("(lldb) target create '%s'", file_path);
FileSpec file_spec;

if (file_path) {
Expand Down
4 changes: 1 addition & 3 deletions lldb/source/Core/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ using namespace lldb_private;
DisassemblerSP Disassembler::FindPlugin(const ArchSpec &arch,
const char *flavor,
const char *plugin_name) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"Disassembler::FindPlugin (arch = %s, plugin_name = %s)",
LLDB_SCOPED_TIMERF("Disassembler::FindPlugin (arch = %s, plugin_name = %s)",
arch.GetArchitectureName(), plugin_name);

DisassemblerCreateInstance create_callback = nullptr;
Expand Down
7 changes: 2 additions & 5 deletions lldb/source/Core/Mangled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ static char *GetItaniumDemangledStr(const char *M) {
bool Mangled::DemangleWithRichManglingInfo(
RichManglingContext &context, SkipMangledNameFn *skip_mangled_name) {
// We need to generate and cache the demangled name.
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"Mangled::DemangleWithRichNameIndexInfo (m_mangled = %s)",
LLDB_SCOPED_TIMERF("Mangled::DemangleWithRichNameIndexInfo (m_mangled = %s)",
m_mangled.GetCString());

// Others are not meant to arrive here. ObjC names or C's main() for example
Expand Down Expand Up @@ -299,8 +297,7 @@ ConstString Mangled::GetDemangledName() const {
// already decoded our mangled name.
if (m_mangled && m_demangled.IsNull()) {
// We need to generate and cache the demangled name.
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "Mangled::GetDemangledName (m_mangled = %s)",
LLDB_SCOPED_TIMERF("Mangled::GetDemangledName (m_mangled = %s)",
m_mangled.GetCString());

// Don't bother running anything that isn't mangled
Expand Down
43 changes: 13 additions & 30 deletions lldb/source/Core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ void Module::DumpSymbolContext(Stream *s) {

size_t Module::GetNumCompileUnits() {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "Module::GetNumCompileUnits (module = %p)",
LLDB_SCOPED_TIMERF("Module::GetNumCompileUnits (module = %p)",
static_cast<void *>(this));
if (SymbolFile *symbols = GetSymbolFile())
return symbols->GetNumCompileUnits();
Expand All @@ -441,9 +440,7 @@ CompUnitSP Module::GetCompileUnitAtIndex(size_t index) {

bool Module::ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")",
LLDB_SCOPED_TIMERF("Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")",
vm_addr);
SectionList *section_list = GetSectionList();
if (section_list)
Expand Down Expand Up @@ -594,9 +591,7 @@ uint32_t Module::ResolveSymbolContextsForFileSpec(
const FileSpec &file_spec, uint32_t line, bool check_inlines,
lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"Module::ResolveSymbolContextForFilePath (%s:%u, "
LLDB_SCOPED_TIMERF("Module::ResolveSymbolContextForFilePath (%s:%u, "
"check_inlines = %s, resolve_scope = 0x%8.8x)",
file_spec.GetPath().c_str(), line,
check_inlines ? "yes" : "no", resolve_scope);
Expand Down Expand Up @@ -940,8 +935,7 @@ void Module::FindTypes_Impl(
size_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();
if (SymbolFile *symbols = GetSymbolFile())
symbols->FindTypes(name, parent_decl_ctx, max_matches,
searched_symbol_files, types);
Expand Down Expand Up @@ -1028,8 +1022,7 @@ void Module::FindTypes(
llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();
if (SymbolFile *symbols = GetSymbolFile())
symbols->FindTypes(pattern, languages, searched_symbol_files, types);
}
Expand All @@ -1040,8 +1033,7 @@ SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) {
if (!m_did_load_symfile.load() && can_create) {
ObjectFile *obj_file = GetObjectFile();
if (obj_file != nullptr) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();
m_symfile_up.reset(
SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
m_did_load_symfile = true;
Expand Down Expand Up @@ -1244,8 +1236,7 @@ ObjectFile *Module::GetObjectFile() {
if (!m_did_load_objfile.load()) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (!m_did_load_objfile.load()) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "Module::GetObjectFile () module = %s",
LLDB_SCOPED_TIMERF("Module::GetObjectFile () module = %s",
GetFileSpec().GetFilename().AsCString(""));
lldb::offset_t data_offset = 0;
lldb::offset_t file_size = 0;
Expand Down Expand Up @@ -1312,9 +1303,8 @@ SectionList *Module::GetUnifiedSectionList() {

const Symbol *Module::FindFirstSymbolWithNameAndType(ConstString name,
SymbolType symbol_type) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(
func_cat, "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
LLDB_SCOPED_TIMERF(
"Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
name.AsCString(), symbol_type);
if (Symtab *symtab = GetSymtab())
return symtab->FindFirstSymbolWithNameAndType(
Expand Down Expand Up @@ -1342,9 +1332,7 @@ void Module::SymbolIndicesToSymbolContextList(
void Module::FindFunctionSymbols(ConstString name,
uint32_t name_type_mask,
SymbolContextList &sc_list) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
LLDB_SCOPED_TIMERF("Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
name.AsCString(), name_type_mask);
if (Symtab *symtab = GetSymtab())
symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
Expand All @@ -1355,10 +1343,8 @@ void Module::FindSymbolsWithNameAndType(ConstString name,
SymbolContextList &sc_list) {
// No need to protect this call using m_mutex all other method calls are
// already thread safe.

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(
func_cat, "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
LLDB_SCOPED_TIMERF(
"Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
name.AsCString(), symbol_type);
if (Symtab *symtab = GetSymtab()) {
std::vector<uint32_t> symbol_indexes;
Expand All @@ -1372,10 +1358,7 @@ void Module::FindSymbolsMatchingRegExAndType(const RegularExpression &regex,
SymbolContextList &sc_list) {
// No need to protect this call using m_mutex all other method calls are
// already thread safe.

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(
func_cat,
LLDB_SCOPED_TIMERF(
"Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
regex.GetText().str().c_str(), symbol_type);
if (Symtab *symtab = GetSymtab()) {
Expand Down
6 changes: 2 additions & 4 deletions lldb/source/Initialization/SystemInitializerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ llvm::Error SystemInitializerCommon::Initialize() {
if (error)
return error;

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();

process_gdb_remote::ProcessGDBRemoteLog::Initialize();

Expand All @@ -147,8 +146,7 @@ llvm::Error SystemInitializerCommon::Initialize() {
}

void SystemInitializerCommon::Terminate() {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();

#if defined(_WIN32)
ProcessWindowsLog::Terminate();
Expand Down
10 changes: 3 additions & 7 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ bool CommandInterpreter::GetSpaceReplPrompts() const {
}

void CommandInterpreter::Initialize() {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();

CommandReturnObject result(m_debugger.GetUseColor());

Expand Down Expand Up @@ -487,8 +486,7 @@ const char *CommandInterpreter::ProcessEmbeddedScriptCommands(const char *arg) {
m_command_dict[NAME] = std::make_shared<CLASS>(*this);

void CommandInterpreter::LoadCommandDictionary() {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();

REGISTER_COMMAND_OBJECT("apropos", CommandObjectApropos);
REGISTER_COMMAND_OBJECT("breakpoint", CommandObjectMultiwordBreakpoint);
Expand Down Expand Up @@ -1649,9 +1647,7 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
command_line);

LLDB_LOGF(log, "Processing command: %s", command_line);

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "Handling command: %s.", command_line);
LLDB_SCOPED_TIMERF("Processing command: %s.", command_line);

if (!no_context_switching)
UpdateExecutionContext(override_context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ line_entry_helper(Target &target, const SymbolContext &sc, Symbol *symbol,
CPPLanguageRuntime::LibCppStdFunctionCallableInfo
CPPLanguageRuntime::FindLibCppStdFunctionCallableInfo(
lldb::ValueObjectSP &valobj_sp) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"CPPLanguageRuntime::FindLibCppStdFunctionCallableInfo");
LLDB_SCOPED_TIMER();

LibCppStdFunctionCallableInfo optional_info;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1831,10 +1831,9 @@ lldb::addr_t AppleObjCRuntimeV2::GetSharedCacheReadOnlyAddress() {
}

void AppleObjCRuntimeV2::UpdateISAToDescriptorMapIfNeeded() {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_TYPES));
LLDB_SCOPED_TIMER();

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_TYPES));

// Else we need to check with our process to see when the map was updated.
Process *process = GetProcess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ ObjectContainer *ObjectContainerBSDArchive::CreateInstance(
DataExtractor data;
data.SetData(data_sp, data_offset, length);
if (file && data_sp && ObjectContainerBSDArchive::MagicBytesMatch(data)) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(
func_cat,
LLDB_SCOPED_TIMERF(
"ObjectContainerBSDArchive::CreateInstance (module = %s, file = "
"%p, file_offset = 0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")",
module_sp->GetFileSpec().GetPath().c_str(),
Expand Down
4 changes: 1 addition & 3 deletions lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,7 @@ size_t ObjectFileELF::GetModuleSpecifications(
uint32_t core_notes_crc = 0;

if (!gnu_debuglink_crc) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
lldb_private::Timer scoped_timer(
func_cat,
LLDB_SCOPED_TIMERF(
"Calculating module crc32 %s with size %" PRIu64 " KiB",
file.GetLastPathComponent().AsCString(),
(length - file_offset) / 1024);
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2161,8 +2161,7 @@ ParseNList(DataExtractor &nlist_data, lldb::offset_t &nlist_data_offset,
enum { DebugSymbols = true, NonDebugSymbols = false };

size_t ObjectFileMachO::ParseSymtab() {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "ObjectFileMachO::ParseSymtab () module = %s",
LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s",
m_file.GetFilename().AsCString(""));
ModuleSP module_sp(GetModule());
if (!module_sp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ bool ScriptInterpreterLua::ExecuteOneLine(llvm::StringRef command,
}

void ScriptInterpreterLua::ExecuteInterpreterLoop() {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();

// At the moment, the only time the debugger does not have an input file
// handle is when this is called directly from lua, in which case it is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,7 @@ bool ScriptInterpreterPythonImpl::ExecuteOneLine(
}

void ScriptInterpreterPythonImpl::ExecuteInterpreterLoop() {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();

Debugger &debugger = m_debugger;

Expand Down Expand Up @@ -2220,8 +2219,7 @@ bool ScriptInterpreterPythonImpl::GetScriptedSummary(
StructuredData::ObjectSP &callee_wrapper_sp,
const TypeSummaryOptions &options, std::string &retval) {

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();

if (!valobj.get()) {
retval.assign("<no object>");
Expand Down Expand Up @@ -3240,8 +3238,7 @@ void ScriptInterpreterPythonImpl::InitializePrivate() {

g_initialized = true;

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
LLDB_SCOPED_TIMER();

// RAII-based initialization which correctly handles multiple-initialization,
// version- specific differences among Python 2 and Python 3, and saving and
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ void DWARFDebugAranges::AppendRange(dw_offset_t offset, dw_addr_t low_pc,
}

void DWARFDebugAranges::Sort(bool minimize) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
LLDB_SCOPED_TIMERF("%s this = %p", LLVM_PRETTY_FUNCTION,
static_cast<void *>(this));

m_aranges.Sort();
Expand Down
8 changes: 2 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ void DWARFUnit::ExtractUnitDIEIfNeeded() {
if (m_first_die)
return; // Already parsed

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "%8.8x: DWARFUnit::ExtractUnitDIEIfNeeded()",
GetOffset());
LLDB_SCOPED_TIMERF("%8.8x: DWARFUnit::ExtractUnitDIEIfNeeded()", GetOffset());

// Set the offset to that of the first DIE and calculate the start of the
// next compilation unit header.
Expand Down Expand Up @@ -145,9 +143,7 @@ DWARFUnit::ScopedExtractDIEs &DWARFUnit::ScopedExtractDIEs::operator=(
void DWARFUnit::ExtractDIEsRWLocked() {
llvm::sys::ScopedWriter first_die_lock(m_first_die_mutex);

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "%8.8x: DWARFUnit::ExtractDIEsIfNeeded()",
GetOffset());
LLDB_SCOPED_TIMERF("%8.8x: DWARFUnit::ExtractDIEsIfNeeded()", GetOffset());

// Set the offset to that of the first DIE and calculate the start of the
// next compilation unit header.
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ void ManualDWARFIndex::Index() {
SymbolFileDWARF &main_dwarf = *m_dwarf;
m_dwarf = nullptr;

static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "%p", static_cast<void *>(&main_dwarf));
LLDB_SCOPED_TIMERF("%p", static_cast<void *>(&main_dwarf));

DWARFDebugInfo &main_info = main_dwarf.DebugInfo();
SymbolFileDWARFDwo *dwp_dwarf = main_dwarf.GetDwpSymbolFile().get();
Expand Down
Loading

0 comments on commit 5c1c844

Please sign in to comment.