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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/gpu/GrConfig.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrAuditTrail_DEFINED 8 #ifndef GrAuditTrail_DEFINED
9 #define GrAuditTrail_DEFINED 9 #define GrAuditTrail_DEFINED
10 10
11 #include "GrConfig.h" 11 #include "GrConfig.h"
12 #include "SkRect.h" 12 #include "SkRect.h"
13 #include "SkString.h" 13 #include "SkString.h"
14 #include "SkTArray.h" 14 #include "SkTArray.h"
15 15
16 /* 16 /*
17 * GrAuditTrail collects a list of draw ops, detailed information about those op s, and can dump them 17 * GrAuditTrail collects a list of draw ops, detailed information about those op s, and can dump them
18 * to json. 18 * to json.
19 *
20 * Capturing this information is expensive and consumes a lot of memory, therefo re it is important
21 * to enable auditing only when required and disable it promptly. The AutoEnable class helps to
22 * ensure that the audit trail is disabled in a timely fashion. Once the informa tion has been dealt
23 * with, be sure to call reset(), or the log will simply keep growing.
19 */ 24 */
20 class GrAuditTrail { 25 class GrAuditTrail {
21 public: 26 public:
22 GrAuditTrail() : fUniqueID(0) {} 27 GrAuditTrail()
28 : fEnabled(false)
29 , fUniqueID(0) {}
23 30
24 class AutoFrame { 31 class AutoFrame {
25 public: 32 public:
26 AutoFrame(GrAuditTrail* auditTrail, const char* name) 33 AutoFrame(GrAuditTrail* auditTrail, const char* name)
27 : fAuditTrail(auditTrail) { 34 : fAuditTrail(auditTrail) {
28 if (GR_BATCH_DEBUGGING_OUTPUT) { 35 if (fAuditTrail->fEnabled) {
29 fAuditTrail->pushFrame(name); 36 fAuditTrail->pushFrame(name);
30 } 37 }
31 } 38 }
32 39
33 ~AutoFrame() { 40 ~AutoFrame() {
34 if (GR_BATCH_DEBUGGING_OUTPUT) { 41 if (fAuditTrail->fEnabled) {
35 fAuditTrail->popFrame(); 42 fAuditTrail->popFrame();
36 } 43 }
37 } 44 }
38 45
39 private: 46 private:
40 GrAuditTrail* fAuditTrail; 47 GrAuditTrail* fAuditTrail;
41 }; 48 };
42 49
50 class AutoEnable {
51 public:
52 AutoEnable(GrAuditTrail* auditTrail)
53 : fAuditTrail(auditTrail) {
54 SkASSERT(!fAuditTrail->isEnabled());
55 fAuditTrail->setEnabled(true);
56 }
57
58 ~AutoEnable() {
59 SkASSERT(fAuditTrail->isEnabled());
60 fAuditTrail->setEnabled(false);
61 }
62
63 private:
64 GrAuditTrail* fAuditTrail;
65 };
66
43 void pushFrame(const char* name) { 67 void pushFrame(const char* name) {
44 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); 68 SkASSERT(fEnabled);
45 Frame* frame = new Frame; 69 Frame* frame = new Frame;
46 if (fStack.empty()) { 70 if (fStack.empty()) {
47 fFrames.emplace_back(frame); 71 fFrames.emplace_back(frame);
48 } else { 72 } else {
49 fStack.back()->fChildren.emplace_back(frame); 73 fStack.back()->fChildren.emplace_back(frame);
50 } 74 }
51 75
52 frame->fUniqueID = fUniqueID++; 76 frame->fUniqueID = fUniqueID++;
53 frame->fName = name; 77 frame->fName = name;
54 fStack.push_back(frame); 78 fStack.push_back(frame);
55 } 79 }
56 80
57 void popFrame() { 81 void popFrame() {
58 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT); 82 SkASSERT(fEnabled);
59 fStack.pop_back(); 83 fStack.pop_back();
60 } 84 }
61 85
62 void addBatch(const char* name, const SkRect& bounds) { 86 void addBatch(const char* name, const SkRect& bounds) {
63 SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && !fStack.empty()); 87 SkASSERT(fEnabled && !fStack.empty());
64 Batch* batch = new Batch; 88 Batch* batch = new Batch;
65 fStack.back()->fChildren.emplace_back(batch); 89 fStack.back()->fChildren.emplace_back(batch);
66 batch->fName = name; 90 batch->fName = name;
67 batch->fBounds = bounds; 91 batch->fBounds = bounds;
68 } 92 }
69 93
70 SkString toJson(bool prettyPrint = false) const; 94 SkString toJson(bool prettyPrint = false) const;
71 95
72 void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && fStack.empty()); fFrame s.reset(); } 96 bool isEnabled() { return fEnabled; }
97 void setEnabled(bool enabled) { fEnabled = enabled; }
98
99 void reset() { SkASSERT(fEnabled && fStack.empty()); fFrames.reset(); }
73 100
74 private: 101 private:
75 // TODO if performance becomes an issue, we can move to using SkVarAlloc 102 // TODO if performance becomes an issue, we can move to using SkVarAlloc
76 struct Event { 103 struct Event {
77 virtual ~Event() {} 104 virtual ~Event() {}
78 virtual SkString toJson() const=0; 105 virtual SkString toJson() const=0;
79 106
80 const char* fName; 107 const char* fName;
81 uint64_t fUniqueID; 108 uint64_t fUniqueID;
82 }; 109 };
83 110
84 typedef SkTArray<SkAutoTDelete<Event>, true> FrameArray; 111 typedef SkTArray<SkAutoTDelete<Event>, true> FrameArray;
85 struct Frame : public Event { 112 struct Frame : public Event {
86 SkString toJson() const override; 113 SkString toJson() const override;
87 FrameArray fChildren; 114 FrameArray fChildren;
88 }; 115 };
89 116
90 struct Batch : public Event { 117 struct Batch : public Event {
91 SkString toJson() const override; 118 SkString toJson() const override;
92 SkRect fBounds; 119 SkRect fBounds;
93 }; 120 };
94 121
95 static void JsonifyTArray(SkString* json, const char* name, const FrameArray & array, 122 static void JsonifyTArray(SkString* json, const char* name, const FrameArray & array,
96 bool addComma); 123 bool addComma);
97 124
125 bool fEnabled;
98 FrameArray fFrames; 126 FrameArray fFrames;
99 SkTArray<Frame*> fStack; 127 SkTArray<Frame*> fStack;
100 uint64_t fUniqueID; 128 uint64_t fUniqueID;
101 }; 129 };
102 130
103 #define GR_AUDIT_TRAIL_INVOKE_GUARD(invoke, ...) \ 131 #define GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, invoke, ...) \
104 if (GR_BATCH_DEBUGGING_OUTPUT) { \ 132 if (audit_trail->isEnabled()) { \
105 invoke(__VA_ARGS__); \ 133 audit_trail->invoke(__VA_ARGS__); \
106 } 134 }
107 135
108 #define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename) \ 136 #define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename) \
109 GrAuditTrail::AutoFrame SK_MACRO_APPEND_LINE(auto_frame)(audit_trail, framen ame); 137 GrAuditTrail::AutoFrame SK_MACRO_APPEND_LINE(auto_frame)(audit_trail, framen ame);
110 138
111 #define GR_AUDIT_TRAIL_RESET(audit_trail) \ 139 #define GR_AUDIT_TRAIL_RESET(audit_trail) \
112 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->reset); 140 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, reset);
113 141
114 #define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \ 142 #define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \
115 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail->addBatch, batchname, bounds); 143 GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, addBatch, batchname, bounds);
116 144
117 #endif 145 #endif
OLDNEW
« 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