[Runtime] Add tracing for section scans.

Section scans (for metadata, protocols, etc.) can be costly. This change adds tracing calls to those scans so we can more easily see how much time is spent in these scans and where they're initiated.

This adds an os_signpost implementation controlled by SWIFT_STDLIB_TRACING, and a default empty implementation for when that's disabled.

rdar://110266743
This commit is contained in:
Mike Ash
2023-06-06 14:12:31 -04:00
parent 5125edeaa1
commit 110f428780
11 changed files with 273 additions and 5 deletions

View File

@@ -30,6 +30,7 @@
#include "../CompatibilityOverride/CompatibilityOverride.h"
#include "ImageInspection.h"
#include "Private.h"
#include "Tracing.h"
#include <new>
#include <vector>
@@ -1089,6 +1090,9 @@ swift_conformsToProtocolMaybeInstantiateSuperclasses(
}
};
auto traceState =
runtime::trace::protocol_conformance_scan_begin(type, protocol);
auto snapshot = C.SectionsToScan.snapshot();
if (C.scanSectionsBackwards) {
for (auto &section : llvm::reverse(snapshot))
@@ -1125,6 +1129,8 @@ swift_conformsToProtocolMaybeInstantiateSuperclasses(
}
noteFinalMetadataState(superclassIterator.state);
traceState.end(foundWitness);
// If it's for a superclass or if we didn't find anything, then add an
// authoritative entry for this type.
if (foundType != type)
@@ -1170,13 +1176,15 @@ swift_conformsToProtocolImpl(const Metadata *const type,
const ContextDescriptor *
swift::_searchConformancesByMangledTypeName(Demangle::NodePointer node) {
auto traceState = runtime::trace::protocol_conformance_scan_begin(node);
auto &C = Conformances.get();
for (auto &section : C.SectionsToScan.snapshot()) {
for (const auto &record : section) {
if (auto ntd = record->getTypeDescriptor()) {
if (_contextDescriptorMatchesMangling(ntd, node))
return ntd;
return traceState.end(ntd);
}
}
}