ProfilerHelpers.h (6791B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=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/. */ 6 7 #ifndef mozilla_dom_indexeddb_profilerhelpers_h__ 8 #define mozilla_dom_indexeddb_profilerhelpers_h__ 9 10 // This file is not exported and is only meant to be included in IndexedDB 11 // source files. 12 13 #include "IndexedDatabaseManager.h" 14 #include "mozilla/dom/BindingDeclarations.h" 15 #include "mozilla/dom/IDBCursorBinding.h" 16 #include "nsID.h" 17 #include "nsString.h" 18 19 namespace mozilla::dom { 20 21 class Event; 22 class IDBDatabase; 23 class IDBIndex; 24 class IDBKeyRange; 25 class IDBObjectStore; 26 class IDBTransaction; 27 28 namespace indexedDB { 29 30 class Key; 31 32 template <bool CheckLoggingMode> 33 class LoggingIdString final : public nsAutoCStringN<NSID_LENGTH> { 34 public: 35 LoggingIdString(); 36 37 explicit LoggingIdString(const nsID& aID); 38 }; 39 40 class MOZ_STACK_CLASS LoggingString final : public nsAutoCString { 41 public: 42 explicit LoggingString(IDBDatabase* aDatabase); 43 explicit LoggingString(const IDBTransaction& aTransaction); 44 explicit LoggingString(IDBObjectStore* aObjectStore); 45 explicit LoggingString(IDBIndex* aIndex); 46 explicit LoggingString(IDBKeyRange* aKeyRange); 47 explicit LoggingString(const Key& aKey); 48 explicit LoggingString(const IDBCursorDirection aDirection); 49 explicit LoggingString(const Optional<uint64_t>& aVersion); 50 explicit LoggingString(const Optional<uint32_t>& aLimit); 51 52 LoggingString(IDBObjectStore* aObjectStore, const Key& aKey); 53 LoggingString(Event* aEvent, const char16_t* aDefault); 54 }; 55 56 // Both the aDetailedFmt and the aConciseFmt need to match the variable argument 57 // list, so we use MOZ_FORMAT_PRINTF twice here. 58 void MOZ_FORMAT_PRINTF(1, 3) MOZ_FORMAT_PRINTF(2, 3) 59 LoggingHelper(const char* aDetailedFmt, const char* aConciseFmt, ...); 60 61 } // namespace indexedDB 62 } // namespace mozilla::dom 63 64 #define IDB_LOG_MARK(_detailedFmt, _conciseFmt, _loggingId, ...) \ 65 mozilla::dom::indexedDB::LoggingHelper("IndexedDB %s: " _detailedFmt, \ 66 "IndexedDB %s: " _conciseFmt, \ 67 _loggingId, ##__VA_ARGS__) 68 69 #define IDB_LOG_ID_STRING(...) \ 70 mozilla::dom::indexedDB::LoggingIdString<true>(__VA_ARGS__).get() 71 72 #define IDB_LOG_STRINGIFY(...) \ 73 mozilla::dom::indexedDB::LoggingString(__VA_ARGS__).get() 74 75 // IDB_LOG_MARK_DETAILED_PARENT and IDB_LOG_MARK_DETAILED_CHILD should have the 76 // same width. 77 #define IDB_LOG_MARK_DETAILED_PARENT "Parent" 78 #define IDB_LOG_MARK_DETAILED_CHILD "Child " 79 80 #define IDB_LOG_MARK_CONCISE_PARENT "P" 81 #define IDB_LOG_MARK_CONCISE_CHILD "C" 82 83 #define IDB_LOG_MARK_DETAILED_TRANSACTION "Transaction[%" PRIi64 "]" 84 #define IDB_LOG_MARK_DETAILED_REQUEST "Request[%" PRIu64 "]" 85 86 #define IDB_LOG_MARK_CONCISE_TRANSACTION "T[%" PRIi64 "]" 87 #define IDB_LOG_MARK_CONCISE_REQUEST "R[%" PRIu64 "]" 88 89 #define IDB_LOG_MARK_TRANSACTION_REQUEST( \ 90 _detailedPeer, _concisePeer, _detailedFmt, _conciseFmt, _loggingId, \ 91 _transactionSerialNumber, _requestSerialNumber, ...) \ 92 IDB_LOG_MARK(_detailedPeer " " IDB_LOG_MARK_DETAILED_TRANSACTION \ 93 " " IDB_LOG_MARK_DETAILED_REQUEST \ 94 ": " _detailedFmt, \ 95 _concisePeer " " IDB_LOG_MARK_CONCISE_TRANSACTION \ 96 " " IDB_LOG_MARK_CONCISE_REQUEST ": " _conciseFmt, \ 97 _loggingId, _transactionSerialNumber, _requestSerialNumber, \ 98 ##__VA_ARGS__) 99 100 #define IDB_LOG_MARK_PARENT_TRANSACTION_REQUEST( \ 101 _detailedFmt, _conciseFmt, _loggingId, _transactionSerialNumber, \ 102 _requestSerialNumber, ...) \ 103 IDB_LOG_MARK_TRANSACTION_REQUEST( \ 104 IDB_LOG_MARK_DETAILED_PARENT, IDB_LOG_MARK_CONCISE_PARENT, _detailedFmt, \ 105 _conciseFmt, _loggingId, _transactionSerialNumber, _requestSerialNumber, \ 106 ##__VA_ARGS__) 107 108 #define IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(_detailedFmt, _conciseFmt, \ 109 _transactionSerialNumber, \ 110 _requestSerialNumber, ...) \ 111 IDB_LOG_MARK_TRANSACTION_REQUEST( \ 112 IDB_LOG_MARK_DETAILED_CHILD, IDB_LOG_MARK_CONCISE_CHILD, _detailedFmt, \ 113 _conciseFmt, IDB_LOG_ID_STRING(), _transactionSerialNumber, \ 114 _requestSerialNumber, ##__VA_ARGS__) 115 116 #define IDB_LOG_MARK_CHILD_REQUEST(_detailedFmt, _conciseFmt, \ 117 _requestSerialNumber, ...) \ 118 IDB_LOG_MARK(IDB_LOG_MARK_DETAILED_CHILD " " IDB_LOG_MARK_DETAILED_REQUEST \ 119 ": " _detailedFmt, \ 120 IDB_LOG_MARK_CONCISE_CHILD " " IDB_LOG_MARK_CONCISE_REQUEST \ 121 ": " _conciseFmt, \ 122 IDB_LOG_ID_STRING(), _requestSerialNumber, ##__VA_ARGS__) 123 124 #define IDB_LOG_MARK_TRANSACTION(_detailedPeer, _concisePeer, _detailedFmt, \ 125 _conciseFmt, _loggingId, \ 126 _transactionSerialNumber, ...) \ 127 IDB_LOG_MARK( \ 128 _detailedPeer " " IDB_LOG_MARK_DETAILED_TRANSACTION ": " _detailedFmt, \ 129 _concisePeer " " IDB_LOG_MARK_CONCISE_TRANSACTION ": " _conciseFmt, \ 130 _loggingId, _transactionSerialNumber, ##__VA_ARGS__) 131 132 #define IDB_LOG_MARK_PARENT_TRANSACTION(_detailedFmt, _conciseFmt, _loggingId, \ 133 _transactionSerialNumber, ...) \ 134 IDB_LOG_MARK_TRANSACTION( \ 135 IDB_LOG_MARK_DETAILED_PARENT, IDB_LOG_MARK_CONCISE_PARENT, _detailedFmt, \ 136 _conciseFmt, _loggingId, _transactionSerialNumber, ##__VA_ARGS__) 137 138 #define IDB_LOG_MARK_CHILD_TRANSACTION(_detailedFmt, _conciseFmt, \ 139 _transactionSerialNumber, ...) \ 140 IDB_LOG_MARK_TRANSACTION(IDB_LOG_MARK_DETAILED_CHILD, \ 141 IDB_LOG_MARK_CONCISE_CHILD, _detailedFmt, \ 142 _conciseFmt, IDB_LOG_ID_STRING(), \ 143 _transactionSerialNumber, ##__VA_ARGS__) 144 145 #endif // mozilla_dom_indexeddb_profilerhelpers_h__