|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_dom_indexeddb_profilerhelpers_h__ |
|
8 #define mozilla_dom_indexeddb_profilerhelpers_h__ |
|
9 |
|
10 #include "GeckoProfiler.h" |
|
11 |
|
12 // Uncomment this if you want IndexedDB operations to be marked in the profiler. |
|
13 //#define IDB_PROFILER_USE_MARKS |
|
14 |
|
15 // Uncomment this if you want extended details to appear in profiler marks. |
|
16 //#define IDB_PROFILER_MARK_DETAILS 0 |
|
17 |
|
18 // Sanity check the options above. |
|
19 #if defined(IDB_PROFILER_USE_MARKS) && !defined(MOZ_ENABLE_PROFILER_SPS) |
|
20 #error Cannot use IDB_PROFILER_USE_MARKS without MOZ_ENABLE_PROFILER_SPS! |
|
21 #endif |
|
22 |
|
23 #if defined(IDB_PROFILER_MARK_DETAILS) && !defined(IDB_PROFILER_USE_MARKS) |
|
24 #error Cannot use IDB_PROFILER_MARK_DETAILS without IDB_PROFILER_USE_MARKS! |
|
25 #endif |
|
26 |
|
27 #ifdef IDB_PROFILER_USE_MARKS |
|
28 |
|
29 #ifdef IDB_PROFILER_MARK_DETAILS |
|
30 |
|
31 #include "IDBCursor.h" |
|
32 #include "IDBDatabase.h" |
|
33 #include "IDBIndex.h" |
|
34 #include "IDBKeyRange.h" |
|
35 #include "IDBObjectStore.h" |
|
36 #include "IDBTransaction.h" |
|
37 #include "Key.h" |
|
38 |
|
39 BEGIN_INDEXEDDB_NAMESPACE |
|
40 |
|
41 class ProfilerString : public nsAutoCString |
|
42 { |
|
43 static const char kQuote = '\"'; |
|
44 static const char kOpenBracket = '['; |
|
45 static const char kCloseBracket = ']'; |
|
46 static const char kOpenParen = '('; |
|
47 static const char kCloseParen = ')'; |
|
48 |
|
49 public: |
|
50 explicit |
|
51 ProfilerString(IDBDatabase* aDatabase) |
|
52 { |
|
53 MOZ_ASSERT(aDatabase); |
|
54 |
|
55 Append(kQuote); |
|
56 AppendUTF16toUTF8(aDatabase->Name(), *this); |
|
57 Append(kQuote); |
|
58 } |
|
59 |
|
60 explicit |
|
61 ProfilerString(IDBTransaction* aTransaction) |
|
62 { |
|
63 MOZ_ASSERT(aTransaction); |
|
64 |
|
65 switch (aTransaction->GetMode()) { |
|
66 case IDBTransaction::READ_ONLY: |
|
67 AppendLiteral("\"readonly\""); |
|
68 break; |
|
69 case IDBTransaction::READ_WRITE: |
|
70 AppendLiteral("\"readwrite\""); |
|
71 break; |
|
72 case IDBTransaction::VERSION_CHANGE: |
|
73 AppendLiteral("\"versionchange\""); |
|
74 break; |
|
75 default: |
|
76 MOZ_CRASH("Unknown mode!"); |
|
77 }; |
|
78 } |
|
79 |
|
80 explicit |
|
81 ProfilerString(IDBObjectStore* aObjectStore) |
|
82 { |
|
83 MOZ_ASSERT(aObjectStore); |
|
84 |
|
85 Append(kQuote); |
|
86 AppendUTF16toUTF8(aObjectStore->Name(), *this); |
|
87 Append(kQuote); |
|
88 } |
|
89 |
|
90 explicit |
|
91 ProfilerString(IDBIndex* aIndex) |
|
92 { |
|
93 MOZ_ASSERT(aIndex); |
|
94 |
|
95 Append(kQuote); |
|
96 AppendUTF16toUTF8(aIndex->Name(), *this); |
|
97 Append(kQuote); |
|
98 } |
|
99 |
|
100 explicit |
|
101 ProfilerString(IDBKeyRange* aKeyRange) |
|
102 { |
|
103 if (aKeyRange) { |
|
104 if (aKeyRange->IsOnly()) { |
|
105 Append(ProfilerString(aKeyRange->Lower())); |
|
106 } |
|
107 else { |
|
108 Append(aKeyRange->IsLowerOpen() ? kOpenParen : kOpenBracket); |
|
109 Append(ProfilerString(aKeyRange->Lower())); |
|
110 AppendLiteral(", "); |
|
111 Append(ProfilerString(aKeyRange->Upper())); |
|
112 Append(aKeyRange->IsUpperOpen() ? kCloseParen : kCloseBracket); |
|
113 } |
|
114 } |
|
115 } |
|
116 |
|
117 explicit |
|
118 ProfilerString(const Key& aKey) |
|
119 { |
|
120 if (aKey.IsUnset()) { |
|
121 Assign("null"); |
|
122 } |
|
123 else if (aKey.IsFloat()) { |
|
124 AppendPrintf("%g", aKey.ToFloat()); |
|
125 } |
|
126 else if (aKey.IsDate()) { |
|
127 AppendPrintf("<Date %g>", aKey.ToDateMsec()); |
|
128 } |
|
129 else if (aKey.IsString()) { |
|
130 nsAutoString str; |
|
131 aKey.ToString(str); |
|
132 AppendPrintf("\"%s\"", NS_ConvertUTF16toUTF8(str).get()); |
|
133 } |
|
134 else { |
|
135 MOZ_ASSERT(aKey.IsArray()); |
|
136 AppendLiteral("<Array>"); |
|
137 } |
|
138 } |
|
139 |
|
140 explicit |
|
141 ProfilerString(const IDBCursor::Direction aDirection) |
|
142 { |
|
143 switch (aDirection) { |
|
144 case IDBCursor::NEXT: |
|
145 AppendLiteral("\"next\""); |
|
146 break; |
|
147 case IDBCursor::NEXT_UNIQUE: |
|
148 AppendLiteral("\"nextunique\""); |
|
149 break; |
|
150 case IDBCursor::PREV: |
|
151 AppendLiteral("\"prev\""); |
|
152 break; |
|
153 case IDBCursor::PREV_UNIQUE: |
|
154 AppendLiteral("\"prevunique\""); |
|
155 break; |
|
156 default: |
|
157 MOZ_CRASH("Unknown direction!"); |
|
158 }; |
|
159 } |
|
160 }; |
|
161 |
|
162 END_INDEXEDDB_NAMESPACE |
|
163 |
|
164 #define IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, ...) \ |
|
165 do { \ |
|
166 nsAutoCString _mark; \ |
|
167 _mark.AppendPrintf(_detailedFmt, ##__VA_ARGS__); \ |
|
168 PROFILER_MARKER(_mark.get()); \ |
|
169 } while (0) |
|
170 |
|
171 #define IDB_PROFILER_STRING(_arg) \ |
|
172 mozilla::dom::indexedDB::ProfilerString((_arg)).get() |
|
173 |
|
174 #else // IDB_PROFILER_MARK_DETAILS |
|
175 |
|
176 #define IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, ...) \ |
|
177 do { \ |
|
178 nsAutoCString _mark; \ |
|
179 _mark.AppendPrintf(_conciseFmt, ##__VA_ARGS__); \ |
|
180 PROFILER_MARKER(_mark.get()); \ |
|
181 } while (0) |
|
182 |
|
183 #define IDB_PROFILER_STRING(_arg) "" |
|
184 |
|
185 #endif // IDB_PROFILER_MARK_DETAILS |
|
186 |
|
187 #define IDB_PROFILER_MARK_IF(_cond, _detailedFmt, _conciseFmt, ...) \ |
|
188 do { \ |
|
189 if (_cond) { \ |
|
190 IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, __VA_ARGS__); \ |
|
191 } \ |
|
192 } while (0) |
|
193 |
|
194 #else // IDB_PROFILER_USE_MARKS |
|
195 |
|
196 #define IDB_PROFILER_MARK(...) do { } while(0) |
|
197 #define IDB_PROFILER_MARK_IF(_cond, ...) do { } while(0) |
|
198 #define IDB_PROFILER_MARK2(_detailedFmt, _notdetailedFmt, ...) do { } while(0) |
|
199 #define IDB_PROFILER_STRING(_arg) "" |
|
200 |
|
201 #endif // IDB_PROFILER_USE_MARKS |
|
202 |
|
203 #endif // mozilla_dom_indexeddb_profilerhelpers_h__ |