Skip to content

Commit c87abd7

Browse files
Merge pull request #3000 from adrian-prantl/76070796-next
Sprinkle scoped timer support all over the Swift language binding.
2 parents 95555b2 + 2ab6ed9 commit c87abd7

File tree

8 files changed

+151
-22
lines changed

8 files changed

+151
-22
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- SwiftExpressionParser.cpp -------------------------------*- C++ -*-===//
1+
//===-- SwiftExpressionParser.cpp ---------------------------------------*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -39,6 +39,7 @@
3939
#include "lldb/Target/Thread.h"
4040
#include "lldb/Utility/Log.h"
4141
#include "lldb/Utility/Stream.h"
42+
#include "lldb/Utility/Timer.h"
4243

4344
#include "llvm-c/Analysis.h"
4445
#include "llvm/ADT/ArrayRef.h"
@@ -254,6 +255,7 @@ class LLDBExprNameLookup : public LLDBNameLookup {
254255
bool lookupAdditions(swift::DeclBaseName Name, swift::DeclContext *DC,
255256
swift::SourceLoc Loc, bool IsTypeLookup,
256257
ResultVector &RV) override {
258+
LLDB_SCOPED_TIMER();
257259
static unsigned counter = 0;
258260
unsigned count = counter++;
259261

@@ -397,6 +399,7 @@ class LLDBREPLNameLookup : public LLDBNameLookup {
397399
bool lookupAdditions(swift::DeclBaseName Name, swift::DeclContext *DC,
398400
swift::SourceLoc Loc, bool IsTypeLookup,
399401
ResultVector &RV) override {
402+
LLDB_SCOPED_TIMER();
400403
static unsigned counter = 0;
401404
unsigned count = counter++;
402405

@@ -447,6 +450,7 @@ class LLDBREPLNameLookup : public LLDBNameLookup {
447450
static CompilerType GetSwiftTypeForVariableValueObject(
448451
lldb::ValueObjectSP valobj_sp, lldb::StackFrameSP &stack_frame_sp,
449452
SwiftLanguageRuntime *runtime) {
453+
LLDB_SCOPED_TIMER();
450454
// Check that the passed ValueObject is valid.
451455
if (!valobj_sp || valobj_sp->GetError().Fail())
452456
return {};
@@ -470,6 +474,7 @@ static CompilerType GetSwiftTypeForVariableValueObject(
470474
static CompilerType ResolveVariable(
471475
lldb::VariableSP variable_sp, lldb::StackFrameSP &stack_frame_sp,
472476
SwiftLanguageRuntime * runtime, lldb::DynamicValueType use_dynamic) {
477+
LLDB_SCOPED_TIMER();
473478
lldb::ValueObjectSP valobj_sp =
474479
stack_frame_sp->GetValueObjectForFrameVariable(variable_sp,
475480
lldb::eNoDynamicValues);
@@ -496,6 +501,8 @@ static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
496501
SwiftASTContextForExpressions &swift_ast_context,
497502
SwiftASTManipulator &manipulator,
498503
lldb::DynamicValueType use_dynamic) {
504+
LLDB_SCOPED_TIMER();
505+
499506
// First emit the typealias for "$__lldb_context".
500507
if (!block)
501508
return;
@@ -640,6 +647,8 @@ static llvm::Optional<llvm::Error> AddVariableInfo(
640647
llvm::SmallDenseSet<const char *, 8> &processed_variables,
641648
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables,
642649
lldb::DynamicValueType use_dynamic) {
650+
LLDB_SCOPED_TIMER();
651+
643652
StringRef name = variable_sp->GetUnqualifiedName().GetStringRef();
644653
const char *name_cstr = name.data();
645654
assert(StringRef(name_cstr) == name && "missing null terminator");
@@ -739,6 +748,7 @@ static llvm::Optional<llvm::Error> RegisterAllVariables(
739748
SwiftASTContextForExpressions &ast_context,
740749
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables,
741750
lldb::DynamicValueType use_dynamic) {
751+
LLDB_SCOPED_TIMER();
742752
if (!sc.block && !sc.function)
743753
return {};
744754

@@ -808,7 +818,8 @@ static void ResolveSpecialNames(
808818
llvm::SmallVectorImpl<swift::Identifier> &special_names,
809819
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables) {
810820
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
811-
821+
LLDB_SCOPED_TIMER();
822+
812823
if (!sc.target_sp)
813824
return;
814825

@@ -1011,6 +1022,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
10111022
lldb::StackFrameWP &stack_frame_wp,
10121023
DiagnosticManager &diagnostic_manager, Log *log,
10131024
bool repl) {
1025+
LLDB_SCOPED_TIMER();
10141026
uint64_t offset = 0;
10151027
bool needs_init = false;
10161028

@@ -1216,6 +1228,7 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
12161228
ExecutionContextScope &exe_scope, const EvaluateExpressionOptions &options,
12171229
bool repl, bool playground) {
12181230
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
1231+
LLDB_SCOPED_TIMER();
12191232

12201233
auto should_disable_objc_runtime = [&]() {
12211234
lldb::StackFrameSP this_frame_sp(stack_frame_wp.lock());
@@ -1445,6 +1458,7 @@ bool SwiftExpressionParser::Complete(CompletionRequest &request, unsigned line,
14451458
unsigned SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
14461459
uint32_t first_line, uint32_t last_line) {
14471460
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
1461+
LLDB_SCOPED_TIMER();
14481462

14491463
SwiftExpressionParser::SILVariableMap variable_map;
14501464
auto *swift_ast_ctx = m_swift_ast_context->get();
@@ -1811,6 +1825,7 @@ unsigned SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
18111825
static bool FindFunctionInModule(ConstString &mangled_name,
18121826
llvm::Module *module, const char *orig_name,
18131827
bool exact) {
1828+
LLDB_SCOPED_TIMER();
18141829
swift::Demangle::Context demangle_ctx;
18151830
for (llvm::Module::iterator fi = module->getFunctionList().begin(),
18161831
fe = module->getFunctionList().end();
@@ -1864,6 +1879,7 @@ Status SwiftExpressionParser::PrepareForExecution(
18641879
lldb::addr_t &func_addr, lldb::addr_t &func_end,
18651880
lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx,
18661881
bool &can_interpret, ExecutionPolicy execution_policy) {
1882+
LLDB_SCOPED_TIMER();
18671883
Status err;
18681884
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
18691885

@@ -1923,6 +1939,7 @@ Status SwiftExpressionParser::PrepareForExecution(
19231939

19241940
bool SwiftExpressionParser::RewriteExpression(
19251941
DiagnosticManager &diagnostic_manager) {
1942+
LLDB_SCOPED_TIMER();
19261943
// There isn't a Swift equivalent to clang::Rewriter, so we'll just
19271944
// use that.
19281945
auto *swift_ast_ctx = m_swift_ast_context->get();

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "lldb/Symbol/VariableList.h"
3333
#include "lldb/Utility/LLDBAssert.h"
3434
#include "lldb/Utility/Log.h"
35+
#include "lldb/Utility/Timer.h"
3536

3637
#include "swift/AST/Type.h"
3738
#include "swift/AST/Types.h"
@@ -160,6 +161,7 @@ findSwiftSelf(StackFrame &frame, lldb::VariableSP self_var_sp) {
160161
void SwiftUserExpression::ScanContext(ExecutionContext &exe_ctx, Status &err) {
161162
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
162163
LLDB_LOG(log, "SwiftUserExpression::ScanContext()");
164+
LLDB_SCOPED_TIMER();
163165

164166
m_target = exe_ctx.GetTargetPtr();
165167
if (!m_target) {
@@ -275,6 +277,7 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,
275277
bool keep_result_in_memory,
276278
bool generate_debug_info) {
277279
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
280+
LLDB_SCOPED_TIMER();
278281

279282
Status err;
280283

@@ -504,6 +507,7 @@ bool SwiftUserExpression::AddArguments(ExecutionContext &exe_ctx,
504507

505508
lldb::ExpressionVariableSP SwiftUserExpression::GetResultAfterDematerialization(
506509
ExecutionContextScope *exe_scope) {
510+
LLDB_SCOPED_TIMER();
507511
lldb::ExpressionVariableSP in_result_sp = m_result_delegate.GetVariable();
508512
lldb::ExpressionVariableSP in_error_sp = m_error_delegate.GetVariable();
509513

lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Target/Process.h"
1919
#include "lldb/Utility/DataBufferHeap.h"
2020
#include "lldb/Utility/Status.h"
21+
#include "lldb/Utility/Timer.h"
2122
#include "swift/AST/Types.h"
2223
#include "swift/Demangling/ManglingMacros.h"
2324
#include "llvm/ADT/Optional.h"
@@ -96,6 +97,7 @@ bool lldb_private::formatters::swift::StringGuts_SummaryProvider(
9697
ValueObject &valobj, Stream &stream,
9798
const TypeSummaryOptions &summary_options,
9899
StringPrinter::ReadStringAndDumpToStreamOptions read_options) {
100+
LLDB_SCOPED_TIMER();
99101

100102
static ConstString g__object("_object");
101103
static ConstString g__storage("_storage");
@@ -379,6 +381,8 @@ bool lldb_private::formatters::swift::StaticString_SummaryProvider(
379381
ValueObject &valobj, Stream &stream,
380382
const TypeSummaryOptions &summary_options,
381383
StringPrinter::ReadStringAndDumpToStreamOptions read_options) {
384+
LLDB_SCOPED_TIMER();
385+
382386
static ConstString g__startPtrOrData("_startPtrOrData");
383387
static ConstString g__byteSize("_utf8CodeUnitCount");
384388
static ConstString g__flags("_flags");
@@ -433,6 +437,7 @@ bool lldb_private::formatters::swift::SwiftSharedString_SummaryProvider_2(
433437
ValueObject &valobj, Stream &stream,
434438
const TypeSummaryOptions &summary_options,
435439
StringPrinter::ReadStringAndDumpToStreamOptions read_options) {
440+
LLDB_SCOPED_TIMER();
436441
ProcessSP process(valobj.GetProcessSP());
437442
if (!process)
438443
return false;
@@ -461,6 +466,7 @@ bool lldb_private::formatters::swift::SwiftSharedString_SummaryProvider_2(
461466

462467
bool lldb_private::formatters::swift::SwiftStringStorage_SummaryProvider(
463468
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
469+
LLDB_SCOPED_TIMER();
464470
ProcessSP process(valobj.GetProcessSP());
465471
if (!process)
466472
return false;
@@ -531,6 +537,7 @@ bool lldb_private::formatters::swift::DarwinBoolean_SummaryProvider(
531537
static bool RangeFamily_SummaryProvider(ValueObject &valobj, Stream &stream,
532538
const TypeSummaryOptions &options,
533539
bool isHalfOpen) {
540+
LLDB_SCOPED_TIMER();
534541
static ConstString g_lowerBound("lowerBound");
535542
static ConstString g_upperBound("upperBound");
536543

@@ -665,6 +672,7 @@ lldb_private::formatters::swift::EnumSyntheticFrontEndCreator(
665672

666673
bool lldb_private::formatters::swift::ObjC_Selector_SummaryProvider(
667674
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
675+
LLDB_SCOPED_TIMER();
668676
static ConstString g_ptr("ptr");
669677
static ConstString g__rawValue("_rawValue");
670678

@@ -811,6 +819,7 @@ bool PrintTypePreservingNSNumber(DataBufferSP buffer_sp, ProcessSP process_sp,
811819

812820
bool lldb_private::formatters::swift::TypePreservingNSNumber_SummaryProvider(
813821
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
822+
LLDB_SCOPED_TIMER();
814823
lldb::addr_t ptr_value(valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS));
815824
if (ptr_value == LLDB_INVALID_ADDRESS)
816825
return false;
@@ -995,6 +1004,8 @@ void PrintMatrix(Stream &stream,
9951004

9961005
bool lldb_private::formatters::swift::SIMDVector_SummaryProvider(
9971006
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
1007+
LLDB_SCOPED_TIMER();
1008+
9981009
// SIMD vector contains an inner member `_storage` which is an opaque
9991010
// container. Given SIMD is always in the form SIMDX<Type> where X is a
10001011
// positive integer, we can calculate the number of elements and the
@@ -1064,6 +1075,8 @@ bool lldb_private::formatters::swift::SIMDVector_SummaryProvider(
10641075

10651076
bool lldb_private::formatters::swift::LegacySIMD_SummaryProvider(
10661077
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
1078+
LLDB_SCOPED_TIMER();
1079+
10671080
Status error;
10681081
ProcessSP process_sp(valobj.GetProcessSP());
10691082
if (!process_sp)
@@ -1148,6 +1161,8 @@ bool lldb_private::formatters::swift::LegacySIMD_SummaryProvider(
11481161

11491162
bool lldb_private::formatters::swift::GLKit_SummaryProvider(
11501163
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
1164+
LLDB_SCOPED_TIMER();
1165+
11511166
// Get the type name without the "GLKit." prefix.
11521167
ConstString full_type_name = valobj.GetTypeName();
11531168
llvm::StringRef type_name = full_type_name.GetStringRef();

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "lldb/Target/RegisterContext.h"
3333
#include "lldb/Utility/Log.h"
3434
#include "lldb/Utility/OptionParsing.h"
35+
#include "lldb/Utility/Timer.h"
3536

3637
#include "swift/AST/ASTMangler.h"
3738
#include "swift/AST/Decl.h"
@@ -418,6 +419,8 @@ SwiftLanguageRuntimeImpl::GetReflectionContext() {
418419
}
419420

420421
void SwiftLanguageRuntimeImpl::SetupReflection() {
422+
LLDB_SCOPED_TIMER();
423+
421424
// SetupABIBit() iterates of the Target's images and thus needs to
422425
// acquire that ModuleList's lock. We need to acquire this before
423426
// locking m_add_module_mutex, since ModulesDidLoad can also be
@@ -2370,7 +2373,8 @@ UnwindPlanSP
23702373
SwiftLanguageRuntime::GetRuntimeUnwindPlan(ProcessSP process_sp,
23712374
RegisterContext *regctx,
23722375
bool &behaves_like_zeroth_frame) {
2373-
2376+
LLDB_SCOPED_TIMER();
2377+
23742378
Target &target(process_sp->GetTarget());
23752379
auto arch = target.GetArchitecture();
23762380
llvm::Optional<AsyncUnwindRegisterNumbers> regnums =
@@ -2527,7 +2531,8 @@ SwiftLanguageRuntime::GetRuntimeUnwindPlan(ProcessSP process_sp,
25272531
static UnwindPlanSP
25282532
GetFollowAsyncContextUnwindPlan(RegisterContext *regctx, ArchSpec &arch,
25292533
bool &behaves_like_zeroth_frame) {
2530-
2534+
LLDB_SCOPED_TIMER();
2535+
25312536
UnwindPlan::RowSP row(new UnwindPlan::Row);
25322537
const int32_t ptr_size = 8;
25332538
row->SetOffset(0);

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
#include "SwiftLanguageRuntimeImpl.h"
1414
#include "SwiftLanguageRuntime.h"
1515

16-
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
1716
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
17+
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
1818
#include "lldb/Symbol/Function.h"
1919
#include "lldb/Symbol/Variable.h"
2020
#include "lldb/Symbol/VariableList.h"
2121
#include "lldb/Target/ProcessStructReader.h"
2222
#include "lldb/Target/Target.h"
23+
#include "lldb/Utility/Timer.h"
2324
#include "swift/AST/Types.h"
2425

2526
#include "swift/AST/ASTContext.h"
@@ -938,6 +939,7 @@ llvm::Optional<uint64_t> SwiftLanguageRuntimeImpl::GetMemberVariableOffsetRemote
938939
llvm::Optional<uint64_t> SwiftLanguageRuntimeImpl::GetMemberVariableOffset(
939940
CompilerType instance_type, ValueObject *instance,
940941
llvm::StringRef member_name, Status *error) {
942+
LLDB_SCOPED_TIMER();
941943
llvm::Optional<uint64_t> offset;
942944

943945
if (!instance_type.IsValid())
@@ -1031,7 +1033,8 @@ static CompilerType GetWeakReferent(TypeSystemSwiftTypeRef &ts,
10311033
llvm::Optional<unsigned>
10321034
SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
10331035
ValueObject *valobj) {
1034-
auto *ts = llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(
1036+
LLDB_SCOPED_TIMER();
1037+
auto *ts = llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(
10351038
type.GetTypeSystem());
10361039
if (!ts)
10371040
return {};
@@ -1273,6 +1276,7 @@ llvm::Optional<std::string> SwiftLanguageRuntimeImpl::GetEnumCaseName(
12731276
llvm::Optional<size_t> SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
12741277
CompilerType type, llvm::StringRef name, ExecutionContext *exe_ctx,
12751278
bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
1279+
LLDB_SCOPED_TIMER();
12761280
auto *ts =
12771281
llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(type.GetTypeSystem());
12781282
if (!ts)
@@ -1949,6 +1953,7 @@ CompilerType
19491953
SwiftLanguageRuntimeImpl::BindGenericTypeParameters(StackFrame &stack_frame,
19501954
TypeSystemSwiftTypeRef &ts,
19511955
ConstString mangled_name) {
1956+
LLDB_SCOPED_TIMER();
19521957
using namespace swift::Demangle;
19531958

19541959
Status error;
@@ -2046,7 +2051,8 @@ SwiftLanguageRuntimeImpl::BindGenericTypeParameters(StackFrame &stack_frame,
20462051
CompilerType
20472052
SwiftLanguageRuntimeImpl::BindGenericTypeParameters(StackFrame &stack_frame,
20482053
CompilerType base_type) {
2049-
auto &target = m_process.GetTarget();
2054+
LLDB_SCOPED_TIMER();
2055+
auto &target = m_process.GetTarget();
20502056
assert(IsScratchContextLocked(target) &&
20512057
"Swift scratch context not locked ahead of archetype binding");
20522058

@@ -2514,6 +2520,8 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
25142520
if (use_dynamic == lldb::eNoDynamicValues)
25152521
return false;
25162522

2523+
LLDB_SCOPED_TIMER();
2524+
25172525
// Try to import a Clang type into Swift.
25182526
if (in_value.GetObjectRuntimeLanguage() == eLanguageTypeObjC)
25192527
return GetDynamicTypeAndAddress_ClangType(

0 commit comments

Comments
 (0)