bug 700693 - OCSP stapling PSM changes r=bsmith
[gecko.git] / dom / indexedDB / ProfilerHelpers.h
blob0f9fa677f5f25677d32fd60f11b33590398897dd
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/. */
7 #ifndef mozilla_dom_indexeddb_profilerhelpers_h__
8 #define mozilla_dom_indexeddb_profilerhelpers_h__
10 #include "GeckoProfiler.h"
12 // Uncomment this if you want IndexedDB operations to be marked in the profiler.
13 //#define IDB_PROFILER_USE_MARKS
15 // Uncomment this if you want extended details to appear in profiler marks.
16 //#define IDB_PROFILER_MARK_DETAILS 0
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
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
27 #ifdef IDB_PROFILER_USE_MARKS
29 #ifdef IDB_PROFILER_MARK_DETAILS
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"
39 BEGIN_INDEXEDDB_NAMESPACE
41 class ProfilerString : public nsAutoCString
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 = ')';
49 public:
50 explicit
51 ProfilerString(IDBDatabase* aDatabase)
53 MOZ_ASSERT(aDatabase);
55 Append(kQuote);
56 AppendUTF16toUTF8(aDatabase->Name(), *this);
57 Append(kQuote);
60 explicit
61 ProfilerString(IDBTransaction* aTransaction)
63 MOZ_ASSERT(aTransaction);
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_NOT_REACHED("Unknown mode!");
80 explicit
81 ProfilerString(IDBObjectStore* aObjectStore)
83 MOZ_ASSERT(aObjectStore);
85 Append(kQuote);
86 AppendUTF16toUTF8(aObjectStore->Name(), *this);
87 Append(kQuote);
90 explicit
91 ProfilerString(IDBIndex* aIndex)
93 MOZ_ASSERT(aIndex);
95 Append(kQuote);
96 AppendUTF16toUTF8(aIndex->Name(), *this);
97 Append(kQuote);
100 explicit
101 ProfilerString(IDBKeyRange* aKeyRange)
103 if (aKeyRange) {
104 if (aKeyRange->IsOnly()) {
105 Append(ProfilerString(aKeyRange->Lower()));
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);
117 explicit
118 ProfilerString(const Key& aKey)
120 if (aKey.IsUnset()) {
121 Assign("null");
123 else if (aKey.IsFloat()) {
124 AppendPrintf("%g", aKey.ToFloat());
126 else if (aKey.IsDate()) {
127 AppendPrintf("<Date %g>", aKey.ToDateMsec());
129 else if (aKey.IsString()) {
130 nsAutoString str;
131 aKey.ToString(str);
132 AppendPrintf("\"%s\"", NS_ConvertUTF16toUTF8(str).get());
134 else {
135 MOZ_ASSERT(aKey.IsArray());
136 AppendLiteral("<Array>");
140 explicit
141 ProfilerString(const IDBCursor::Direction aDirection)
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_NOT_REACHED("Unknown direction!");
162 END_INDEXEDDB_NAMESPACE
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)
171 #define IDB_PROFILER_STRING(_arg) \
172 mozilla::dom::indexedDB::ProfilerString((_arg)).get()
174 #else // IDB_PROFILER_MARK_DETAILS
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)
183 #define IDB_PROFILER_STRING(_arg) ""
185 #endif // IDB_PROFILER_MARK_DETAILS
187 #define IDB_PROFILER_MARK_IF(_cond, _detailedFmt, _conciseFmt, ...) \
188 do { \
189 if (_cond) { \
190 IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, __VA_ARGS__); \
192 } while (0)
194 #else // IDB_PROFILER_USE_MARKS
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) ""
201 #endif // IDB_PROFILER_USE_MARKS
203 #endif // mozilla_dom_indexeddb_profilerhelpers_h__