Skip to content

Commit c240be4

Browse files
committed
Sprinkle scoped timer support all over the Swift language binding.
The scoped timers translate into Signposts on Darwin and should make performance tracking much easier. rdar://76070796
1 parent 0fbb794 commit c240be4

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");
@@ -735,6 +744,7 @@ static llvm::Optional<llvm::Error> RegisterAllVariables(
735744
SwiftASTContextForExpressions &ast_context,
736745
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables,
737746
lldb::DynamicValueType use_dynamic) {
747+
LLDB_SCOPED_TIMER();
738748
if (!sc.block && !sc.function)
739749
return {};
740750

@@ -804,7 +814,8 @@ static void ResolveSpecialNames(
804814
llvm::SmallVectorImpl<swift::Identifier> &special_names,
805815
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables) {
806816
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
807-
817+
LLDB_SCOPED_TIMER();
818+
808819
if (!sc.target_sp)
809820
return;
810821

@@ -1007,6 +1018,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
10071018
lldb::StackFrameWP &stack_frame_wp,
10081019
DiagnosticManager &diagnostic_manager, Log *log,
10091020
bool repl) {
1021+
LLDB_SCOPED_TIMER();
10101022
uint64_t offset = 0;
10111023
bool needs_init = false;
10121024

@@ -1212,6 +1224,7 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
12121224
ExecutionContextScope &exe_scope, const EvaluateExpressionOptions &options,
12131225
bool repl, bool playground) {
12141226
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
1227+
LLDB_SCOPED_TIMER();
12151228

12161229
auto should_disable_objc_runtime = [&]() {
12171230
lldb::StackFrameSP this_frame_sp(stack_frame_wp.lock());
@@ -1441,6 +1454,7 @@ bool SwiftExpressionParser::Complete(CompletionRequest &request, unsigned line,
14411454
unsigned SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
14421455
uint32_t first_line, uint32_t last_line) {
14431456
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
1457+
LLDB_SCOPED_TIMER();
14441458

14451459
SwiftExpressionParser::SILVariableMap variable_map;
14461460
auto *swift_ast_ctx = m_swift_ast_context->get();
@@ -1807,6 +1821,7 @@ unsigned SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
18071821
static bool FindFunctionInModule(ConstString &mangled_name,
18081822
llvm::Module *module, const char *orig_name,
18091823
bool exact) {
1824+
LLDB_SCOPED_TIMER();
18101825
swift::Demangle::Context demangle_ctx;
18111826
for (llvm::Module::iterator fi = module->getFunctionList().begin(),
18121827
fe = module->getFunctionList().end();
@@ -1860,6 +1875,7 @@ Status SwiftExpressionParser::PrepareForExecution(
18601875
lldb::addr_t &func_addr, lldb::addr_t &func_end,
18611876
lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx,
18621877
bool &can_interpret, ExecutionPolicy execution_policy) {
1878+
LLDB_SCOPED_TIMER();
18631879
Status err;
18641880
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
18651881

@@ -1919,6 +1935,7 @@ Status SwiftExpressionParser::PrepareForExecution(
19191935

19201936
bool SwiftExpressionParser::RewriteExpression(
19211937
DiagnosticManager &diagnostic_manager) {
1938+
LLDB_SCOPED_TIMER();
19221939
// There isn't a Swift equivalent to clang::Rewriter, so we'll just
19231940
// use that.
19241941
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

@@ -506,6 +509,7 @@ bool SwiftUserExpression::AddArguments(ExecutionContext &exe_ctx,
506509

507510
lldb::ExpressionVariableSP SwiftUserExpression::GetResultAfterDematerialization(
508511
ExecutionContextScope *exe_scope) {
512+
LLDB_SCOPED_TIMER();
509513
lldb::ExpressionVariableSP in_result_sp = m_result_delegate.GetVariable();
510514
lldb::ExpressionVariableSP in_error_sp = m_error_delegate.GetVariable();
511515

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
@@ -2175,7 +2178,8 @@ UnwindPlanSP
21752178
SwiftLanguageRuntime::GetRuntimeUnwindPlan(ProcessSP process_sp,
21762179
RegisterContext *regctx,
21772180
bool &behaves_like_zeroth_frame) {
2178-
2181+
LLDB_SCOPED_TIMER();
2182+
21792183
Target &target(process_sp->GetTarget());
21802184
auto arch = target.GetArchitecture();
21812185
llvm::Optional<AsyncUnwindRegisterNumbers> regnums =
@@ -2332,7 +2336,8 @@ SwiftLanguageRuntime::GetRuntimeUnwindPlan(ProcessSP process_sp,
23322336
static UnwindPlanSP
23332337
GetFollowAsyncContextUnwindPlan(RegisterContext *regctx, ArchSpec &arch,
23342338
bool &behaves_like_zeroth_frame) {
2335-
2339+
LLDB_SCOPED_TIMER();
2340+
23362341
UnwindPlan::RowSP row(new UnwindPlan::Row);
23372342
const int32_t ptr_size = 8;
23382343
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)