From 3bf0042caa550b1f0cd56633ed66174141f2728f Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Mon, 24 Jul 2017 14:27:18 -0400 Subject: [PATCH] ok, basic tracing support This doesn't do anything in the default process-per-task mode, because those child tasks exit using _exit(), which doesn't trigger the event tracer destructor to flush. I don't remember exactly why I exit with _exit(), so I'm going to have to follow up on that. But written this way as I think I'm at least initializing the tracing in the right place for each process for the future. In threaded (-j -1) and serial (-j 0) modes, everything seems to work great. I'm also thinking I might add a tracer like the SkDebugf tracer but using ok_log(), which handles interlaced logging from concurrent tasks better than vanilla SkDebugf. Example: ninja -C out ok; and out/ok gm 8888 filter:search=fontmgr_bounds trace -j -1 Change-Id: Ia3cdad930ce65e6fd12fa74f3fb00894e35138d3 Reviewed-on: https://skia-review.googlesource.com/26350 Reviewed-by: Brian Osman Commit-Queue: Mike Klein --- tools/ok_vias.cpp | 26 ++++++++++++++++++++++++++ tools/trace/SkEventTracingPriv.cpp | 10 ++++++---- tools/trace/SkEventTracingPriv.h | 5 +++-- 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 target; + std::string trace_mode; + + static std::unique_ptr Create(Options options, std::unique_ptr 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 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.