Add --trace_folder to aapt2
Add a tracing API and instrument key functions in order to profile
aapt2 bottleneck. The API allows to generate systrace fragment files.
Impact on performance is neglibible with each Trace requiring less
than 1us and the final Flush operation at the end of a command
requiring around 40us.
Bug: None
Test: None
Change-Id: I51b564d3694e9384679f43b878b32295527dddf6
diff --git a/tools/aapt2/link/AutoVersioner.cpp b/tools/aapt2/link/AutoVersioner.cpp
index 960c7d4..73b9254 100644
--- a/tools/aapt2/link/AutoVersioner.cpp
+++ b/tools/aapt2/link/AutoVersioner.cpp
@@ -23,6 +23,7 @@
#include "ResourceTable.h"
#include "SdkConstants.h"
#include "ValueVisitor.h"
+#include "trace/TraceBuffer.h"
using android::ConfigDescription;
@@ -70,6 +71,7 @@
}
bool AutoVersioner::Consume(IAaptContext* context, ResourceTable* table) {
+ TRACE_NAME("AutoVersioner::Consume");
for (auto& package : table->packages) {
for (auto& type : package->types) {
if (type->type != ResourceType::kStyle) {
diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp
index 582a5b8..b0a2055 100644
--- a/tools/aapt2/link/ManifestFixer.cpp
+++ b/tools/aapt2/link/ManifestFixer.cpp
@@ -21,6 +21,7 @@
#include "android-base/logging.h"
#include "ResourceUtils.h"
+#include "trace/TraceBuffer.h"
#include "util/Util.h"
#include "xml/XmlActionExecutor.h"
#include "xml/XmlDom.h"
@@ -451,6 +452,7 @@
}
bool ManifestFixer::Consume(IAaptContext* context, xml::XmlResource* doc) {
+ TRACE_CALL();
xml::Element* root = xml::FindRootElement(doc->root.get());
if (!root || !root->namespace_uri.empty() || root->name != "manifest") {
context->GetDiagnostics()->Error(DiagMessage(doc->file.source)
diff --git a/tools/aapt2/link/ProductFilter.cpp b/tools/aapt2/link/ProductFilter.cpp
index c1a95ee1..793740a 100644
--- a/tools/aapt2/link/ProductFilter.cpp
+++ b/tools/aapt2/link/ProductFilter.cpp
@@ -17,6 +17,7 @@
#include "link/Linkers.h"
#include "ResourceTable.h"
+#include "trace/TraceBuffer.h"
namespace aapt {
@@ -81,6 +82,7 @@
}
bool ProductFilter::Consume(IAaptContext* context, ResourceTable* table) {
+ TRACE_NAME("ProductFilter::Consume");
bool error = false;
for (auto& pkg : table->packages) {
for (auto& type : pkg->types) {
diff --git a/tools/aapt2/link/ReferenceLinker.cpp b/tools/aapt2/link/ReferenceLinker.cpp
index c2340ba..28f09aa 100644
--- a/tools/aapt2/link/ReferenceLinker.cpp
+++ b/tools/aapt2/link/ReferenceLinker.cpp
@@ -27,6 +27,7 @@
#include "link/Linkers.h"
#include "process/IResourceTableConsumer.h"
#include "process/SymbolTable.h"
+#include "trace/TraceBuffer.h"
#include "util/Util.h"
#include "xml/XmlUtil.h"
@@ -353,6 +354,7 @@
}
bool ReferenceLinker::Consume(IAaptContext* context, ResourceTable* table) {
+ TRACE_NAME("ReferenceLinker::Consume");
EmptyDeclStack decl_stack;
bool error = false;
for (auto& package : table->packages) {
diff --git a/tools/aapt2/link/ResourceExcluder.cpp b/tools/aapt2/link/ResourceExcluder.cpp
index 2555995..b3b9dc4 100644
--- a/tools/aapt2/link/ResourceExcluder.cpp
+++ b/tools/aapt2/link/ResourceExcluder.cpp
@@ -20,6 +20,7 @@
#include "DominatorTree.h"
#include "ResourceTable.h"
+#include "trace/TraceBuffer.h"
using android::ConfigDescription;
@@ -65,6 +66,7 @@
} // namespace
bool ResourceExcluder::Consume(IAaptContext* context, ResourceTable* table) {
+ TRACE_NAME("ResourceExcluder::Consume");
for (auto& package : table->packages) {
for (auto& type : package->types) {
for (auto& entry : type->entries) {
diff --git a/tools/aapt2/link/TableMerger.cpp b/tools/aapt2/link/TableMerger.cpp
index cc9fed5..e937517 100644
--- a/tools/aapt2/link/TableMerger.cpp
+++ b/tools/aapt2/link/TableMerger.cpp
@@ -21,6 +21,7 @@
#include "ResourceTable.h"
#include "ResourceUtils.h"
#include "ResourceValues.h"
+#include "trace/TraceBuffer.h"
#include "ValueVisitor.h"
#include "util/Util.h"
@@ -38,6 +39,7 @@
}
bool TableMerger::Merge(const Source& src, ResourceTable* table, bool overlay) {
+ TRACE_CALL();
// We allow adding new resources if this is not an overlay, or if the options allow overlays
// to add new resources.
return MergeImpl(src, table, overlay, options_.auto_add_overlay || !overlay /*allow_new*/);
diff --git a/tools/aapt2/link/XmlReferenceLinker.cpp b/tools/aapt2/link/XmlReferenceLinker.cpp
index 160ff92..d68f7dd 100644
--- a/tools/aapt2/link/XmlReferenceLinker.cpp
+++ b/tools/aapt2/link/XmlReferenceLinker.cpp
@@ -25,6 +25,7 @@
#include "link/ReferenceLinker.h"
#include "process/IResourceTableConsumer.h"
#include "process/SymbolTable.h"
+#include "trace/TraceBuffer.h"
#include "util/Util.h"
#include "xml/XmlDom.h"
@@ -151,6 +152,7 @@
} // namespace
bool XmlReferenceLinker::Consume(IAaptContext* context, xml::XmlResource* resource) {
+ TRACE_NAME("XmlReferenceLinker::Consume");
CallSite callsite{resource->file.name.package};
std::string out_name = resource->file.name.entry;