2017-07-20 19:43:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/trace/EventTracingPriv.h"
|
2017-07-20 19:43:35 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/utils/SkEventTracer.h"
|
|
|
|
#include "src/core/SkATrace.h"
|
|
|
|
#include "src/core/SkTraceEvent.h"
|
|
|
|
#include "tools/flags/CommandLineFlags.h"
|
|
|
|
#include "tools/trace/ChromeTracingTracer.h"
|
|
|
|
#include "tools/trace/SkDebugfTracer.h"
|
2017-07-20 19:43:35 +00:00
|
|
|
|
2019-03-21 16:31:36 +00:00
|
|
|
static DEFINE_string(trace,
|
2019-03-20 17:01:47 +00:00
|
|
|
"",
|
2017-07-20 19:43:35 +00:00
|
|
|
"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");
|
|
|
|
|
2019-03-21 16:31:36 +00:00
|
|
|
static DEFINE_string(traceMatch,
|
2019-03-20 17:01:47 +00:00
|
|
|
"",
|
2017-07-26 19:50:37 +00:00
|
|
|
"Filter which categories are traced.\n"
|
|
|
|
"Uses same format as --match\n");
|
|
|
|
|
2017-07-24 18:27:18 +00:00
|
|
|
void initializeEventTracingForTools(const char* traceFlag) {
|
|
|
|
if (!traceFlag) {
|
|
|
|
if (FLAGS_trace.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
traceFlag = FLAGS_trace[0];
|
2017-07-20 19:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkEventTracer* eventTracer = nullptr;
|
|
|
|
if (0 == strcmp(traceFlag, "atrace")) {
|
|
|
|
eventTracer = new SkATrace();
|
|
|
|
} else if (0 == strcmp(traceFlag, "debugf")) {
|
|
|
|
eventTracer = new SkDebugfTracer();
|
|
|
|
} else {
|
2019-03-20 17:01:47 +00:00
|
|
|
eventTracer = new ChromeTracingTracer(traceFlag);
|
2017-07-20 19:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkAssertResult(SkEventTracer::SetInstance(eventTracer));
|
|
|
|
}
|
2017-07-21 15:06:24 +00:00
|
|
|
|
2017-07-26 13:36:09 +00:00
|
|
|
uint8_t* SkEventTracingCategories::getCategoryGroupEnabled(const char* name) {
|
|
|
|
static_assert(0 == offsetof(CategoryState, fEnabled), "CategoryState");
|
|
|
|
|
|
|
|
// We ignore the "disabled-by-default-" prefix in our internal tools
|
|
|
|
if (SkStrStartsWith(name, TRACE_CATEGORY_PREFIX)) {
|
|
|
|
name += strlen(TRACE_CATEGORY_PREFIX);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chrome's implementation of this API does a two-phase lookup (once without a lock, then again
|
|
|
|
// with a lock. But the tracing macros avoid calling these functions more than once per site,
|
|
|
|
// so just do something simple (and easier to reason about):
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive lock(fMutex);
|
2017-07-21 15:06:24 +00:00
|
|
|
for (int i = 0; i < fNumCategories; ++i) {
|
|
|
|
if (0 == strcmp(name, fCategories[i].fName)) {
|
|
|
|
return reinterpret_cast<uint8_t*>(&fCategories[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fNumCategories >= kMaxCategories) {
|
|
|
|
SkDEBUGFAIL("Exhausted event tracing categories. Increase kMaxCategories.");
|
|
|
|
return reinterpret_cast<uint8_t*>(&fCategories[0]);
|
|
|
|
}
|
|
|
|
|
2019-03-20 15:50:33 +00:00
|
|
|
fCategories[fNumCategories].fEnabled =
|
|
|
|
CommandLineFlags::ShouldSkip(FLAGS_traceMatch, name)
|
|
|
|
? 0
|
|
|
|
: SkEventTracer::kEnabledForRecording_CategoryGroupEnabledFlags;
|
2017-07-26 19:50:37 +00:00
|
|
|
|
2017-07-21 15:06:24 +00:00
|
|
|
fCategories[fNumCategories].fName = name;
|
|
|
|
return reinterpret_cast<uint8_t*>(&fCategories[fNumCategories++]);
|
|
|
|
}
|
|
|
|
|
2017-07-26 13:36:09 +00:00
|
|
|
const char* SkEventTracingCategories::getCategoryGroupName(const uint8_t* categoryEnabledFlag) {
|
2017-07-21 15:06:24 +00:00
|
|
|
if (categoryEnabledFlag) {
|
|
|
|
return reinterpret_cast<const CategoryState*>(categoryEnabledFlag)->fName;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|