003 File Manager
Current Path:
/usr/src/contrib/llvm-project/lldb/source/Utility
usr
/
src
/
contrib
/
llvm-project
/
lldb
/
source
/
Utility
/
📁
..
📄
ARM64_DWARF_Registers.h
(1.68 KB)
📄
ARM64_ehframe_Registers.h
(1.74 KB)
📄
ARM_DWARF_Registers.h
(3.21 KB)
📄
ARM_ehframe_Registers.h
(907 B)
📄
ArchSpec.cpp
(51.71 KB)
📄
Args.cpp
(20.02 KB)
📄
Baton.cpp
(630 B)
📄
Broadcaster.cpp
(14.94 KB)
📄
CompletionRequest.cpp
(3.11 KB)
📄
Connection.cpp
(476 B)
📄
ConstString.cpp
(12.33 KB)
📄
DataBufferHeap.cpp
(2.28 KB)
📄
DataBufferLLVM.cpp
(1.06 KB)
📄
DataEncoder.cpp
(6.17 KB)
📄
DataExtractor.cpp
(35.43 KB)
📄
Environment.cpp
(1.44 KB)
📄
Event.cpp
(8.2 KB)
📄
FileSpec.cpp
(17.66 KB)
📄
GDBRemote.cpp
(5.03 KB)
📄
IOObject.cpp
(537 B)
📄
LLDBAssert.cpp
(1.37 KB)
📄
Listener.cpp
(16.12 KB)
📄
Log.cpp
(10.81 KB)
📄
Logging.cpp
(3.24 KB)
📄
NameMatches.cpp
(1.06 KB)
📄
PPC64LE_DWARF_Registers.h
(4.24 KB)
📄
PPC64_DWARF_Registers.h
(2.6 KB)
📄
ProcessInfo.cpp
(13.29 KB)
📄
RegisterValue.cpp
(23.92 KB)
📄
RegularExpression.cpp
(1.36 KB)
📄
Reproducer.cpp
(8.75 KB)
📄
ReproducerInstrumentation.cpp
(6.84 KB)
📄
Scalar.cpp
(36.74 KB)
📄
SelectHelper.cpp
(7.23 KB)
📄
State.cpp
(2.52 KB)
📄
Status.cpp
(8.34 KB)
📄
Stream.cpp
(11.28 KB)
📄
StreamCallback.cpp
(793 B)
📄
StreamString.cpp
(1.95 KB)
📄
StringExtractor.cpp
(10.19 KB)
📄
StringExtractorGDBRemote.cpp
(17.3 KB)
📄
StringLexer.cpp
(1.79 KB)
📄
StringList.cpp
(5.83 KB)
📄
StructuredData.cpp
(5.11 KB)
📄
TildeExpressionResolver.cpp
(2.54 KB)
📄
Timer.cpp
(4.61 KB)
📄
UUID.cpp
(2.8 KB)
📄
UriParser.cpp
(1.94 KB)
📄
UserID.cpp
(648 B)
📄
UserIDResolver.cpp
(1.34 KB)
📄
UuidCompatibility.h
(648 B)
📄
VASprintf.cpp
(1.55 KB)
📄
VMRange.cpp
(2.1 KB)
📄
XcodeSDK.cpp
(8.26 KB)
Editing: Timer.cpp
//===-- Timer.cpp ---------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// #include "lldb/Utility/Timer.h" #include "lldb/Utility/Stream.h" #include <algorithm> #include <map> #include <mutex> #include <utility> #include <vector> #include <assert.h> #include <inttypes.h> #include <stdarg.h> #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); m_nanos_total.store(0, std::memory_order_release); m_count.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(); m_category.m_nanos_total += std::chrono::nanoseconds(total_dur).count(); m_category.m_count++; } void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; } /* binary function predicate: * - returns whether a person is less than another person */ namespace { struct Stats { const char *name; uint64_t nanos; uint64_t nanos_total; uint64_t count; }; } // namespace static bool CategoryMapIteratorSortCriterion(const Stats &lhs, const Stats &rhs) { return lhs.nanos > rhs.nanos; } void Timer::ResetCategoryTimes() { for (Category *i = g_categories; i; i = i->m_next) { i->m_nanos.store(0, std::memory_order_release); i->m_nanos_total.store(0, std::memory_order_release); i->m_count.store(0, std::memory_order_release); } } void Timer::DumpCategoryTimes(Stream *s) { std::vector<Stats> sorted; for (Category *i = g_categories; i; i = i->m_next) { uint64_t nanos = i->m_nanos.load(std::memory_order_acquire); if (nanos) { uint64_t nanos_total = i->m_nanos_total.load(std::memory_order_acquire); uint64_t count = i->m_count.load(std::memory_order_acquire); Stats stats{i->m_name, nanos, nanos_total, count}; sorted.push_back(stats); } } if (sorted.empty()) return; // Later code will break without any elements. // Sort by time llvm::sort(sorted.begin(), sorted.end(), CategoryMapIteratorSortCriterion); for (const auto &stats : sorted) s->Printf("%.9f sec (total: %.3fs; child: %.3fs; count: %" PRIu64 ") for %s\n", stats.nanos / 1000000000., stats.nanos_total / 1000000000., (stats.nanos_total - stats.nanos) / 1000000000., stats.count, stats.name); }
Upload File
Create Folder