diff options
Diffstat (limited to 'lldb/source/Core')
-rw-r--r-- | lldb/source/Core/Disassembler.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Core/Mangled.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Core/Module.cpp | 34 | ||||
-rw-r--r-- | lldb/source/Core/Timer.cpp | 71 |
4 files changed, 56 insertions, 57 deletions
diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp index eb79022c43a..0a5d763b6d3 100644 --- a/lldb/source/Core/Disassembler.cpp +++ b/lldb/source/Core/Disassembler.cpp @@ -59,7 +59,8 @@ using namespace lldb_private; DisassemblerSP Disassembler::FindPlugin(const ArchSpec &arch, const char *flavor, const char *plugin_name) { - Timer scoped_timer(LLVM_PRETTY_FUNCTION, + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, "Disassembler::FindPlugin (arch = %s, plugin_name = %s)", arch.GetArchitectureName(), plugin_name); @@ -1460,4 +1461,3 @@ std::function<bool(const Instruction::Operand &)> lldb_private::OperandMatchers::MatchOpType(Instruction::Operand::Type type) { return [type](const Instruction::Operand &op) { return op.m_type == type; }; } - diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp index 3d96340b911..c2e9b8904a0 100644 --- a/lldb/source/Core/Mangled.cpp +++ b/lldb/source/Core/Mangled.cpp @@ -258,8 +258,8 @@ Mangled::GetDemangledName(lldb::LanguageType language) const { // haven't already decoded our mangled name. if (m_mangled && !m_demangled) { // We need to generate and cache the demangled name. - Timer scoped_timer(LLVM_PRETTY_FUNCTION, - "Mangled::GetDemangledName (m_mangled = %s)", + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, "Mangled::GetDemangledName (m_mangled = %s)", m_mangled.GetCString()); Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DEMANGLE); diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 0de866ac8a2..1b510d2ff7b 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -429,8 +429,8 @@ void Module::DumpSymbolContext(Stream *s) { size_t Module::GetNumCompileUnits() { std::lock_guard<std::recursive_mutex> guard(m_mutex); - Timer scoped_timer(LLVM_PRETTY_FUNCTION, - "Module::GetNumCompileUnits (module = %p)", + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, "Module::GetNumCompileUnits (module = %p)", static_cast<void *>(this)); SymbolVendor *symbols = GetSymbolVendor(); if (symbols) @@ -453,7 +453,8 @@ 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); - Timer scoped_timer(LLVM_PRETTY_FUNCTION, + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr); SectionList *section_list = GetSectionList(); @@ -616,7 +617,8 @@ uint32_t Module::ResolveSymbolContextsForFileSpec(const FileSpec &file_spec, uint32_t resolve_scope, SymbolContextList &sc_list) { std::lock_guard<std::recursive_mutex> guard(m_mutex); - Timer scoped_timer(LLVM_PRETTY_FUNCTION, + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, "Module::ResolveSymbolContextForFilePath (%s:%u, " "check_inlines = %s, resolve_scope = 0x%8.8x)", file_spec.GetPath().c_str(), line, @@ -987,7 +989,8 @@ size_t Module::FindTypes_Impl( const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, TypeMap &types) { - Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION); + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); if (!sc.module_sp || sc.module_sp.get() == this) { SymbolVendor *symbols = GetSymbolVendor(); if (symbols) @@ -1078,7 +1081,8 @@ SymbolVendor *Module::GetSymbolVendor(bool can_create, if (!m_did_load_symbol_vendor.load() && can_create) { ObjectFile *obj_file = GetObjectFile(); if (obj_file != nullptr) { - Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION); + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); m_symfile_ap.reset( SymbolVendor::FindPlugin(shared_from_this(), feedback_strm)); m_did_load_symbol_vendor = true; @@ -1278,8 +1282,8 @@ ObjectFile *Module::GetObjectFile() { if (!m_did_load_objfile.load()) { std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!m_did_load_objfile.load()) { - Timer scoped_timer(LLVM_PRETTY_FUNCTION, - "Module::GetObjectFile () module = %s", + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString("")); DataBufferSP data_sp; lldb::offset_t data_offset = 0; @@ -1338,9 +1342,9 @@ SectionList *Module::GetUnifiedSectionList() { const Symbol *Module::FindFirstSymbolWithNameAndType(const ConstString &name, SymbolType symbol_type) { + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer( - LLVM_PRETTY_FUNCTION, - "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)", + func_cat, "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)", name.AsCString(), symbol_type); SymbolVendor *sym_vendor = GetSymbolVendor(); if (sym_vendor) { @@ -1372,7 +1376,8 @@ void Module::SymbolIndicesToSymbolContextList( size_t Module::FindFunctionSymbols(const ConstString &name, uint32_t name_type_mask, SymbolContextList &sc_list) { - Timer scoped_timer(LLVM_PRETTY_FUNCTION, + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)", name.AsCString(), name_type_mask); SymbolVendor *sym_vendor = GetSymbolVendor(); @@ -1390,9 +1395,9 @@ size_t Module::FindSymbolsWithNameAndType(const ConstString &name, // 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( - LLVM_PRETTY_FUNCTION, - "Module::FindSymbolsWithNameAndType (name = %s, type = %i)", + func_cat, "Module::FindSymbolsWithNameAndType (name = %s, type = %i)", name.AsCString(), symbol_type); const size_t initial_size = sc_list.GetSize(); SymbolVendor *sym_vendor = GetSymbolVendor(); @@ -1413,8 +1418,9 @@ size_t Module::FindSymbolsMatchingRegExAndType(const RegularExpression ®ex, // 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( - LLVM_PRETTY_FUNCTION, + func_cat, "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)", regex.GetText().str().c_str(), symbol_type); const size_t initial_size = sc_list.GetSize(); diff --git a/lldb/source/Core/Timer.cpp b/lldb/source/Core/Timer.cpp index 60da39b7f19..6de4516f721 100644 --- a/lldb/source/Core/Timer.cpp +++ b/lldb/source/Core/Timer.cpp @@ -27,8 +27,8 @@ using namespace lldb_private; #define TIMER_INDENT_AMOUNT 2 namespace { -typedef std::map<const char *, std::chrono::nanoseconds> TimerCategoryMap; typedef std::vector<Timer *> TimerStack; +static std::atomic<Timer::Category *> g_categories; } // end of anonymous namespace std::atomic<bool> Timer::g_quiet(true); @@ -38,16 +38,6 @@ static std::mutex &GetFileMutex() { return *g_file_mutex_ptr; } -static std::mutex &GetCategoryMutex() { - static std::mutex g_category_mutex; - return g_category_mutex; -} - -static TimerCategoryMap &GetCategoryMap() { - static TimerCategoryMap g_category_map; - return g_category_map; -} - static void ThreadSpecificCleanup(void *p) { delete static_cast<TimerStack *>(p); } @@ -64,9 +54,17 @@ static TimerStack *GetTimerStackForCurrentThread() { return (TimerStack *)timer_stack; } +Timer::Category::Category(const char *cat) : m_name(cat) { + m_nanos.store(0, std::memory_order_release); + Category *expected = g_categories; + do { + m_next = expected; + } while (!g_categories.compare_exchange_weak(expected, this)); +} + void Timer::SetQuiet(bool value) { g_quiet = value; } -Timer::Timer(const char *category, const char *format, ...) +Timer::Timer(Timer::Category &category, const char *format, ...) : m_category(category), m_total_start(std::chrono::steady_clock::now()) { TimerStack *stack = GetTimerStackForCurrentThread(); if (!stack) @@ -114,11 +112,7 @@ Timer::~Timer() { stack->back()->ChildDuration(total_dur); // Keep total results for each category so we can dump results. - { - std::lock_guard<std::mutex> guard(GetCategoryMutex()); - TimerCategoryMap &category_map = GetCategoryMap(); - category_map[m_category] += timer_dur; - } + m_category.m_nanos += std::chrono::nanoseconds(timer_dur).count(); } void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; } @@ -126,33 +120,32 @@ void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; } /* binary function predicate: * - returns whether a person is less than another person */ -static bool -CategoryMapIteratorSortCriterion(const TimerCategoryMap::const_iterator &lhs, - const TimerCategoryMap::const_iterator &rhs) { - return lhs->second > rhs->second; + +typedef std::pair<const char *, uint64_t> TimerEntry; + +static bool CategoryMapIteratorSortCriterion(const TimerEntry &lhs, + const TimerEntry &rhs) { + return lhs.second > rhs.second; } void Timer::ResetCategoryTimes() { - std::lock_guard<std::mutex> guard(GetCategoryMutex()); - TimerCategoryMap &category_map = GetCategoryMap(); - category_map.clear(); + for (Category *i = g_categories; i; i = i->m_next) + i->m_nanos.store(0, std::memory_order_release); } void Timer::DumpCategoryTimes(Stream *s) { - std::lock_guard<std::mutex> guard(GetCategoryMutex()); - TimerCategoryMap &category_map = GetCategoryMap(); - std::vector<TimerCategoryMap::const_iterator> sorted_iterators; - TimerCategoryMap::const_iterator pos, end = category_map.end(); - for (pos = category_map.begin(); pos != end; ++pos) { - sorted_iterators.push_back(pos); - } - std::sort(sorted_iterators.begin(), sorted_iterators.end(), - CategoryMapIteratorSortCriterion); - - const size_t count = sorted_iterators.size(); - for (size_t i = 0; i < count; ++i) { - const auto timer = sorted_iterators[i]->second; - s->Printf("%.9f sec for %s\n", std::chrono::duration<double>(timer).count(), - sorted_iterators[i]->first); + std::vector<TimerEntry> sorted; + for (Category *i = g_categories; i; i = i->m_next) { + uint64_t nanos = i->m_nanos.load(std::memory_order_acquire); + if (nanos) + sorted.push_back(std::make_pair(i->m_name, nanos)); } + if (sorted.empty()) + return; // Later code will break without any elements. + + // Sort by time + std::sort(sorted.begin(), sorted.end(), CategoryMapIteratorSortCriterion); + + for (const auto &timer : sorted) + s->Printf("%.9f sec for %s\n", timer.second / 1000000000., timer.first); } |