dom/indexedDB/ProfilerHelpers.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial