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/compile/Png.cpp b/tools/aapt2/compile/Png.cpp
index 33122dc..d396d81 100644
--- a/tools/aapt2/compile/Png.cpp
+++ b/tools/aapt2/compile/Png.cpp
@@ -27,6 +27,7 @@
#include "androidfw/ResourceTypes.h"
#include "Source.h"
+#include "trace/TraceBuffer.h"
#include "util/BigBuffer.h"
#include "util/Util.h"
@@ -1233,6 +1234,7 @@
bool Png::process(const Source& source, std::istream* input,
BigBuffer* outBuffer, const PngOptions& options) {
+ TRACE_CALL();
png_byte signature[kPngSignatureSize];
// Read the PNG signature first.
diff --git a/tools/aapt2/compile/PngCrunch.cpp b/tools/aapt2/compile/PngCrunch.cpp
index 0346a19..1f4ea44d 100644
--- a/tools/aapt2/compile/PngCrunch.cpp
+++ b/tools/aapt2/compile/PngCrunch.cpp
@@ -27,6 +27,8 @@
#include "android-base/logging.h"
#include "android-base/macros.h"
+#include "trace/TraceBuffer.h"
+
namespace aapt {
// Custom deleter that destroys libpng read and info structs.
@@ -142,6 +144,7 @@
}
std::unique_ptr<Image> ReadPng(IAaptContext* context, const Source& source, io::InputStream* in) {
+ TRACE_CALL();
// Create a diagnostics that has the source information encoded.
SourcePathDiagnostics source_diag(source, context->GetDiagnostics());
@@ -480,6 +483,7 @@
bool WritePng(IAaptContext* context, const Image* image,
const NinePatch* nine_patch, io::OutputStream* out,
const PngOptions& options) {
+ TRACE_CALL();
// Create and initialize the write png_struct with the default error and
// warning handlers.
// The header version is also passed in to ensure that this was built against the same
diff --git a/tools/aapt2/compile/XmlIdCollector.cpp b/tools/aapt2/compile/XmlIdCollector.cpp
index 2199d00..5054115 100644
--- a/tools/aapt2/compile/XmlIdCollector.cpp
+++ b/tools/aapt2/compile/XmlIdCollector.cpp
@@ -22,6 +22,7 @@
#include "ResourceUtils.h"
#include "ResourceValues.h"
#include "text/Unicode.h"
+#include "trace/TraceBuffer.h"
#include "xml/XmlDom.h"
namespace aapt {
@@ -72,6 +73,7 @@
} // namespace
bool XmlIdCollector::Consume(IAaptContext* context, xml::XmlResource* xmlRes) {
+ TRACE_CALL();
xmlRes->file.exported_symbols.clear();
SourcePathDiagnostics source_diag(xmlRes->file.source, context->GetDiagnostics());
IdCollector collector(&xmlRes->file.exported_symbols, &source_diag);