aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/trace/SkEventTracingPriv.cpp
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-07-20 15:43:35 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-20 20:11:22 +0000
commit53136aa93f0d0e72facabb70a7d40ed265e4be0e (patch)
tree3ae630fda54ade043c357bf80222e06eda6bbef2 /tools/trace/SkEventTracingPriv.cpp
parent45c16fa82cd2fec010d4cb7763b654a413cabd0c (diff)
First stab at JSON event tracer
Not yet thread safe (so it forces threading off). Builds JSON on the fly, so overhead is certainly bad. Plan to fix all of that, but this at least "works". There is now one tracing flag: 'trace'. - 'debugf' installs the SkDebugf tracer. - 'atrace' installs the Android ATrace tracer. - Any other value is interpreted as a filename, and produces a JSON file for chrome://tracing. All three modes work in DM, nanobench, and Viewer. Bug: skia: Change-Id: I3fbc22382b99418a508c670be2770195c0a1c364 Reviewed-on: https://skia-review.googlesource.com/24781 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tools/trace/SkEventTracingPriv.cpp')
-rw-r--r--tools/trace/SkEventTracingPriv.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/trace/SkEventTracingPriv.cpp b/tools/trace/SkEventTracingPriv.cpp
new file mode 100644
index 0000000000..217511ffa7
--- /dev/null
+++ b/tools/trace/SkEventTracingPriv.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkEventTracingPriv.h"
+
+#include "SkATrace.h"
+#include "SkCommandLineFlags.h"
+#include "SkEventTracer.h"
+#include "SkChromeTracingTracer.h"
+#include "SkDebugfTracer.h"
+
+DEFINE_string(trace, "",
+ "Log trace events in one of several modes:\n"
+ " debugf : Show events using SkDebugf\n"
+ " atrace : Send events to Android ATrace\n"
+ " <filename> : Any other string is interpreted as a filename. Writes\n"
+ " trace events to specified file as JSON, for viewing\n"
+ " with chrome://tracing");
+
+void initializeEventTracingForTools(int32_t* threadsFlag) {
+ if (FLAGS_trace.isEmpty()) {
+ return;
+ }
+
+ const char* traceFlag = FLAGS_trace[0];
+ SkEventTracer* eventTracer = nullptr;
+ if (0 == strcmp(traceFlag, "atrace")) {
+ eventTracer = new SkATrace();
+ } else if (0 == strcmp(traceFlag, "debugf")) {
+ eventTracer = new SkDebugfTracer();
+ } else {
+ if (threadsFlag && *threadsFlag != 0) {
+ SkDebugf("JSON tracing is not yet thread-safe, disabling threading.\n");
+ *threadsFlag = 0;
+ }
+ eventTracer = new SkChromeTracingTracer(traceFlag);
+ }
+
+ SkAssertResult(SkEventTracer::SetInstance(eventTracer));
+}