diff options
author | Brian Salomon <bsalomon@google.com> | 2017-07-19 10:53:20 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-19 15:41:34 +0000 |
commit | dcbb9d90db0e07b7a3625bcdab3af11ab44c4cfe (patch) | |
tree | 53f66c3a874feb791aa373597282286f08803f03 /tools | |
parent | 925f52d03b731c49c1a2b52c6ced53169a1df669 (diff) |
Add SkDebugf trace event handler.
Also adds more trace events to GPU backend.
Change-Id: Ifa5f0cd4b1fd582f0cc30d37d9e6414dc498c75d
Reviewed-on: https://skia-review.googlesource.com/24622
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/flags/SkCommonFlags.cpp | 2 | ||||
-rw-r--r-- | tools/flags/SkCommonFlags.h | 1 | ||||
-rw-r--r-- | tools/trace/SkDebugfTracer.cpp | 90 | ||||
-rw-r--r-- | tools/trace/SkDebugfTracer.h | 47 |
4 files changed, 140 insertions, 0 deletions
diff --git a/tools/flags/SkCommonFlags.cpp b/tools/flags/SkCommonFlags.cpp index 0148bcd820..35fc0cf82f 100644 --- a/tools/flags/SkCommonFlags.cpp +++ b/tools/flags/SkCommonFlags.cpp @@ -72,6 +72,8 @@ DEFINE_bool(forceAnalyticAA, false, "Force analytic anti-aliasing even if the pa "whether it's concave or convex, we consider a path complicated" "if its number of points is comparable to its resolution."); +DEFINE_bool(trace, false, "Show trace events using SkDebugf."); + bool CollectImages(SkCommandLineFlags::StringArray images, SkTArray<SkString>* output) { SkASSERT(output); diff --git a/tools/flags/SkCommonFlags.h b/tools/flags/SkCommonFlags.h index 92ac141dad..71ff8c3753 100644 --- a/tools/flags/SkCommonFlags.h +++ b/tools/flags/SkCommonFlags.h @@ -34,6 +34,7 @@ DECLARE_string(writePath); DECLARE_bool(pre_log); DECLARE_bool(analyticAA); DECLARE_bool(forceAnalyticAA); +DECLARE_bool(trace) DECLARE_string(key); DECLARE_string(properties); diff --git a/tools/trace/SkDebugfTracer.cpp b/tools/trace/SkDebugfTracer.cpp new file mode 100644 index 0000000000..272af7827d --- /dev/null +++ b/tools/trace/SkDebugfTracer.cpp @@ -0,0 +1,90 @@ +/* + * 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 "SkDebugfTracer.h" +#include "SkTraceEvent.h" + +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(" "); + } + switch (argTypes[i]) { + case TRACE_VALUE_TYPE_BOOL: + args.appendf("%s=%s", + argNames[i], + (*reinterpret_cast<bool*>(argValues[i]) ? "true" : "false")); + 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: + args.appendf("%s=%g", argNames[i], *SkTCast<const double*>(&argValues[i])); + break; + case TRACE_VALUE_TYPE_POINTER: + args.appendf("%s=0x%p", argNames[i], reinterpret_cast<void*>(argValues[i])); + break; + case TRACE_VALUE_TYPE_STRING: + case TRACE_VALUE_TYPE_COPY_STRING: { + static constexpr size_t kMaxLen = 20; + const char* str = reinterpret_cast<const char*>(argValues[i]); + SkString string(str); + 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) { + SkDebugf( + "[% 2d]%s %s%s #%d {\n", fIndent.size(), fIndent.c_str(), name, args.c_str(), fCnt); + 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); +} + +const uint8_t* SkDebugfTracer::getCategoryGroupEnabled(const char* name) { + static uint8_t yes = SkEventTracer::kEnabledForRecording_CategoryGroupEnabledFlags; + return &yes; +} diff --git a/tools/trace/SkDebugfTracer.h b/tools/trace/SkDebugfTracer.h new file mode 100644 index 0000000000..4350d1ac3c --- /dev/null +++ b/tools/trace/SkDebugfTracer.h @@ -0,0 +1,47 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkDebugfTracer_DEFINED +#define SkDebugfTracer_DEFINED + +#include "SkEventTracer.h" +#include "SkString.h" + +/** + * A SkEventTracer implementation that logs events using SkDebugf. + */ +class SkDebugfTracer : public SkEventTracer { +public: + SkDebugfTracer() {} + + SkEventTracer::Handle 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) override; + + void updateTraceEventDuration(const uint8_t* categoryEnabledFlag, + const char* name, + SkEventTracer::Handle handle) override; + + const uint8_t* getCategoryGroupEnabled(const char* name) override; + + const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override { + static const char* category = "category?"; + return category; + } + +private: + SkString fIndent; + int fCnt = 0; +}; + +#endif |