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!
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!
27 #ifdef IDB_PROFILER_USE_MARKS
29 #ifdef IDB_PROFILER_MARK_DETAILS
31 #include "IDBCursor.h"
32 #include "IDBDatabase.h"
34 #include "IDBKeyRange.h"
35 #include "IDBObjectStore.h"
36 #include "IDBTransaction.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
= ')';
51 ProfilerString(IDBDatabase
* aDatabase
)
53 MOZ_ASSERT(aDatabase
);
56 AppendUTF16toUTF8(aDatabase
->Name(), *this);
61 ProfilerString(IDBTransaction
* aTransaction
)
63 MOZ_ASSERT(aTransaction
);
65 switch (aTransaction
->GetMode()) {
66 case IDBTransaction::READ_ONLY
:
67 AppendLiteral("\"readonly\"");
69 case IDBTransaction::READ_WRITE
:
70 AppendLiteral("\"readwrite\"");
72 case IDBTransaction::VERSION_CHANGE
:
73 AppendLiteral("\"versionchange\"");
76 MOZ_NOT_REACHED("Unknown mode!");
81 ProfilerString(IDBObjectStore
* aObjectStore
)
83 MOZ_ASSERT(aObjectStore
);
86 AppendUTF16toUTF8(aObjectStore
->Name(), *this);
91 ProfilerString(IDBIndex
* aIndex
)
96 AppendUTF16toUTF8(aIndex
->Name(), *this);
101 ProfilerString(IDBKeyRange
* aKeyRange
)
104 if (aKeyRange
->IsOnly()) {
105 Append(ProfilerString(aKeyRange
->Lower()));
108 Append(aKeyRange
->IsLowerOpen() ? kOpenParen
: kOpenBracket
);
109 Append(ProfilerString(aKeyRange
->Lower()));
111 Append(ProfilerString(aKeyRange
->Upper()));
112 Append(aKeyRange
->IsUpperOpen() ? kCloseParen
: kCloseBracket
);
118 ProfilerString(const Key
& aKey
)
120 if (aKey
.IsUnset()) {
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()) {
132 AppendPrintf("\"%s\"", NS_ConvertUTF16toUTF8(str
).get());
135 MOZ_ASSERT(aKey
.IsArray());
136 AppendLiteral("<Array>");
141 ProfilerString(const IDBCursor::Direction aDirection
)
143 switch (aDirection
) {
144 case IDBCursor::NEXT
:
145 AppendLiteral("\"next\"");
147 case IDBCursor::NEXT_UNIQUE
:
148 AppendLiteral("\"nextunique\"");
150 case IDBCursor::PREV
:
151 AppendLiteral("\"prev\"");
153 case IDBCursor::PREV_UNIQUE
:
154 AppendLiteral("\"prevunique\"");
157 MOZ_NOT_REACHED("Unknown direction!");
162 END_INDEXEDDB_NAMESPACE
164 #define IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, ...) \
166 nsAutoCString _mark; \
167 _mark.AppendPrintf(_detailedFmt, ##__VA_ARGS__); \
168 PROFILER_MARKER(_mark.get()); \
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, ...) \
178 nsAutoCString _mark; \
179 _mark.AppendPrintf(_conciseFmt, ##__VA_ARGS__); \
180 PROFILER_MARKER(_mark.get()); \
183 #define IDB_PROFILER_STRING(_arg) ""
185 #endif // IDB_PROFILER_MARK_DETAILS
187 #define IDB_PROFILER_MARK_IF(_cond, _detailedFmt, _conciseFmt, ...) \
190 IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, __VA_ARGS__); \
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__