diff options
Diffstat (limited to 'lldb/source/Core')
-rw-r--r-- | lldb/source/Core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/source/Core/Disassembler.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Core/Mangled.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Core/Module.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Core/Timer.cpp | 135 |
5 files changed, 5 insertions, 141 deletions
diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index f541d1407d0..c5105bd9ab1 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -32,7 +32,6 @@ add_lldb_library(lldbCore State.cpp StreamAsynchronousIO.cpp StreamFile.cpp - Timer.cpp UserSettingsController.cpp Value.cpp ValueObject.cpp diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp index 0a5d763b6d3..6d463d552da 100644 --- a/lldb/source/Core/Disassembler.cpp +++ b/lldb/source/Core/Disassembler.cpp @@ -17,7 +17,6 @@ #include "lldb/Core/ModuleList.h" // for ModuleList #include "lldb/Core/PluginManager.h" #include "lldb/Core/SourceManager.h" // for SourceManager -#include "lldb/Core/Timer.h" #include "lldb/Host/FileSystem.h" #include "lldb/Interpreter/OptionValue.h" #include "lldb/Interpreter/OptionValueArray.h" @@ -37,8 +36,9 @@ #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/Status.h" -#include "lldb/Utility/Stream.h" // for Stream -#include "lldb/Utility/StreamString.h" // for StreamString +#include "lldb/Utility/Stream.h" // for Stream +#include "lldb/Utility/StreamString.h" // for StreamString +#include "lldb/Utility/Timer.h" #include "lldb/lldb-private-enumerations.h" // for InstructionType:... #include "lldb/lldb-private-interfaces.h" // for DisassemblerCrea... #include "lldb/lldb-private-types.h" // for RegisterInfo diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp index 4dac0b8f3bf..211a0c32cee 100644 --- a/lldb/source/Core/Mangled.cpp +++ b/lldb/source/Core/Mangled.cpp @@ -27,12 +27,12 @@ #include <cxxabi.h> #endif -#include "lldb/Core/Timer.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Logging.h" #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/Stream.h" +#include "lldb/Utility/Timer.h" #include "lldb/lldb-enumerations.h" // for LanguageType #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 1b510d2ff7b..aaae4700db3 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -17,7 +17,6 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/SearchFilter.h" // for SearchFilt... #include "lldb/Core/Section.h" -#include "lldb/Core/Timer.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -45,6 +44,7 @@ #include "lldb/Utility/Status.h" #include "lldb/Utility/Stream.h" // for Stream #include "lldb/Utility/StreamString.h" +#include "lldb/Utility/Timer.h" #if defined(LLVM_ON_WIN32) #include "lldb/Host/windows/PosixApi.h" // for PATH_MAX diff --git a/lldb/source/Core/Timer.cpp b/lldb/source/Core/Timer.cpp deleted file mode 100644 index 59c3e13a717..00000000000 --- a/lldb/source/Core/Timer.cpp +++ /dev/null @@ -1,135 +0,0 @@ -//===-- Timer.cpp -----------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#include "lldb/Core/Timer.h" - -#include "lldb/Host/Host.h" -#include "lldb/Utility/Stream.h" -#include "lldb/lldb-types.h" // for thread_key_t - -#include <algorithm> -#include <map> -#include <mutex> -#include <utility> // for pair -#include <vector> - -#include <assert.h> // for assert -#include <stdarg.h> // for va_end, va_list, va_start -#include <stdio.h> - -using namespace lldb_private; - -#define TIMER_INDENT_AMOUNT 2 - -namespace { -typedef std::vector<Timer *> TimerStack; -static std::atomic<Timer::Category *> g_categories; -} // end of anonymous namespace - -std::atomic<bool> Timer::g_quiet(true); -std::atomic<unsigned> Timer::g_display_depth(0); -static std::mutex &GetFileMutex() { - static std::mutex *g_file_mutex_ptr = new std::mutex(); - return *g_file_mutex_ptr; -} - -static TimerStack &GetTimerStackForCurrentThread() { - static thread_local TimerStack g_stack; - return g_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(Timer::Category &category, const char *format, ...) - : m_category(category), m_total_start(std::chrono::steady_clock::now()) { - TimerStack &stack = GetTimerStackForCurrentThread(); - - stack.push_back(this); - if (g_quiet && stack.size() <= g_display_depth) { - std::lock_guard<std::mutex> lock(GetFileMutex()); - - // Indent - ::fprintf(stdout, "%*s", int(stack.size() - 1) * TIMER_INDENT_AMOUNT, ""); - // Print formatted string - va_list args; - va_start(args, format); - ::vfprintf(stdout, format, args); - va_end(args); - - // Newline - ::fprintf(stdout, "\n"); - } -} - -Timer::~Timer() { - using namespace std::chrono; - - auto stop_time = steady_clock::now(); - auto total_dur = stop_time - m_total_start; - auto timer_dur = total_dur - m_child_duration; - - TimerStack &stack = GetTimerStackForCurrentThread(); - if (g_quiet && stack.size() <= g_display_depth) { - std::lock_guard<std::mutex> lock(GetFileMutex()); - ::fprintf(stdout, "%*s%.9f sec (%.9f sec)\n", - int(stack.size() - 1) * TIMER_INDENT_AMOUNT, "", - duration<double>(total_dur).count(), - duration<double>(timer_dur).count()); - } - - assert(stack.back() == this); - stack.pop_back(); - if (!stack.empty()) - stack.back()->ChildDuration(total_dur); - - // Keep total results for each category so we can dump results. - m_category.m_nanos += std::chrono::nanoseconds(timer_dur).count(); -} - -void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; } - -/* binary function predicate: - * - returns whether a person is less than another person - */ - -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() { - 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::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); -} |