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 <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Mike Klein 2017-07-24 14:27:18 -04:00 committed by Skia Commit-Bot
parent 89d9d95570
commit 3bf0042caa
3 changed files with 35 additions and 6 deletions

View File

@ -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};

View File

@ -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();

View File

@ -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.