Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add information on swiftmodule load times to statistics dump command #9671

Open
wants to merge 1 commit into
base: stable/20240723
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,25 @@ static void printASTValidationError(
LLDB_LOG(log, " -- {0}", ExtraOpt);
}

std::optional<llvm::json::Value> SwiftASTContext::ReportStatistics() {
const auto &load_times = GetSwiftModuleLoadTimes();
llvm::json::Array swift_module_load_times;
StatsDuration swift_module_total_load_time;
for (const auto &entry : load_times) {
llvm::json::Object obj;
obj.try_emplace("name", entry.first().str());
obj.try_emplace("loadTime", entry.second.get().count());
swift_module_total_load_time += entry.second;
swift_module_load_times.emplace_back(std::move(obj));
}

llvm::json::Object obj;
obj.try_emplace("swiftmodules", std::move(swift_module_load_times));
obj.try_emplace("totalLoadTime", swift_module_total_load_time.get().count());
llvm::json::Value ret = std::move(obj);
return ret;
}

void SwiftASTContext::DiagnoseWarnings(Process &process,
const SymbolContext &sc) const {
if (!sc.module_sp || !HasDiagnostics())
Expand Down Expand Up @@ -3892,6 +3911,10 @@ SwiftASTContext::GetModule(const SourceModule &module, bool *cached) {
return *module_decl;
}

auto &load_time_map = GetSwiftModuleLoadTimes();
StatsDuration &load_time = load_time_map[module.path.front().GetStringRef()];
ElapsedTime elapsed(load_time);

LLDB_SCOPED_TIMER();
ThreadSafeASTContext ast = GetASTContext();
if (!ast) {
Expand Down
12 changes: 12 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "lldb/Core/ThreadSafeDenseSet.h"
#include "lldb/Expression/DiagnosticManager.h"
#include "lldb/Utility/Either.h"
#include "lldb/Target/Statistics.h"
#include "llvm/Support/JSON.h"

#include "swift/AST/Import.h"
#include "swift/AST/Module.h"
Expand Down Expand Up @@ -553,6 +555,15 @@ class SwiftASTContext : public TypeSystemSwift {

const SwiftModuleMap &GetModuleCache() { return m_swift_module_cache; }


typedef llvm::StringMap<StatsDuration> SwiftModuleLoadTimeMap;

SwiftModuleLoadTimeMap &GetSwiftModuleLoadTimes() {
return m_swift_module_load_time_map;
}

std::optional<llvm::json::Value> ReportStatistics() override;

const swift::irgen::TypeInfo *
GetSwiftTypeInfo(lldb::opaque_compiler_type_t type);

Expand Down Expand Up @@ -942,6 +953,7 @@ class SwiftASTContext : public TypeSystemSwift {
std::shared_ptr<TypeSystemClang> m_clangimporter_typesystem;
std::unique_ptr<swift::DWARFImporterDelegate> m_dwarfimporter_delegate_up;
SwiftModuleMap m_swift_module_cache;
SwiftModuleLoadTimeMap m_swift_module_load_time_map;
SwiftTypeFromMangledNameMap m_mangled_name_to_type_map;
SwiftMangledNameFromTypeMap m_type_to_mangled_name_map;
uint32_t m_pointer_byte_size = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,15 @@ Status TypeSystemSwiftTypeRef::IsCompatible() {
return {};
}

std::optional<llvm::json::Value> TypeSystemSwiftTypeRef::ReportStatistics() {
// This SymbolContext is not being used within the function GetSwiftASTContextOrNull
SymbolContext sc;
if (auto *swift_ast_context = GetSwiftASTContextOrNull(sc)) {
return swift_ast_context->ReportStatistics();
}
return std::nullopt;
}

void TypeSystemSwiftTypeRef::DiagnoseWarnings(Process &process,
const SymbolContext &sc) const {
// This gets called only from Thread::FrameSelectedCallback(StackFrame).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
void ClearModuleDependentCaches() override;
lldb::TargetWP GetTargetWP() const override { return {}; }

std::optional<llvm::json::Value> ReportStatistics() override;

/// Return a SwiftASTContext type for type.
CompilerType ReconstructType(CompilerType type,
const ExecutionContext *exe_ctx);
Expand Down