2017-07-19 14:53:20 +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 "src/core/SkTraceEvent.h"
|
|
|
|
#include "tools/trace/SkDebugfTracer.h"
|
2017-07-19 14:53:20 +00:00
|
|
|
|
|
|
|
SkEventTracer::Handle SkDebugfTracer::addTraceEvent(char phase,
|
|
|
|
const uint8_t* categoryEnabledFlag,
|
|
|
|
const char* name,
|
|
|
|
uint64_t id,
|
|
|
|
int numArgs,
|
|
|
|
const char** argNames,
|
|
|
|
const uint8_t* argTypes,
|
|
|
|
const uint64_t* argValues,
|
|
|
|
uint8_t flags) {
|
|
|
|
SkString args;
|
|
|
|
for (int i = 0; i < numArgs; ++i) {
|
|
|
|
if (i > 0) {
|
|
|
|
args.append(", ");
|
|
|
|
} else {
|
|
|
|
args.append(" ");
|
|
|
|
}
|
2017-07-21 19:30:14 +00:00
|
|
|
skia::tracing_internals::TraceValueUnion value;
|
|
|
|
value.as_uint = argValues[i];
|
2017-07-19 14:53:20 +00:00
|
|
|
switch (argTypes[i]) {
|
|
|
|
case TRACE_VALUE_TYPE_BOOL:
|
2017-07-21 19:30:14 +00:00
|
|
|
args.appendf("%s=%s", argNames[i], value.as_bool ? "true" : "false");
|
2017-07-19 14:53:20 +00:00
|
|
|
break;
|
|
|
|
case TRACE_VALUE_TYPE_UINT:
|
|
|
|
args.appendf("%s=%u", argNames[i], static_cast<uint32_t>(argValues[i]));
|
|
|
|
break;
|
|
|
|
case TRACE_VALUE_TYPE_INT:
|
|
|
|
args.appendf("%s=%d", argNames[i], static_cast<int32_t>(argValues[i]));
|
|
|
|
break;
|
|
|
|
case TRACE_VALUE_TYPE_DOUBLE:
|
2017-07-21 19:30:14 +00:00
|
|
|
args.appendf("%s=%g", argNames[i], value.as_double);
|
2017-07-19 14:53:20 +00:00
|
|
|
break;
|
|
|
|
case TRACE_VALUE_TYPE_POINTER:
|
2017-07-21 19:30:14 +00:00
|
|
|
args.appendf("%s=0x%p", argNames[i], value.as_pointer);
|
2017-07-19 14:53:20 +00:00
|
|
|
break;
|
|
|
|
case TRACE_VALUE_TYPE_STRING:
|
|
|
|
case TRACE_VALUE_TYPE_COPY_STRING: {
|
|
|
|
static constexpr size_t kMaxLen = 20;
|
2017-07-21 19:30:14 +00:00
|
|
|
SkString string(value.as_string);
|
2017-07-19 14:53:20 +00:00
|
|
|
size_t truncAt = string.size();
|
|
|
|
size_t newLineAt = SkStrFind(string.c_str(), "\n");
|
|
|
|
if (newLineAt > 0) {
|
|
|
|
truncAt = newLineAt;
|
|
|
|
}
|
|
|
|
truncAt = SkTMin(truncAt, kMaxLen);
|
|
|
|
if (truncAt < string.size()) {
|
|
|
|
string.resize(truncAt);
|
|
|
|
string.append("...");
|
|
|
|
}
|
|
|
|
args.appendf("%s=\"%s\"", argNames[i], string.c_str());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
args.appendf("%s=<unknown type>", argNames[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool open = (phase == TRACE_EVENT_PHASE_COMPLETE);
|
|
|
|
if (open) {
|
2017-07-21 15:06:24 +00:00
|
|
|
const char* category = this->getCategoryGroupName(categoryEnabledFlag);
|
|
|
|
SkDebugf("[% 2d]%s <%s> %s%s #%d {\n", fIndent.size(), fIndent.c_str(), category, name,
|
|
|
|
args.c_str(), fCnt);
|
2017-07-19 14:53:20 +00:00
|
|
|
fIndent.append(" ");
|
|
|
|
} else {
|
|
|
|
SkDebugf("%s%s #%d\n", name, args.c_str(), fCnt);
|
|
|
|
}
|
|
|
|
++fCnt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugfTracer::updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
|
|
|
|
const char* name,
|
|
|
|
SkEventTracer::Handle handle) {
|
|
|
|
fIndent.resize(fIndent.size() - 1);
|
|
|
|
SkDebugf("[% 2d]%s } %s\n", fIndent.size(), fIndent.c_str(), name);
|
|
|
|
}
|