michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_indexeddb_profilerhelpers_h__ michael@0: #define mozilla_dom_indexeddb_profilerhelpers_h__ michael@0: michael@0: #include "GeckoProfiler.h" michael@0: michael@0: // Uncomment this if you want IndexedDB operations to be marked in the profiler. michael@0: //#define IDB_PROFILER_USE_MARKS michael@0: michael@0: // Uncomment this if you want extended details to appear in profiler marks. michael@0: //#define IDB_PROFILER_MARK_DETAILS 0 michael@0: michael@0: // Sanity check the options above. michael@0: #if defined(IDB_PROFILER_USE_MARKS) && !defined(MOZ_ENABLE_PROFILER_SPS) michael@0: #error Cannot use IDB_PROFILER_USE_MARKS without MOZ_ENABLE_PROFILER_SPS! michael@0: #endif michael@0: michael@0: #if defined(IDB_PROFILER_MARK_DETAILS) && !defined(IDB_PROFILER_USE_MARKS) michael@0: #error Cannot use IDB_PROFILER_MARK_DETAILS without IDB_PROFILER_USE_MARKS! michael@0: #endif michael@0: michael@0: #ifdef IDB_PROFILER_USE_MARKS michael@0: michael@0: #ifdef IDB_PROFILER_MARK_DETAILS michael@0: michael@0: #include "IDBCursor.h" michael@0: #include "IDBDatabase.h" michael@0: #include "IDBIndex.h" michael@0: #include "IDBKeyRange.h" michael@0: #include "IDBObjectStore.h" michael@0: #include "IDBTransaction.h" michael@0: #include "Key.h" michael@0: michael@0: BEGIN_INDEXEDDB_NAMESPACE michael@0: michael@0: class ProfilerString : public nsAutoCString michael@0: { michael@0: static const char kQuote = '\"'; michael@0: static const char kOpenBracket = '['; michael@0: static const char kCloseBracket = ']'; michael@0: static const char kOpenParen = '('; michael@0: static const char kCloseParen = ')'; michael@0: michael@0: public: michael@0: explicit michael@0: ProfilerString(IDBDatabase* aDatabase) michael@0: { michael@0: MOZ_ASSERT(aDatabase); michael@0: michael@0: Append(kQuote); michael@0: AppendUTF16toUTF8(aDatabase->Name(), *this); michael@0: Append(kQuote); michael@0: } michael@0: michael@0: explicit michael@0: ProfilerString(IDBTransaction* aTransaction) michael@0: { michael@0: MOZ_ASSERT(aTransaction); michael@0: michael@0: switch (aTransaction->GetMode()) { michael@0: case IDBTransaction::READ_ONLY: michael@0: AppendLiteral("\"readonly\""); michael@0: break; michael@0: case IDBTransaction::READ_WRITE: michael@0: AppendLiteral("\"readwrite\""); michael@0: break; michael@0: case IDBTransaction::VERSION_CHANGE: michael@0: AppendLiteral("\"versionchange\""); michael@0: break; michael@0: default: michael@0: MOZ_CRASH("Unknown mode!"); michael@0: }; michael@0: } michael@0: michael@0: explicit michael@0: ProfilerString(IDBObjectStore* aObjectStore) michael@0: { michael@0: MOZ_ASSERT(aObjectStore); michael@0: michael@0: Append(kQuote); michael@0: AppendUTF16toUTF8(aObjectStore->Name(), *this); michael@0: Append(kQuote); michael@0: } michael@0: michael@0: explicit michael@0: ProfilerString(IDBIndex* aIndex) michael@0: { michael@0: MOZ_ASSERT(aIndex); michael@0: michael@0: Append(kQuote); michael@0: AppendUTF16toUTF8(aIndex->Name(), *this); michael@0: Append(kQuote); michael@0: } michael@0: michael@0: explicit michael@0: ProfilerString(IDBKeyRange* aKeyRange) michael@0: { michael@0: if (aKeyRange) { michael@0: if (aKeyRange->IsOnly()) { michael@0: Append(ProfilerString(aKeyRange->Lower())); michael@0: } michael@0: else { michael@0: Append(aKeyRange->IsLowerOpen() ? kOpenParen : kOpenBracket); michael@0: Append(ProfilerString(aKeyRange->Lower())); michael@0: AppendLiteral(", "); michael@0: Append(ProfilerString(aKeyRange->Upper())); michael@0: Append(aKeyRange->IsUpperOpen() ? kCloseParen : kCloseBracket); michael@0: } michael@0: } michael@0: } michael@0: michael@0: explicit michael@0: ProfilerString(const Key& aKey) michael@0: { michael@0: if (aKey.IsUnset()) { michael@0: Assign("null"); michael@0: } michael@0: else if (aKey.IsFloat()) { michael@0: AppendPrintf("%g", aKey.ToFloat()); michael@0: } michael@0: else if (aKey.IsDate()) { michael@0: AppendPrintf("", aKey.ToDateMsec()); michael@0: } michael@0: else if (aKey.IsString()) { michael@0: nsAutoString str; michael@0: aKey.ToString(str); michael@0: AppendPrintf("\"%s\"", NS_ConvertUTF16toUTF8(str).get()); michael@0: } michael@0: else { michael@0: MOZ_ASSERT(aKey.IsArray()); michael@0: AppendLiteral(""); michael@0: } michael@0: } michael@0: michael@0: explicit michael@0: ProfilerString(const IDBCursor::Direction aDirection) michael@0: { michael@0: switch (aDirection) { michael@0: case IDBCursor::NEXT: michael@0: AppendLiteral("\"next\""); michael@0: break; michael@0: case IDBCursor::NEXT_UNIQUE: michael@0: AppendLiteral("\"nextunique\""); michael@0: break; michael@0: case IDBCursor::PREV: michael@0: AppendLiteral("\"prev\""); michael@0: break; michael@0: case IDBCursor::PREV_UNIQUE: michael@0: AppendLiteral("\"prevunique\""); michael@0: break; michael@0: default: michael@0: MOZ_CRASH("Unknown direction!"); michael@0: }; michael@0: } michael@0: }; michael@0: michael@0: END_INDEXEDDB_NAMESPACE michael@0: michael@0: #define IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, ...) \ michael@0: do { \ michael@0: nsAutoCString _mark; \ michael@0: _mark.AppendPrintf(_detailedFmt, ##__VA_ARGS__); \ michael@0: PROFILER_MARKER(_mark.get()); \ michael@0: } while (0) michael@0: michael@0: #define IDB_PROFILER_STRING(_arg) \ michael@0: mozilla::dom::indexedDB::ProfilerString((_arg)).get() michael@0: michael@0: #else // IDB_PROFILER_MARK_DETAILS michael@0: michael@0: #define IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, ...) \ michael@0: do { \ michael@0: nsAutoCString _mark; \ michael@0: _mark.AppendPrintf(_conciseFmt, ##__VA_ARGS__); \ michael@0: PROFILER_MARKER(_mark.get()); \ michael@0: } while (0) michael@0: michael@0: #define IDB_PROFILER_STRING(_arg) "" michael@0: michael@0: #endif // IDB_PROFILER_MARK_DETAILS michael@0: michael@0: #define IDB_PROFILER_MARK_IF(_cond, _detailedFmt, _conciseFmt, ...) \ michael@0: do { \ michael@0: if (_cond) { \ michael@0: IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, __VA_ARGS__); \ michael@0: } \ michael@0: } while (0) michael@0: michael@0: #else // IDB_PROFILER_USE_MARKS michael@0: michael@0: #define IDB_PROFILER_MARK(...) do { } while(0) michael@0: #define IDB_PROFILER_MARK_IF(_cond, ...) do { } while(0) michael@0: #define IDB_PROFILER_MARK2(_detailedFmt, _notdetailedFmt, ...) do { } while(0) michael@0: #define IDB_PROFILER_STRING(_arg) "" michael@0: michael@0: #endif // IDB_PROFILER_USE_MARKS michael@0: michael@0: #endif // mozilla_dom_indexeddb_profilerhelpers_h__