1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/ProfilerHelpers.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,203 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_indexeddb_profilerhelpers_h__ 1.11 +#define mozilla_dom_indexeddb_profilerhelpers_h__ 1.12 + 1.13 +#include "GeckoProfiler.h" 1.14 + 1.15 +// Uncomment this if you want IndexedDB operations to be marked in the profiler. 1.16 +//#define IDB_PROFILER_USE_MARKS 1.17 + 1.18 +// Uncomment this if you want extended details to appear in profiler marks. 1.19 +//#define IDB_PROFILER_MARK_DETAILS 0 1.20 + 1.21 +// Sanity check the options above. 1.22 +#if defined(IDB_PROFILER_USE_MARKS) && !defined(MOZ_ENABLE_PROFILER_SPS) 1.23 +#error Cannot use IDB_PROFILER_USE_MARKS without MOZ_ENABLE_PROFILER_SPS! 1.24 +#endif 1.25 + 1.26 +#if defined(IDB_PROFILER_MARK_DETAILS) && !defined(IDB_PROFILER_USE_MARKS) 1.27 +#error Cannot use IDB_PROFILER_MARK_DETAILS without IDB_PROFILER_USE_MARKS! 1.28 +#endif 1.29 + 1.30 +#ifdef IDB_PROFILER_USE_MARKS 1.31 + 1.32 +#ifdef IDB_PROFILER_MARK_DETAILS 1.33 + 1.34 +#include "IDBCursor.h" 1.35 +#include "IDBDatabase.h" 1.36 +#include "IDBIndex.h" 1.37 +#include "IDBKeyRange.h" 1.38 +#include "IDBObjectStore.h" 1.39 +#include "IDBTransaction.h" 1.40 +#include "Key.h" 1.41 + 1.42 +BEGIN_INDEXEDDB_NAMESPACE 1.43 + 1.44 +class ProfilerString : public nsAutoCString 1.45 +{ 1.46 + static const char kQuote = '\"'; 1.47 + static const char kOpenBracket = '['; 1.48 + static const char kCloseBracket = ']'; 1.49 + static const char kOpenParen = '('; 1.50 + static const char kCloseParen = ')'; 1.51 + 1.52 +public: 1.53 + explicit 1.54 + ProfilerString(IDBDatabase* aDatabase) 1.55 + { 1.56 + MOZ_ASSERT(aDatabase); 1.57 + 1.58 + Append(kQuote); 1.59 + AppendUTF16toUTF8(aDatabase->Name(), *this); 1.60 + Append(kQuote); 1.61 + } 1.62 + 1.63 + explicit 1.64 + ProfilerString(IDBTransaction* aTransaction) 1.65 + { 1.66 + MOZ_ASSERT(aTransaction); 1.67 + 1.68 + switch (aTransaction->GetMode()) { 1.69 + case IDBTransaction::READ_ONLY: 1.70 + AppendLiteral("\"readonly\""); 1.71 + break; 1.72 + case IDBTransaction::READ_WRITE: 1.73 + AppendLiteral("\"readwrite\""); 1.74 + break; 1.75 + case IDBTransaction::VERSION_CHANGE: 1.76 + AppendLiteral("\"versionchange\""); 1.77 + break; 1.78 + default: 1.79 + MOZ_CRASH("Unknown mode!"); 1.80 + }; 1.81 + } 1.82 + 1.83 + explicit 1.84 + ProfilerString(IDBObjectStore* aObjectStore) 1.85 + { 1.86 + MOZ_ASSERT(aObjectStore); 1.87 + 1.88 + Append(kQuote); 1.89 + AppendUTF16toUTF8(aObjectStore->Name(), *this); 1.90 + Append(kQuote); 1.91 + } 1.92 + 1.93 + explicit 1.94 + ProfilerString(IDBIndex* aIndex) 1.95 + { 1.96 + MOZ_ASSERT(aIndex); 1.97 + 1.98 + Append(kQuote); 1.99 + AppendUTF16toUTF8(aIndex->Name(), *this); 1.100 + Append(kQuote); 1.101 + } 1.102 + 1.103 + explicit 1.104 + ProfilerString(IDBKeyRange* aKeyRange) 1.105 + { 1.106 + if (aKeyRange) { 1.107 + if (aKeyRange->IsOnly()) { 1.108 + Append(ProfilerString(aKeyRange->Lower())); 1.109 + } 1.110 + else { 1.111 + Append(aKeyRange->IsLowerOpen() ? kOpenParen : kOpenBracket); 1.112 + Append(ProfilerString(aKeyRange->Lower())); 1.113 + AppendLiteral(", "); 1.114 + Append(ProfilerString(aKeyRange->Upper())); 1.115 + Append(aKeyRange->IsUpperOpen() ? kCloseParen : kCloseBracket); 1.116 + } 1.117 + } 1.118 + } 1.119 + 1.120 + explicit 1.121 + ProfilerString(const Key& aKey) 1.122 + { 1.123 + if (aKey.IsUnset()) { 1.124 + Assign("null"); 1.125 + } 1.126 + else if (aKey.IsFloat()) { 1.127 + AppendPrintf("%g", aKey.ToFloat()); 1.128 + } 1.129 + else if (aKey.IsDate()) { 1.130 + AppendPrintf("<Date %g>", aKey.ToDateMsec()); 1.131 + } 1.132 + else if (aKey.IsString()) { 1.133 + nsAutoString str; 1.134 + aKey.ToString(str); 1.135 + AppendPrintf("\"%s\"", NS_ConvertUTF16toUTF8(str).get()); 1.136 + } 1.137 + else { 1.138 + MOZ_ASSERT(aKey.IsArray()); 1.139 + AppendLiteral("<Array>"); 1.140 + } 1.141 + } 1.142 + 1.143 + explicit 1.144 + ProfilerString(const IDBCursor::Direction aDirection) 1.145 + { 1.146 + switch (aDirection) { 1.147 + case IDBCursor::NEXT: 1.148 + AppendLiteral("\"next\""); 1.149 + break; 1.150 + case IDBCursor::NEXT_UNIQUE: 1.151 + AppendLiteral("\"nextunique\""); 1.152 + break; 1.153 + case IDBCursor::PREV: 1.154 + AppendLiteral("\"prev\""); 1.155 + break; 1.156 + case IDBCursor::PREV_UNIQUE: 1.157 + AppendLiteral("\"prevunique\""); 1.158 + break; 1.159 + default: 1.160 + MOZ_CRASH("Unknown direction!"); 1.161 + }; 1.162 + } 1.163 +}; 1.164 + 1.165 +END_INDEXEDDB_NAMESPACE 1.166 + 1.167 +#define IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, ...) \ 1.168 + do { \ 1.169 + nsAutoCString _mark; \ 1.170 + _mark.AppendPrintf(_detailedFmt, ##__VA_ARGS__); \ 1.171 + PROFILER_MARKER(_mark.get()); \ 1.172 + } while (0) 1.173 + 1.174 +#define IDB_PROFILER_STRING(_arg) \ 1.175 + mozilla::dom::indexedDB::ProfilerString((_arg)).get() 1.176 + 1.177 +#else // IDB_PROFILER_MARK_DETAILS 1.178 + 1.179 +#define IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, ...) \ 1.180 + do { \ 1.181 + nsAutoCString _mark; \ 1.182 + _mark.AppendPrintf(_conciseFmt, ##__VA_ARGS__); \ 1.183 + PROFILER_MARKER(_mark.get()); \ 1.184 + } while (0) 1.185 + 1.186 +#define IDB_PROFILER_STRING(_arg) "" 1.187 + 1.188 +#endif // IDB_PROFILER_MARK_DETAILS 1.189 + 1.190 +#define IDB_PROFILER_MARK_IF(_cond, _detailedFmt, _conciseFmt, ...) \ 1.191 + do { \ 1.192 + if (_cond) { \ 1.193 + IDB_PROFILER_MARK(_detailedFmt, _conciseFmt, __VA_ARGS__); \ 1.194 + } \ 1.195 + } while (0) 1.196 + 1.197 +#else // IDB_PROFILER_USE_MARKS 1.198 + 1.199 +#define IDB_PROFILER_MARK(...) do { } while(0) 1.200 +#define IDB_PROFILER_MARK_IF(_cond, ...) do { } while(0) 1.201 +#define IDB_PROFILER_MARK2(_detailedFmt, _notdetailedFmt, ...) do { } while(0) 1.202 +#define IDB_PROFILER_STRING(_arg) "" 1.203 + 1.204 +#endif // IDB_PROFILER_USE_MARKS 1.205 + 1.206 +#endif // mozilla_dom_indexeddb_profilerhelpers_h__