Convert GrAuditTrail to use scoped frames
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1579193002 Review URL: https://codereview.chromium.org/1579193002
This commit is contained in:
parent
61a237e319
commit
87a721b246
@ -19,36 +19,77 @@
|
||||
*/
|
||||
class GrAuditTrail {
|
||||
public:
|
||||
void addOp(const SkString& name) {
|
||||
GrAuditTrail() : fUniqueID(0) {}
|
||||
|
||||
class AutoFrame {
|
||||
public:
|
||||
AutoFrame(GrAuditTrail* auditTrail, const char* name)
|
||||
: fAuditTrail(auditTrail) {
|
||||
if (GR_BATCH_DEBUGGING_OUTPUT) {
|
||||
fAuditTrail->pushFrame(name);
|
||||
}
|
||||
}
|
||||
|
||||
~AutoFrame() {
|
||||
if (GR_BATCH_DEBUGGING_OUTPUT) {
|
||||
fAuditTrail->popFrame();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
GrAuditTrail* fAuditTrail;
|
||||
};
|
||||
|
||||
void pushFrame(const char* name) {
|
||||
SkASSERT(GR_BATCH_DEBUGGING_OUTPUT);
|
||||
fOps.push_back().fName = name;
|
||||
Frame* frame;
|
||||
if (fStack.empty()) {
|
||||
frame = &fFrames.push_back();
|
||||
} else {
|
||||
frame = &fStack.back()->fChildren.push_back();
|
||||
}
|
||||
|
||||
frame->fUniqueID = fUniqueID++;
|
||||
frame->fName = name;
|
||||
fStack.push_back(frame);
|
||||
}
|
||||
|
||||
void addBatch(const SkString& name, const SkRect& bounds) {
|
||||
void popFrame() {
|
||||
SkASSERT(GR_BATCH_DEBUGGING_OUTPUT);
|
||||
Op::Batch& batch = fOps.back().fBatches.push_back();
|
||||
fStack.pop_back();
|
||||
}
|
||||
|
||||
void addBatch(const char* name, const SkRect& bounds) {
|
||||
// TODO when every internal callsite pushes a frame, we can add the assert
|
||||
SkASSERT(GR_BATCH_DEBUGGING_OUTPUT /*&& !fStack.empty()*/);
|
||||
Frame::Batch& batch = fStack.back()->fBatches.push_back();
|
||||
batch.fName = name;
|
||||
batch.fBounds = bounds;
|
||||
}
|
||||
|
||||
SkString toJson() const;
|
||||
|
||||
void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); fOps.reset(); }
|
||||
void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && fStack.empty()); fFrames.reset(); }
|
||||
|
||||
private:
|
||||
struct Op {
|
||||
struct Frame {
|
||||
SkString toJson() const;
|
||||
struct Batch {
|
||||
SkString toJson() const;
|
||||
SkString fName;
|
||||
const char* fName;
|
||||
SkRect fBounds;
|
||||
};
|
||||
|
||||
SkString fName;
|
||||
const char* fName;
|
||||
// TODO combine these into a single array
|
||||
SkTArray<Batch> fBatches;
|
||||
SkTArray<Frame> fChildren;
|
||||
uint64_t fUniqueID;
|
||||
};
|
||||
|
||||
SkTArray<Op> fOps;
|
||||
SkTArray<Frame> fFrames;
|
||||
SkTArray<Frame*> fStack;
|
||||
uint64_t fUniqueID;
|
||||
};
|
||||
|
||||
#define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \
|
||||
@ -56,13 +97,13 @@ private:
|
||||
invoke(__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define GR_AUDIT_TRAIL_ADDOP(audit_trail, opname) \
|
||||
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addOp, opname);
|
||||
#define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename) \
|
||||
GrAuditTrail::AutoFrame SK_MACRO_APPEND_LINE(auto_frame)(audit_trail, framename);
|
||||
|
||||
#define GR_AUDIT_TRAIL_RESET(audit_trail) \
|
||||
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset);
|
||||
|
||||
#define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \
|
||||
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, SkString(batchname), bounds);
|
||||
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, batchname, bounds);
|
||||
|
||||
#endif
|
||||
|
@ -8,12 +8,16 @@
|
||||
#include "GrAuditTrail.h"
|
||||
|
||||
template <class T>
|
||||
static void jsonify_tarray(SkString* json, const SkTArray<T>& array) {
|
||||
for (int i = 0; i < array.count(); i++) {
|
||||
json->append(array[i].toJson());
|
||||
if (i < array.count() - 1) {
|
||||
json->append(",");
|
||||
static void jsonify_tarray(SkString* json, const char* name, const SkTArray<T>& array) {
|
||||
if (array.count()) {
|
||||
json->appendf("\"%s\": [", name);
|
||||
for (int i = 0; i < array.count(); i++) {
|
||||
json->append(array[i].toJson());
|
||||
if (i < array.count() - 1) {
|
||||
json->append(",");
|
||||
}
|
||||
}
|
||||
json->append("]");
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,30 +91,27 @@ static SkString pretty_print_json(SkString json) {
|
||||
SkString GrAuditTrail::toJson() const {
|
||||
SkString json;
|
||||
json.append("{");
|
||||
json.append("\"Ops\": [");
|
||||
jsonify_tarray(&json, fOps);
|
||||
json.append("]");
|
||||
jsonify_tarray(&json, "Stacks", fFrames);
|
||||
json.append("}");
|
||||
|
||||
// TODO if this becomes a performance issue we should make pretty print configurable
|
||||
return pretty_print_json(json);
|
||||
}
|
||||
|
||||
SkString GrAuditTrail::Op::toJson() const {
|
||||
SkString GrAuditTrail::Frame::toJson() const {
|
||||
SkString json;
|
||||
json.append("{");
|
||||
json.appendf("\"Name\": \"%s\",", fName.c_str());
|
||||
json.append("\"Batches\": [");
|
||||
jsonify_tarray(&json, fBatches);
|
||||
json.append("]");
|
||||
json.appendf("\"Name\": \"%s\",", fName);
|
||||
jsonify_tarray(&json, "Batches", fBatches);
|
||||
jsonify_tarray(&json, "Frames", fChildren);
|
||||
json.append("}");
|
||||
return json;
|
||||
}
|
||||
|
||||
SkString GrAuditTrail::Op::Batch::toJson() const {
|
||||
SkString GrAuditTrail::Frame::Batch::toJson() const {
|
||||
SkString json;
|
||||
json.append("{");
|
||||
json.appendf("\"Name\": \"%s\",", fName.c_str());
|
||||
json.appendf("\"Name\": \"%s\",", fName);
|
||||
json.append("\"Bounds\": {");
|
||||
json.appendf("\"Left\": %f,", fBounds.fLeft);
|
||||
json.appendf("\"Right\": %f,", fBounds.fRight);
|
||||
|
@ -58,7 +58,7 @@ private:
|
||||
/**
|
||||
* GR_CREATE_TRACE_MARKER will place begin and end trace markers for both
|
||||
* cpu and gpu (if gpu tracing enabled) for the current scope.
|
||||
* marker is of type const char* and target is of type GrDrawTarget*
|
||||
* name is of type const char* and target is of type GrDrawTarget*
|
||||
*/
|
||||
#define GR_CREATE_TRACE_MARKER(name, target) \
|
||||
/* Chromium tracing */ \
|
||||
@ -86,6 +86,10 @@ private:
|
||||
GrGpuTraceMarkerGenerator SK_MACRO_APPEND_LINE(TMG)(target); \
|
||||
SK_MACRO_APPEND_LINE(TMG).initialize(name, &name_counter); \
|
||||
|
||||
/**
|
||||
* Context level GrTracing macros, classname and op are const char*, context is GrContext
|
||||
* TODO can we just have one set of macros? Probably.
|
||||
*/
|
||||
#define GR_CREATE_TRACE_MARKER_CONTEXT(classname, op, context) \
|
||||
/* Chromium tracing */ \
|
||||
static int SK_MACRO_APPEND_LINE(name_counter) = 0; \
|
||||
@ -96,7 +100,7 @@ private:
|
||||
INTERNAL_GR_CREATE_TRACE_MARKER_SCOPED_C(classname "::" op, \
|
||||
SK_MACRO_APPEND_LINE(name_counter), context) \
|
||||
} \
|
||||
GR_AUDIT_TRAIL_ADDOP(context->getAuditTrail(), SkString(op)); \
|
||||
GR_AUDIT_TRAIL_AUTO_FRAME(context->getAuditTrail(), classname "::" op); \
|
||||
INTERNAL_TRACE_EVENT_ADD_SCOPED(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), classname "::" op, \
|
||||
"id", SK_MACRO_APPEND_LINE(name_counter));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user