Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: include/private/GrAuditTrail.h

Issue 1712753002: GrAuditTrail can now be enabled/disabled at runtime (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: removed one more reference to GR_BATCH_DEBUGGING_OUTPUT Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/GrConfig.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/private/GrAuditTrail.h
diff --git a/include/private/GrAuditTrail.h b/include/private/GrAuditTrail.h
index 21236566b9b19045b48d7bf4f80a42dad9303021..52a7c9031dc2d7bf8a1ab0b7a3ce9c991b5d688b 100644
--- a/include/private/GrAuditTrail.h
+++ b/include/private/GrAuditTrail.h
@@ -16,22 +16,29 @@
/*
* GrAuditTrail collects a list of draw ops, detailed information about those ops, and can dump them
* to json.
+ *
+ * Capturing this information is expensive and consumes a lot of memory, therefore it is important
+ * to enable auditing only when required and disable it promptly. The AutoEnable class helps to
+ * ensure that the audit trail is disabled in a timely fashion. Once the information has been dealt
+ * with, be sure to call reset(), or the log will simply keep growing.
*/
class GrAuditTrail {
public:
- GrAuditTrail() : fUniqueID(0) {}
+ GrAuditTrail()
+ : fEnabled(false)
+ , fUniqueID(0) {}
class AutoFrame {
public:
AutoFrame(GrAuditTrail* auditTrail, const char* name)
: fAuditTrail(auditTrail) {
- if (GR_BATCH_DEBUGGING_OUTPUT) {
+ if (fAuditTrail->fEnabled) {
fAuditTrail->pushFrame(name);
}
}
~AutoFrame() {
- if (GR_BATCH_DEBUGGING_OUTPUT) {
+ if (fAuditTrail->fEnabled) {
fAuditTrail->popFrame();
}
}
@@ -40,8 +47,25 @@ public:
GrAuditTrail* fAuditTrail;
};
+ class AutoEnable {
+ public:
+ AutoEnable(GrAuditTrail* auditTrail)
+ : fAuditTrail(auditTrail) {
+ SkASSERT(!fAuditTrail->isEnabled());
+ fAuditTrail->setEnabled(true);
+ }
+
+ ~AutoEnable() {
+ SkASSERT(fAuditTrail->isEnabled());
+ fAuditTrail->setEnabled(false);
+ }
+
+ private:
+ GrAuditTrail* fAuditTrail;
+ };
+
void pushFrame(const char* name) {
- SkASSERT(GR_BATCH_DEBUGGING_OUTPUT);
+ SkASSERT(fEnabled);
Frame* frame = new Frame;
if (fStack.empty()) {
fFrames.emplace_back(frame);
@@ -55,12 +79,12 @@ public:
}
void popFrame() {
- SkASSERT(GR_BATCH_DEBUGGING_OUTPUT);
+ SkASSERT(fEnabled);
fStack.pop_back();
}
void addBatch(const char* name, const SkRect& bounds) {
- SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && !fStack.empty());
+ SkASSERT(fEnabled && !fStack.empty());
Batch* batch = new Batch;
fStack.back()->fChildren.emplace_back(batch);
batch->fName = name;
@@ -69,7 +93,10 @@ public:
SkString toJson(bool prettyPrint = false) const;
- void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && fStack.empty()); fFrames.reset(); }
+ bool isEnabled() { return fEnabled; }
+ void setEnabled(bool enabled) { fEnabled = enabled; }
+
+ void reset() { SkASSERT(fEnabled && fStack.empty()); fFrames.reset(); }
private:
// TODO if performance becomes an issue, we can move to using SkVarAlloc
@@ -95,23 +122,24 @@ private:
static void JsonifyTArray(SkString* json, const char* name, const FrameArray& array,
bool addComma);
+ bool fEnabled;
FrameArray fFrames;
SkTArray<Frame*> fStack;
uint64_t fUniqueID;
};
-#define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \
- if (GR_BATCH_DEBUGGING_OUTPUT) { \
- invoke(__VA_ARGS__); \
+#define GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, invoke, ...) \
+ if (audit_trail->isEnabled()) { \
+ audit_trail->invoke(__VA_ARGS__); \
}
#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);
+ 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, batchname, bounds);
+ GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, addBatch, batchname, bounds);
#endif
« no previous file with comments | « include/gpu/GrConfig.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698