Skip to content

Commit 2ab6ed9

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 (cherry picked from commit c240be4)
1 parent ab639f6 commit 2ab6ed9

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,6 +4209,7 @@ swift::Identifier SwiftASTContext::GetIdentifier(const llvm::StringRef &name) {
42094209

42104210
ConstString SwiftASTContext::GetMangledTypeName(swift::TypeBase *type_base) {
42114211
VALID_OR_RETURN(ConstString());
4212+
LLDB_SCOPED_TIMER();
42124213

42134214
auto iter = m_type_to_mangled_name_map.find(type_base),
42144215
end = m_type_to_mangled_name_map.end();
@@ -4269,6 +4270,7 @@ SwiftASTContext::GetTypeFromMangledTypename(ConstString mangled_typename) {
42694270
}
42704271

42714272
CompilerType SwiftASTContext::GetAsClangType(ConstString mangled_name) {
4273+
LLDB_SCOPED_TIMER();
42724274
if (!swift::Demangle::isObjCSymbol(mangled_name.GetStringRef()))
42734275
return {};
42744276

@@ -4368,6 +4370,7 @@ swift::TypeBase *SwiftASTContext::ReconstructType(ConstString mangled_typename,
43684370
LOG_PRINTF(LIBLLDB_LOG_TYPES, "(\"%s\") -- not cached, searching",
43694371
mangled_cstr);
43704372

4373+
LLDB_SCOPED_TIMERF("%s (not cached)", LLVM_PRETTY_FUNCTION);
43714374
found_type = swift::Demangle::getTypeForMangling(
43724375
*ast_ctx, mangled_typename.GetStringRef())
43734376
.getPointer();
@@ -4514,6 +4517,7 @@ SwiftASTContext::FindContainedTypeOrDecl(llvm::StringRef name,
45144517
TypeOrDecl container_type_or_decl,
45154518
TypesOrDecls &results, bool append) {
45164519
VALID_OR_RETURN(0);
4520+
LLDB_SCOPED_TIMER();
45174521

45184522
if (!append)
45194523
results.clear();
@@ -4562,7 +4566,7 @@ llvm::Optional<SwiftASTContext::TypeOrDecl>
45624566
SwiftASTContext::FindTypeOrDecl(const char *name,
45634567
swift::ModuleDecl *swift_module) {
45644568
VALID_OR_RETURN(llvm::Optional<SwiftASTContext::TypeOrDecl>());
4565-
4569+
45664570
TypesOrDecls search_results;
45674571

45684572
FindTypesOrDecls(name, swift_module, search_results, false);
@@ -4648,6 +4652,7 @@ size_t SwiftASTContext::FindTypesOrDecls(const char *name,
46484652
size_t SwiftASTContext::FindType(const char *name,
46494653
std::set<CompilerType> &results, bool append) {
46504654
VALID_OR_RETURN(0);
4655+
LLDB_SCOPED_TIMER();
46514656

46524657
if (!append)
46534658
results.clear();
@@ -4675,6 +4680,7 @@ size_t SwiftASTContext::FindType(const char *name,
46754680

46764681
CompilerType SwiftASTContext::ImportType(CompilerType &type, Status &error) {
46774682
VALID_OR_RETURN(CompilerType());
4683+
LLDB_SCOPED_TIMER();
46784684

46794685
if (m_ast_context_ap.get() == NULL)
46804686
return CompilerType();
@@ -4928,6 +4934,7 @@ void SwiftASTContext::AddErrorStatusAsGenericDiagnostic(Status error) {
49284934
void SwiftASTContext::PrintDiagnostics(DiagnosticManager &diagnostic_manager,
49294935
uint32_t bufferID, uint32_t first_line,
49304936
uint32_t last_line) {
4937+
LLDB_SCOPED_TIMER();
49314938
// If this is a fatal error, copy the error into the AST context's
49324939
// fatal error field, and then put it to the stream, otherwise just
49334940
// dump the diagnostics to the stream.
@@ -5241,6 +5248,7 @@ bool SwiftASTContext::IsPossibleDynamicType(opaque_compiler_type_t type,
52415248
bool check_cplusplus,
52425249
bool check_objc) {
52435250
VALID_OR_RETURN_CHECK_TYPE(type, false);
5251+
LLDB_SCOPED_TIMER();
52445252

52455253
auto can_type = GetCanonicalSwiftType(type);
52465254
if (!can_type)
@@ -5340,6 +5348,7 @@ bool SwiftASTContext::IsFullyRealized(const CompilerType &compiler_type) {
53405348

53415349
bool SwiftASTContext::GetProtocolTypeInfo(const CompilerType &type,
53425350
ProtocolInfo &protocol_info) {
5351+
LLDB_SCOPED_TIMER();
53435352
if (swift::CanType swift_can_type = ::GetCanonicalSwiftType(type)) {
53445353
if (!swift_can_type.isExistentialType())
53455354
return false;
@@ -5419,6 +5428,7 @@ SwiftASTContext::GetTypeRefType(lldb::opaque_compiler_type_t type) {
54195428
ConstString SwiftASTContext::GetTypeName(opaque_compiler_type_t type) {
54205429
VALID_OR_RETURN_CHECK_TYPE(
54215430
type, ConstString("<invalid Swift context or opaque type>"));
5431+
LLDB_SCOPED_TIMER();
54225432
std::string type_name;
54235433
swift::Type swift_type(GetSwiftType(type));
54245434

@@ -5442,6 +5452,7 @@ ConstString SwiftASTContext::GetTypeName(opaque_compiler_type_t type) {
54425452
static llvm::DenseMap<swift::CanType, swift::Identifier>
54435453
GetArchetypeNames(swift::Type swift_type, swift::ASTContext &ast_ctx,
54445454
const SymbolContext *sc) {
5455+
LLDB_SCOPED_TIMER();
54455456
llvm::DenseMap<swift::CanType, swift::Identifier> dict;
54465457

54475458
assert(&swift_type->getASTContext() == &ast_ctx);
@@ -5469,6 +5480,7 @@ ConstString SwiftASTContext::GetDisplayTypeName(opaque_compiler_type_t type,
54695480
const SymbolContext *sc) {
54705481
VALID_OR_RETURN_CHECK_TYPE(
54715482
type, ConstString("<invalid Swift context or opaque type>"));
5483+
LLDB_SCOPED_TIMER();
54725484
std::string type_name(GetTypeName(type).AsCString(""));
54735485
if (type) {
54745486
swift::Type swift_type(GetSwiftType(type));
@@ -5487,6 +5499,7 @@ uint32_t
54875499
SwiftASTContext::GetTypeInfo(opaque_compiler_type_t type,
54885500
CompilerType *pointee_or_element_clang_type) {
54895501
VALID_OR_RETURN_CHECK_TYPE(type, 0);
5502+
LLDB_SCOPED_TIMER();
54905503

54915504
if (pointee_or_element_clang_type)
54925505
pointee_or_element_clang_type->Clear();
@@ -5810,6 +5823,7 @@ TypeMemberFunctionImpl
58105823
SwiftASTContext::GetMemberFunctionAtIndex(opaque_compiler_type_t type,
58115824
size_t idx) {
58125825
VALID_OR_RETURN_CHECK_TYPE(type, TypeMemberFunctionImpl());
5826+
LLDB_SCOPED_TIMER();
58135827

58145828
std::string name("");
58155829
CompilerType result_type;
@@ -5983,6 +5997,7 @@ llvm::Optional<uint64_t>
59835997
SwiftASTContext::GetBitSize(opaque_compiler_type_t type,
59845998
ExecutionContextScope *exe_scope) {
59855999
VALID_OR_RETURN_CHECK_TYPE(type, llvm::None);
6000+
LLDB_SCOPED_TIMER();
59866001

59876002
// If the type has type parameters, bind them first.
59886003
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
@@ -6032,6 +6047,7 @@ llvm::Optional<uint64_t>
60326047
SwiftASTContext::GetByteStride(opaque_compiler_type_t type,
60336048
ExecutionContextScope *exe_scope) {
60346049
VALID_OR_RETURN_CHECK_TYPE(type, llvm::None);
6050+
LLDB_SCOPED_TIMER();
60356051

60366052
// If the type has type parameters, bind them first.
60376053
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
@@ -6064,6 +6080,7 @@ llvm::Optional<size_t>
60646080
SwiftASTContext::GetTypeBitAlign(opaque_compiler_type_t type,
60656081
ExecutionContextScope *exe_scope) {
60666082
VALID_OR_RETURN_CHECK_TYPE(type, llvm::None);
6083+
LLDB_SCOPED_TIMER();
60676084

60686085
// If the type has type parameters, bind them first.
60696086
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
@@ -6264,6 +6281,7 @@ uint32_t SwiftASTContext::GetNumChildren(opaque_compiler_type_t type,
62646281
bool omit_empty_base_classes,
62656282
const ExecutionContext *exe_ctx) {
62666283
VALID_OR_RETURN_CHECK_TYPE(type, 0);
6284+
LLDB_SCOPED_TIMER();
62676285

62686286
uint32_t num_children = 0;
62696287

@@ -6605,6 +6623,7 @@ CompilerType SwiftASTContext::GetFieldAtIndex(opaque_compiler_type_t type,
66056623
uint32_t *bitfield_bit_size_ptr,
66066624
bool *is_bitfield_ptr) {
66076625
VALID_OR_RETURN_CHECK_TYPE(type, CompilerType());
6626+
LLDB_SCOPED_TIMER();
66086627

66096628
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
66106629

@@ -6936,6 +6955,7 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex(
69366955
bool &child_is_base_class, bool &child_is_deref_of_parent,
69376956
ValueObject *valobj, uint64_t &language_flags) {
69386957
VALID_OR_RETURN_CHECK_TYPE(type, CompilerType());
6958+
LLDB_SCOPED_TIMER();
69396959

69406960
auto get_type_size = [&exe_ctx](uint32_t &result, CompilerType type) {
69416961
auto *exe_scope =
@@ -7242,6 +7262,7 @@ size_t SwiftASTContext::GetIndexOfChildMemberWithName(
72427262
opaque_compiler_type_t type, const char *name, ExecutionContext *exe_ctx,
72437263
bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
72447264
VALID_OR_RETURN_CHECK_TYPE(type, 0);
7265+
LLDB_SCOPED_TIMER();
72457266

72467267
if (name && name[0]) {
72477268
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
@@ -7607,6 +7628,7 @@ bool SwiftASTContext::DumpTypeValue(
76077628
size_t byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
76087629
ExecutionContextScope *exe_scope, bool is_base_class) {
76097630
VALID_OR_RETURN_CHECK_TYPE(type, false);
7631+
LLDB_SCOPED_TIMER();
76107632

76117633
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
76127634

@@ -7773,7 +7795,7 @@ bool SwiftASTContext::DumpTypeValue(
77737795
bool SwiftASTContext::IsImportedType(opaque_compiler_type_t type,
77747796
CompilerType *original_type) {
77757797
VALID_OR_RETURN_CHECK_TYPE(type, false);
7776-
7798+
LLDB_SCOPED_TIMER();
77777799
bool success = false;
77787800

77797801
if (swift::Type swift_can_type = GetSwiftType(type)) {
@@ -7892,6 +7914,7 @@ void SwiftASTContext::DumpTypeDescription(opaque_compiler_type_t type,
78927914
bool print_help_if_available,
78937915
bool print_extensions_if_available,
78947916
lldb::DescriptionLevel level) {
7917+
LLDB_SCOPED_TIMER();
78957918
const auto initial_written_bytes = s->GetWrittenBytes();
78967919

78977920
if (type) {
@@ -8193,6 +8216,7 @@ static swift::ModuleDecl *LoadOneModule(const SourceModule &module,
81938216
SwiftASTContext &swift_ast_context,
81948217
lldb::StackFrameWP &stack_frame_wp,
81958218
Status &error) {
8219+
LLDB_SCOPED_TIMER();
81968220
if (!module.path.size())
81978221
return nullptr;
81988222

@@ -8253,6 +8277,7 @@ bool SwiftASTContext::GetImplicitImports(
82538277
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
82548278
&modules,
82558279
Status &error) {
8280+
LLDB_SCOPED_TIMER();
82568281
if (!swift_ast_context.GetCompileUnitImports(sc, stack_frame_wp, modules,
82578282
error)) {
82588283
return false;
@@ -8348,6 +8373,7 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
83488373
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
83498374
*modules,
83508375
Status &error) {
8376+
LLDB_SCOPED_TIMER();
83518377
CompileUnit *compile_unit = sc.comp_unit;
83528378
if (compile_unit)
83538379
// Check the cache if this compile unit's imports were previously

lldb/source/Target/Target.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,7 @@ Target::CreateUtilityFunction(std::string expression, std::string name,
25092509
llvm::Optional<SwiftASTContextReader> Target::GetScratchSwiftASTContext(
25102510
Status &error, ExecutionContextScope &exe_scope, bool create_on_demand) {
25112511
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET));
2512+
LLDB_SCOPED_TIMER();
25122513

25132514
Module *lldb_module = nullptr;
25142515
if (m_use_scratch_typesystem_per_module)

0 commit comments

Comments
 (0)