aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/ok_vias.cpp26
-rw-r--r--tools/trace/SkEventTracingPriv.cpp10
-rw-r--r--tools/trace/SkEventTracingPriv.h5
3 files changed, 35 insertions, 6 deletions
diff --git a/tools/ok_vias.cpp b/tools/ok_vias.cpp
index b7fd2fef13..35e6f1fcab 100644
--- a/tools/ok_vias.cpp
+++ b/tools/ok_vias.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkEventTracingPriv.h"
#include "SkImage.h"
#include "SkOSFile.h"
#include "SkPictureRecorder.h"
@@ -186,3 +187,28 @@ struct Memory : Dst {
}
};
static Register memory{"memory", "print process maximum memory usage", Memory::Create};
+
+static SkOnce init_tracing_once;
+struct Trace : Dst {
+ std::unique_ptr<Dst> target;
+ std::string trace_mode;
+
+ static std::unique_ptr<Dst> Create(Options options, std::unique_ptr<Dst> dst) {
+ Trace via;
+ via.target = std::move(dst);
+ via.trace_mode = options("mode", "trace.json");
+ return move_unique(via);
+ }
+
+ Status draw(Src* src) override {
+ init_tracing_once([&] { initializeEventTracingForTools(trace_mode.c_str()); });
+ return target->draw(src);
+ }
+
+ sk_sp<SkImage> image() override {
+ return target->image();
+ }
+};
+static Register trace {"trace",
+ "enable tracing in mode=atrace, mode=debugf, or mode=trace.json",
+ Trace::Create};
diff --git a/tools/trace/SkEventTracingPriv.cpp b/tools/trace/SkEventTracingPriv.cpp
index 783cfeaa32..42d992cb13 100644
--- a/tools/trace/SkEventTracingPriv.cpp
+++ b/tools/trace/SkEventTracingPriv.cpp
@@ -22,12 +22,14 @@ DEFINE_string(trace, "",
" trace events to specified file as JSON, for viewing\n"
" with chrome://tracing");
-void initializeEventTracingForTools() {
- if (FLAGS_trace.isEmpty()) {
- return;
+void initializeEventTracingForTools(const char* traceFlag) {
+ if (!traceFlag) {
+ if (FLAGS_trace.isEmpty()) {
+ return;
+ }
+ traceFlag = FLAGS_trace[0];
}
- const char* traceFlag = FLAGS_trace[0];
SkEventTracer* eventTracer = nullptr;
if (0 == strcmp(traceFlag, "atrace")) {
eventTracer = new SkATrace();
diff --git a/tools/trace/SkEventTracingPriv.h b/tools/trace/SkEventTracingPriv.h
index aa3ee6d4d9..fb7b2f3fa5 100644
--- a/tools/trace/SkEventTracingPriv.h
+++ b/tools/trace/SkEventTracingPriv.h
@@ -11,9 +11,10 @@
#include "SkMutex.h"
/**
- * Construct and install an SkEventTracer, based on the 'trace' command line argument.
+ * Construct and install an SkEventTracer, based on the mode,
+ * defaulting to the --trace command line argument.
*/
-void initializeEventTracingForTools();
+void initializeEventTracingForTools(const char* mode = nullptr);
/**
* Helper class used by internal implementations of SkEventTracer to manage categories.