Bug 1650076 - Move ProfilerHelpers implementation into cpp file. r=dom-workers-and-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D82014
This commit is contained in:
Simon Giesecke 2020-07-03 09:38:41 +00:00
Родитель ec0b99bf07
Коммит 5d197908e3
5 изменённых файлов: 296 добавлений и 251 удалений

Просмотреть файл

@ -7,6 +7,7 @@
#include "IDBIndex.h" #include "IDBIndex.h"
#include "IDBCursorType.h" #include "IDBCursorType.h"
#include "IDBDatabase.h"
#include "IDBEvents.h" #include "IDBEvents.h"
#include "IDBKeyRange.h" #include "IDBKeyRange.h"
#include "IDBObjectStore.h" #include "IDBObjectStore.h"

Просмотреть файл

@ -26,6 +26,7 @@
#include "nsGlobalWindow.h" #include "nsGlobalWindow.h"
#include "mozilla/Logging.h" #include "mozilla/Logging.h"
#include "ActorsChild.h"
#include "FileManager.h" #include "FileManager.h"
#include "IDBEvents.h" #include "IDBEvents.h"
#include "IDBFactory.h" #include "IDBFactory.h"

Просмотреть файл

@ -0,0 +1,267 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ProfilerHelpers.h"
#include "ActorsChild.h"
#include "BackgroundChildImpl.h"
#include "GeckoProfiler.h"
#include "IDBDatabase.h"
#include "IDBIndex.h"
#include "IDBKeyRange.h"
#include "IDBObjectStore.h"
#include "IDBTransaction.h"
#include "Key.h"
namespace mozilla {
namespace dom {
namespace indexedDB {
namespace {
static const char kQuote = '\"';
static const char kOpenBracket = '[';
static const char kCloseBracket = ']';
static const char kOpenParen = '(';
static const char kCloseParen = ')';
} // namespace
LoggingIdString::LoggingIdString() {
using mozilla::ipc::BackgroundChildImpl;
if (IndexedDatabaseManager::GetLoggingMode() !=
IndexedDatabaseManager::Logging_Disabled) {
const BackgroundChildImpl::ThreadLocal* threadLocal =
BackgroundChildImpl::GetThreadLocalForCurrentThread();
if (threadLocal) {
const auto& idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
if (idbThreadLocal) {
Assign(idbThreadLocal->IdString());
}
}
}
}
LoggingIdString::LoggingIdString(const nsID& aID) {
static_assert(NSID_LENGTH > 1, "NSID_LENGTH is set incorrectly!");
static_assert(NSID_LENGTH <= kStorageSize,
"nsID string won't fit in our storage!");
// Capacity() excludes the null terminator; NSID_LENGTH includes it.
MOZ_ASSERT(Capacity() + 1 == NSID_LENGTH);
if (IndexedDatabaseManager::GetLoggingMode() !=
IndexedDatabaseManager::Logging_Disabled) {
// NSID_LENGTH counts the null terminator, SetLength() does not.
SetLength(NSID_LENGTH - 1);
aID.ToProvidedString(
*reinterpret_cast<char(*)[NSID_LENGTH]>(BeginWriting()));
}
}
LoggingString::LoggingString(IDBDatabase* aDatabase) : nsAutoCString(kQuote) {
MOZ_ASSERT(aDatabase);
AppendUTF16toUTF8(aDatabase->Name(), *this);
Append(kQuote);
}
LoggingString::LoggingString(const IDBTransaction& aTransaction)
: nsAutoCString(kOpenBracket) {
constexpr auto kCommaSpace = ", "_ns;
const nsTArray<nsString>& stores = aTransaction.ObjectStoreNamesInternal();
for (uint32_t count = stores.Length(), index = 0; index < count; index++) {
Append(kQuote);
AppendUTF16toUTF8(stores[index], *this);
Append(kQuote);
if (index != count - 1) {
Append(kCommaSpace);
}
}
Append(kCloseBracket);
Append(kCommaSpace);
switch (aTransaction.GetMode()) {
case IDBTransaction::Mode::ReadOnly:
AppendLiteral("\"readonly\"");
break;
case IDBTransaction::Mode::ReadWrite:
AppendLiteral("\"readwrite\"");
break;
case IDBTransaction::Mode::ReadWriteFlush:
AppendLiteral("\"readwriteflush\"");
break;
case IDBTransaction::Mode::Cleanup:
AppendLiteral("\"cleanup\"");
break;
case IDBTransaction::Mode::VersionChange:
AppendLiteral("\"versionchange\"");
break;
default:
MOZ_CRASH("Unknown mode!");
};
}
LoggingString::LoggingString(IDBObjectStore* aObjectStore)
: nsAutoCString(kQuote) {
MOZ_ASSERT(aObjectStore);
AppendUTF16toUTF8(aObjectStore->Name(), *this);
Append(kQuote);
}
LoggingString::LoggingString(IDBIndex* aIndex) : nsAutoCString(kQuote) {
MOZ_ASSERT(aIndex);
AppendUTF16toUTF8(aIndex->Name(), *this);
Append(kQuote);
}
LoggingString::LoggingString(IDBKeyRange* aKeyRange) {
if (aKeyRange) {
if (aKeyRange->IsOnly()) {
Assign(LoggingString(aKeyRange->Lower()));
} else {
if (aKeyRange->LowerOpen()) {
Assign(kOpenParen);
} else {
Assign(kOpenBracket);
}
Append(LoggingString(aKeyRange->Lower()));
AppendLiteral(", ");
Append(LoggingString(aKeyRange->Upper()));
if (aKeyRange->UpperOpen()) {
Append(kCloseParen);
} else {
Append(kCloseBracket);
}
}
} else {
AssignLiteral("<undefined>");
}
}
LoggingString::LoggingString(const Key& aKey) {
if (aKey.IsUnset()) {
AssignLiteral("<undefined>");
} else if (aKey.IsFloat()) {
AppendPrintf("%g", aKey.ToFloat());
} else if (aKey.IsDate()) {
AppendPrintf("<Date %g>", aKey.ToDateMsec());
} else if (aKey.IsString()) {
AppendPrintf("\"%s\"", NS_ConvertUTF16toUTF8(aKey.ToString()).get());
} else if (aKey.IsBinary()) {
AssignLiteral("[object ArrayBuffer]");
} else {
MOZ_ASSERT(aKey.IsArray());
AssignLiteral("[...]");
}
}
LoggingString::LoggingString(const IDBCursorDirection aDirection) {
switch (aDirection) {
case IDBCursorDirection::Next:
AssignLiteral("\"next\"");
break;
case IDBCursorDirection::Nextunique:
AssignLiteral("\"nextunique\"");
break;
case IDBCursorDirection::Prev:
AssignLiteral("\"prev\"");
break;
case IDBCursorDirection::Prevunique:
AssignLiteral("\"prevunique\"");
break;
default:
MOZ_CRASH("Unknown direction!");
};
}
LoggingString::LoggingString(const Optional<uint64_t>& aVersion) {
if (aVersion.WasPassed()) {
AppendInt(aVersion.Value());
} else {
AssignLiteral("<undefined>");
}
}
LoggingString::LoggingString(const Optional<uint32_t>& aLimit) {
if (aLimit.WasPassed()) {
AppendInt(aLimit.Value());
} else {
AssignLiteral("<undefined>");
}
}
LoggingString::LoggingString(IDBObjectStore* aObjectStore, const Key& aKey) {
MOZ_ASSERT(aObjectStore);
if (!aObjectStore->HasValidKeyPath()) {
Append(LoggingString(aKey));
}
}
LoggingString::LoggingString(Event* aEvent, const char16_t* aDefault)
: nsAutoCString(kQuote) {
MOZ_ASSERT(aDefault);
nsAutoString eventType;
if (aEvent) {
aEvent->GetType(eventType);
} else {
eventType = nsDependentString(aDefault);
}
AppendUTF16toUTF8(eventType, *this);
Append(kQuote);
}
void MOZ_FORMAT_PRINTF(2, 3)
LoggingHelper(bool aUseProfiler, const char* aFmt, ...) {
MOZ_ASSERT(IndexedDatabaseManager::GetLoggingMode() !=
IndexedDatabaseManager::Logging_Disabled);
MOZ_ASSERT(aFmt);
mozilla::LogModule* logModule = IndexedDatabaseManager::GetLoggingModule();
MOZ_ASSERT(logModule);
static const mozilla::LogLevel logLevel = LogLevel::Warning;
if (MOZ_LOG_TEST(logModule, logLevel) ||
#ifdef MOZ_GECKO_PROFILER
(aUseProfiler && profiler_thread_is_being_profiled())
#else
false
#endif
) {
nsAutoCString message;
{
va_list args;
va_start(args, aFmt);
message.AppendPrintf(aFmt, args);
va_end(args);
}
MOZ_LOG(logModule, logLevel, ("%s", message.get()));
if (aUseProfiler) {
PROFILER_ADD_MARKER(message.get(), DOM);
}
}
}
} // namespace indexedDB
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -10,277 +10,52 @@
// This file is not exported and is only meant to be included in IndexedDB // This file is not exported and is only meant to be included in IndexedDB
// source files. // source files.
#include "BackgroundChildImpl.h"
#include "GeckoProfiler.h"
#include "IDBCursorType.h"
#include "IDBDatabase.h"
#include "IDBIndex.h"
#include "IDBKeyRange.h"
#include "IDBObjectStore.h"
#include "IDBTransaction.h"
#include "IndexedDatabaseManager.h" #include "IndexedDatabaseManager.h"
#include "Key.h"
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/Event.h" #include "mozilla/dom/IDBCursorBinding.h"
#include "nsDebug.h"
#include "nsID.h" #include "nsID.h"
#include "nsString.h" #include "nsString.h"
#include "mozilla/Logging.h"
// Include this last to avoid path problems on Windows.
#include "ActorsChild.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class Event;
class IDBDatabase;
class IDBIndex;
class IDBKeyRange;
class IDBObjectStore;
class IDBTransaction;
namespace indexedDB { namespace indexedDB {
class Key;
class MOZ_STACK_CLASS LoggingIdString final class MOZ_STACK_CLASS LoggingIdString final
: public nsAutoCStringN<NSID_LENGTH> { : public nsAutoCStringN<NSID_LENGTH> {
public: public:
LoggingIdString() { LoggingIdString();
using mozilla::ipc::BackgroundChildImpl;
if (IndexedDatabaseManager::GetLoggingMode() != explicit LoggingIdString(const nsID& aID);
IndexedDatabaseManager::Logging_Disabled) {
const BackgroundChildImpl::ThreadLocal* threadLocal =
BackgroundChildImpl::GetThreadLocalForCurrentThread();
if (threadLocal) {
const auto& idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
if (idbThreadLocal) {
Assign(idbThreadLocal->IdString());
}
}
}
}
explicit LoggingIdString(const nsID& aID) {
static_assert(NSID_LENGTH > 1, "NSID_LENGTH is set incorrectly!");
static_assert(NSID_LENGTH <= kStorageSize,
"nsID string won't fit in our storage!");
// Capacity() excludes the null terminator; NSID_LENGTH includes it.
MOZ_ASSERT(Capacity() + 1 == NSID_LENGTH);
if (IndexedDatabaseManager::GetLoggingMode() !=
IndexedDatabaseManager::Logging_Disabled) {
// NSID_LENGTH counts the null terminator, SetLength() does not.
SetLength(NSID_LENGTH - 1);
aID.ToProvidedString(
*reinterpret_cast<char(*)[NSID_LENGTH]>(BeginWriting()));
}
}
}; };
class MOZ_STACK_CLASS LoggingString final : public nsAutoCString { class MOZ_STACK_CLASS LoggingString final : public nsAutoCString {
static const char kQuote = '\"';
static const char kOpenBracket = '[';
static const char kCloseBracket = ']';
static const char kOpenParen = '(';
static const char kCloseParen = ')';
public: public:
explicit LoggingString(IDBDatabase* aDatabase) : nsAutoCString(kQuote) { explicit LoggingString(IDBDatabase* aDatabase);
MOZ_ASSERT(aDatabase); explicit LoggingString(const IDBTransaction& aTransaction);
explicit LoggingString(IDBObjectStore* aObjectStore);
explicit LoggingString(IDBIndex* aIndex);
explicit LoggingString(IDBKeyRange* aKeyRange);
explicit LoggingString(const Key& aKey);
explicit LoggingString(const IDBCursorDirection aDirection);
explicit LoggingString(const Optional<uint64_t>& aVersion);
explicit LoggingString(const Optional<uint32_t>& aLimit);
AppendUTF16toUTF8(aDatabase->Name(), *this); LoggingString(IDBObjectStore* aObjectStore, const Key& aKey);
Append(kQuote); LoggingString(Event* aEvent, const char16_t* aDefault);
}
explicit LoggingString(const IDBTransaction& aTransaction)
: nsAutoCString(kOpenBracket) {
constexpr auto kCommaSpace = ", "_ns;
const nsTArray<nsString>& stores = aTransaction.ObjectStoreNamesInternal();
for (uint32_t count = stores.Length(), index = 0; index < count; index++) {
Append(kQuote);
AppendUTF16toUTF8(stores[index], *this);
Append(kQuote);
if (index != count - 1) {
Append(kCommaSpace);
}
}
Append(kCloseBracket);
Append(kCommaSpace);
switch (aTransaction.GetMode()) {
case IDBTransaction::Mode::ReadOnly:
AppendLiteral("\"readonly\"");
break;
case IDBTransaction::Mode::ReadWrite:
AppendLiteral("\"readwrite\"");
break;
case IDBTransaction::Mode::ReadWriteFlush:
AppendLiteral("\"readwriteflush\"");
break;
case IDBTransaction::Mode::Cleanup:
AppendLiteral("\"cleanup\"");
break;
case IDBTransaction::Mode::VersionChange:
AppendLiteral("\"versionchange\"");
break;
default:
MOZ_CRASH("Unknown mode!");
};
}
explicit LoggingString(IDBObjectStore* aObjectStore) : nsAutoCString(kQuote) {
MOZ_ASSERT(aObjectStore);
AppendUTF16toUTF8(aObjectStore->Name(), *this);
Append(kQuote);
}
explicit LoggingString(IDBIndex* aIndex) : nsAutoCString(kQuote) {
MOZ_ASSERT(aIndex);
AppendUTF16toUTF8(aIndex->Name(), *this);
Append(kQuote);
}
explicit LoggingString(IDBKeyRange* aKeyRange) {
if (aKeyRange) {
if (aKeyRange->IsOnly()) {
Assign(LoggingString(aKeyRange->Lower()));
} else {
if (aKeyRange->LowerOpen()) {
Assign(kOpenParen);
} else {
Assign(kOpenBracket);
}
Append(LoggingString(aKeyRange->Lower()));
AppendLiteral(", ");
Append(LoggingString(aKeyRange->Upper()));
if (aKeyRange->UpperOpen()) {
Append(kCloseParen);
} else {
Append(kCloseBracket);
}
}
} else {
AssignLiteral("<undefined>");
}
}
explicit LoggingString(const Key& aKey) {
if (aKey.IsUnset()) {
AssignLiteral("<undefined>");
} else if (aKey.IsFloat()) {
AppendPrintf("%g", aKey.ToFloat());
} else if (aKey.IsDate()) {
AppendPrintf("<Date %g>", aKey.ToDateMsec());
} else if (aKey.IsString()) {
AppendPrintf("\"%s\"", NS_ConvertUTF16toUTF8(aKey.ToString()).get());
} else if (aKey.IsBinary()) {
AssignLiteral("[object ArrayBuffer]");
} else {
MOZ_ASSERT(aKey.IsArray());
AssignLiteral("[...]");
}
}
explicit LoggingString(const IDBCursorDirection aDirection) {
switch (aDirection) {
case IDBCursorDirection::Next:
AssignLiteral("\"next\"");
break;
case IDBCursorDirection::Nextunique:
AssignLiteral("\"nextunique\"");
break;
case IDBCursorDirection::Prev:
AssignLiteral("\"prev\"");
break;
case IDBCursorDirection::Prevunique:
AssignLiteral("\"prevunique\"");
break;
default:
MOZ_CRASH("Unknown direction!");
};
}
explicit LoggingString(const Optional<uint64_t>& aVersion) {
if (aVersion.WasPassed()) {
AppendInt(aVersion.Value());
} else {
AssignLiteral("<undefined>");
}
}
explicit LoggingString(const Optional<uint32_t>& aLimit) {
if (aLimit.WasPassed()) {
AppendInt(aLimit.Value());
} else {
AssignLiteral("<undefined>");
}
}
LoggingString(IDBObjectStore* aObjectStore, const Key& aKey) {
MOZ_ASSERT(aObjectStore);
if (!aObjectStore->HasValidKeyPath()) {
Append(LoggingString(aKey));
}
}
LoggingString(Event* aEvent, const char16_t* aDefault)
: nsAutoCString(kQuote) {
MOZ_ASSERT(aDefault);
nsAutoString eventType;
if (aEvent) {
aEvent->GetType(eventType);
} else {
eventType = nsDependentString(aDefault);
}
AppendUTF16toUTF8(eventType, *this);
Append(kQuote);
}
}; };
inline void MOZ_FORMAT_PRINTF(2, 3) void MOZ_FORMAT_PRINTF(2, 3)
LoggingHelper(bool aUseProfiler, const char* aFmt, ...) { LoggingHelper(bool aUseProfiler, const char* aFmt, ...);
MOZ_ASSERT(IndexedDatabaseManager::GetLoggingMode() !=
IndexedDatabaseManager::Logging_Disabled);
MOZ_ASSERT(aFmt);
mozilla::LogModule* logModule = IndexedDatabaseManager::GetLoggingModule();
MOZ_ASSERT(logModule);
static const mozilla::LogLevel logLevel = LogLevel::Warning;
if (MOZ_LOG_TEST(logModule, logLevel) ||
#ifdef MOZ_GECKO_PROFILER
(aUseProfiler && profiler_thread_is_being_profiled())
#else
false
#endif
) {
nsAutoCString message;
{
va_list args;
va_start(args, aFmt);
message.AppendPrintf(aFmt, args);
va_end(args);
}
MOZ_LOG(logModule, logLevel, ("%s", message.get()));
if (aUseProfiler) {
PROFILER_ADD_MARKER(message.get(), DOM);
}
}
}
} // namespace indexedDB } // namespace indexedDB
} // namespace dom } // namespace dom

Просмотреть файл

@ -74,6 +74,7 @@ UNIFIED_SOURCES += [
'IndexedDatabaseManager.cpp', 'IndexedDatabaseManager.cpp',
'KeyPath.cpp', 'KeyPath.cpp',
'PermissionRequestBase.cpp', 'PermissionRequestBase.cpp',
'ProfilerHelpers.cpp',
'ReportInternalError.cpp', 'ReportInternalError.cpp',
'ScriptErrorHelper.cpp', 'ScriptErrorHelper.cpp',
] ]