mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 20:55:39 +00:00
d5e552f528
clang's -Wmissing-prototypes option identifies global functions that can be made static (because they're only called from one compilation unit) or removed (if they're never called). xpcom/base/Logging.cpp:85:13 [-Wmissing-prototypes] no previous prototype for function 'ToLogStr' xpcom/base/Logging.cpp:132:13 [-Wmissing-prototypes] no previous prototype for function 'ExpandPIDMarker' xpcom/base/LogModulePrefWatcher.cpp:37:6 [-Wmissing-prototypes] no previous prototype for function 'ResetExistingPrefs' xpcom/base/LogModulePrefWatcher.cpp:109:6 [-Wmissing-prototypes] no previous prototype for function 'LoadExistingPrefs' xpcom/base/nsCycleCollector.cpp:212:6 [-Wmissing-prototypes] no previous prototype for function 'SuspectUsingNurseryPurpleBuffer' xpcom/components/nsComponentManager.cpp:421:31 [-Wmissing-prototypes] no previous prototype for function 'begin' xpcom/components/nsComponentManager.cpp:427:31 [-Wmissing-prototypes] no previous prototype for function 'end' xpcom/ds/Dafsa.cpp:23:6 [-Wmissing-prototypes] no previous prototype for function 'GetNextOffset' xpcom/ds/Dafsa.cpp:55:6 [-Wmissing-prototypes] no previous prototype for function 'IsEOL' xpcom/ds/Dafsa.cpp:62:6 [-Wmissing-prototypes] no previous prototype for function 'IsMatch' xpcom/ds/Dafsa.cpp:70:6 [-Wmissing-prototypes] no previous prototype for function 'IsEndCharMatch' xpcom/ds/Dafsa.cpp:78:6 [-Wmissing-prototypes] no previous prototype for function 'GetReturnValue' xpcom/ds/Dafsa.cpp:91:5 [-Wmissing-prototypes] no previous prototype for function 'LookupString' xpcom/io/CocoaFileUtils.mm:195:13 [-Wmissing-prototypes] no previous prototype for function 'GetQuarantinePropKey' xpcom/io/CocoaFileUtils.mm:203:24 [-Wmissing-prototypes] no previous prototype for function 'CreateQuarantineDictionary' xpcom/rust/gtest/bench-collections/Bench.cpp:65:11 [-Wmissing-prototypes] no previous prototype for function 'MyRand' xpcom/rust/gtest/bench-collections/Bench.cpp:85:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_unordered_set' xpcom/rust/gtest/bench-collections/Bench.cpp:125:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_PLDHashTable' xpcom/rust/gtest/bench-collections/Bench.cpp:166:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_MozHashSet' xpcom/tests/gtest/TestAtoms.cpp:114:6 [-Wmissing-prototypes] no previous prototype for function 'isStaticAtom' xpcom/tests/gtest/TestCallTemplates.cpp:72:6 [-Wmissing-prototypes] no previous prototype for function 'JustTestingCompilation' xpcom/tests/gtest/TestCOMPtr.cpp:87:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIFoo' xpcom/tests/gtest/TestCOMPtr.cpp:98:6 [-Wmissing-prototypes] no previous prototype for function 'set_a_IFoo' xpcom/tests/gtest/TestCOMPtr.cpp:105:16 [-Wmissing-prototypes] no previous prototype for function 'return_a_IFoo' xpcom/tests/gtest/TestCOMPtr.cpp:164:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIBar' xpcom/tests/gtest/TestCOMPtr.cpp:175:6 [-Wmissing-prototypes] no previous prototype for function 'AnIFooPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:177:6 [-Wmissing-prototypes] no previous prototype for function 'AVoidPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:179:6 [-Wmissing-prototypes] no previous prototype for function 'AnISupportsPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:263:6 [-Wmissing-prototypes] no previous prototype for function 'Comparison' xpcom/tests/gtest/TestCOMPtr.cpp:298:6 [-Wmissing-prototypes] no previous prototype for function 'DontAddRef' xpcom/tests/gtest/TestCRT.cpp:17:5 [-Wmissing-prototypes] no previous prototype for function 'sign' xpcom/tests/gtest/TestDeadlockDetector.cpp:62:6 [-Wmissing-prototypes] no previous prototype for function 'DisableCrashReporter' xpcom/tests/gtest/TestDeadlockDetector.cpp:74:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:95:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity2_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:159:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity4_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:182:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity5_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:303:5 [-Wmissing-prototypes] no previous prototype for function 'ContentionNoDeadlock_Child' xpcom/tests/gtest/TestHashtables.cpp:88:6 [-Wmissing-prototypes] no previous prototype for function 'testTHashtable' xpcom/tests/gtest/TestHashtables.cpp:205:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIFoo' xpcom/tests/gtest/TestMoveString.cpp:25:6 [-Wmissing-prototypes] no previous prototype for function 'SetAsOwned' xpcom/tests/gtest/TestMoveString.cpp:34:6 [-Wmissing-prototypes] no previous prototype for function 'ExpectTruncated' xpcom/tests/gtest/TestMoveString.cpp:40:6 [-Wmissing-prototypes] no previous prototype for function 'ExpectNew' xpcom/tests/gtest/TestMruCache.cpp:52:11 [-Wmissing-prototypes] no previous prototype for function 'MakeStringKey' xpcom/tests/gtest/TestMultiplexInputStream.cpp:106:34 [-Wmissing-prototypes] no previous prototype for function 'CreateStreamHelper' xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp:62:10 [-Wmissing-prototypes] no previous prototype for function 'ReadSegmentsFunction' xpcom/tests/gtest/TestNsDeque.cpp:240:6 [-Wmissing-prototypes] no previous prototype for function 'CheckIfQueueEmpty' xpcom/tests/gtest/TestNsRefPtr.cpp:105:10 [-Wmissing-prototypes] no previous prototype for function 'CreateFoo' xpcom/tests/gtest/TestNsRefPtr.cpp:116:6 [-Wmissing-prototypes] no previous prototype for function 'set_a_Foo' xpcom/tests/gtest/TestNsRefPtr.cpp:123:13 [-Wmissing-prototypes] no previous prototype for function 'return_a_Foo' xpcom/tests/gtest/TestNsRefPtr.cpp:391:6 [-Wmissing-prototypes] no previous prototype for function 'AnFooPtrPtrContext' xpcom/tests/gtest/TestNsRefPtr.cpp:392:6 [-Wmissing-prototypes] no previous prototype for function 'AVoidPtrPtrContext' xpcom/tests/gtest/TestPLDHash.cpp:33:6 [-Wmissing-prototypes] no previous prototype for function 'TestCrashyOperation' xpcom/tests/gtest/TestPipes.cpp:98:10 [-Wmissing-prototypes] no previous prototype for function 'TestPipe' xpcom/tests/gtest/TestPipes.cpp:212:10 [-Wmissing-prototypes] no previous prototype for function 'TestShortWrites' xpcom/tests/gtest/TestPipes.cpp:354:6 [-Wmissing-prototypes] no previous prototype for function 'RunTests' xpcom/tests/gtest/TestPLDHash.cpp:90:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_InitialLengthTooBig' xpcom/tests/gtest/TestPLDHash.cpp:95:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_InitialEntryStoreTooBig' xpcom/tests/gtest/TestPLDHash.cpp:102:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_EntrySizeTooBig' xpcom/tests/gtest/TestSlicedInputStream.cpp:111:20 [-Wmissing-prototypes] no previous prototype for function 'CreateSeekableStreams' xpcom/tests/gtest/TestSlicedInputStream.cpp:125:20 [-Wmissing-prototypes] no previous prototype for function 'CreateNonSeekableStreams' xpcom/tests/gtest/TestStrings.cpp:471:6 [-Wmissing-prototypes] no previous prototype for function 'test_assign_helper' xpcom/tests/gtest/TestTArray.cpp:60:22 [-Wmissing-prototypes] no previous prototype for function 'DummyArray' xpcom/tests/gtest/TestTArray.cpp:72:22 [-Wmissing-prototypes] no previous prototype for function 'FakeHugeArray' xpcom/tests/gtest/TestThrottledEventQueue.cpp:96:6 [-Wmissing-prototypes] no previous prototype for function 'Enqueue' xpcom/threads/BlockingResourceBase.cpp:86:6 [-Wmissing-prototypes] no previous prototype for function 'PrintCycle' xpcom/threads/CPUUsageWatcher.cpp:41:10 [-Wmissing-prototypes] no previous prototype for function 'GetMicroseconds' xpcom/threads/CPUUsageWatcher.cpp:46:10 [-Wmissing-prototypes] no previous prototype for function 'GetMicroseconds' xpcom/threads/CPUUsageWatcher.cpp:51:40 [-Wmissing-prototypes] no previous prototype for function 'GetProcessCPUStats' xpcom/threads/CPUUsageWatcher.cpp:80:40 [-Wmissing-prototypes] no previous prototype for function 'GetGlobalCPUStats' xpcom/threads/nsTimerImpl.cpp:196:21 [-Wmissing-prototypes] no previous prototype for function 'GetTimerFiringsLog' Differential Revision: https://phabricator.services.mozilla.com/D23264 --HG-- extra : rebase_source : e03df033209e0a08fc263603e78bc16a09467f15 extra : source : 3beec9fbfdedf346fff85309029e7805717958ac
164 lines
5.5 KiB
C++
164 lines
5.5 KiB
C++
/* -*- 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 "LogModulePrefWatcher.h"
|
|
|
|
#include "mozilla/Logging.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "nsMemory.h"
|
|
#include "nsString.h"
|
|
#include "nsXULAppAPI.h"
|
|
#include "base/process_util.h"
|
|
|
|
static const char kLoggingPrefPrefix[] = "logging.";
|
|
static const char kLoggingConfigPrefPrefix[] = "logging.config";
|
|
static const int kLoggingConfigPrefixLen = sizeof(kLoggingConfigPrefPrefix) - 1;
|
|
static const char kLoggingPrefClearOnStartup[] =
|
|
"logging.config.clear_on_startup";
|
|
static const char kLoggingPrefLogFile[] = "logging.config.LOG_FILE";
|
|
static const char kLoggingPrefAddTimestamp[] = "logging.config.add_timestamp";
|
|
static const char kLoggingPrefSync[] = "logging.config.sync";
|
|
|
|
namespace mozilla {
|
|
|
|
NS_IMPL_ISUPPORTS(LogModulePrefWatcher, nsIObserver)
|
|
|
|
/**
|
|
* Resets all the preferences in the logging. branch
|
|
* This is needed because we may crash while logging, and this would cause us
|
|
* to log after restarting as well.
|
|
*
|
|
* If logging after restart is desired, set the logging.config.clear_on_startup
|
|
* pref to false, or use the MOZ_LOG_FILE and MOZ_LOG_MODULES env vars.
|
|
*/
|
|
static void ResetExistingPrefs() {
|
|
uint32_t count;
|
|
char** names;
|
|
nsresult rv = Preferences::GetRootBranch()->GetChildList(kLoggingPrefPrefix,
|
|
&count, &names);
|
|
if (NS_SUCCEEDED(rv) && count) {
|
|
for (size_t i = 0; i < count; i++) {
|
|
// Clearing the pref will cause it to reload, thus resetting the log level
|
|
Preferences::ClearUser(names[i]);
|
|
}
|
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, names);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Loads the log level from the given pref and updates the corresponding
|
|
* LogModule.
|
|
*/
|
|
static void LoadPrefValue(const char* aName) {
|
|
LogLevel logLevel = LogLevel::Disabled;
|
|
|
|
nsresult rv;
|
|
int32_t prefLevel = 0;
|
|
nsAutoCString prefValue;
|
|
|
|
if (strncmp(aName, kLoggingConfigPrefPrefix, kLoggingConfigPrefixLen) == 0) {
|
|
nsAutoCString prefName(aName);
|
|
|
|
if (prefName.EqualsLiteral(kLoggingPrefLogFile)) {
|
|
rv = Preferences::GetCString(aName, prefValue);
|
|
// The pref was reset. Clear the user file.
|
|
if (NS_FAILED(rv) || prefValue.IsEmpty()) {
|
|
LogModule::SetLogFile(nullptr);
|
|
return;
|
|
}
|
|
|
|
// If the pref value doesn't have a PID placeholder, append it to the end.
|
|
if (!strstr(prefValue.get(), "%PID")) {
|
|
prefValue.AppendLiteral("%PID");
|
|
}
|
|
|
|
LogModule::SetLogFile(prefValue.BeginReading());
|
|
} else if (prefName.EqualsLiteral(kLoggingPrefAddTimestamp)) {
|
|
bool addTimestamp = Preferences::GetBool(aName, false);
|
|
LogModule::SetAddTimestamp(addTimestamp);
|
|
} else if (prefName.EqualsLiteral(kLoggingPrefSync)) {
|
|
bool sync = Preferences::GetBool(aName, false);
|
|
LogModule::SetIsSync(sync);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Preferences::GetInt(aName, &prefLevel) == NS_OK) {
|
|
logLevel = ToLogLevel(prefLevel);
|
|
} else if (Preferences::GetCString(aName, prefValue) == NS_OK) {
|
|
if (prefValue.LowerCaseEqualsLiteral("error")) {
|
|
logLevel = LogLevel::Error;
|
|
} else if (prefValue.LowerCaseEqualsLiteral("warning")) {
|
|
logLevel = LogLevel::Warning;
|
|
} else if (prefValue.LowerCaseEqualsLiteral("info")) {
|
|
logLevel = LogLevel::Info;
|
|
} else if (prefValue.LowerCaseEqualsLiteral("debug")) {
|
|
logLevel = LogLevel::Debug;
|
|
} else if (prefValue.LowerCaseEqualsLiteral("verbose")) {
|
|
logLevel = LogLevel::Verbose;
|
|
}
|
|
}
|
|
|
|
const char* moduleName = aName + strlen(kLoggingPrefPrefix);
|
|
LogModule::Get(moduleName)->SetLevel(logLevel);
|
|
}
|
|
|
|
static void LoadExistingPrefs() {
|
|
nsIPrefBranch* root = Preferences::GetRootBranch();
|
|
if (!root) {
|
|
return;
|
|
}
|
|
|
|
uint32_t count;
|
|
char** names;
|
|
nsresult rv = root->GetChildList(kLoggingPrefPrefix, &count, &names);
|
|
if (NS_SUCCEEDED(rv) && count) {
|
|
for (size_t i = 0; i < count; i++) {
|
|
LoadPrefValue(names[i]);
|
|
}
|
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, names);
|
|
}
|
|
}
|
|
|
|
LogModulePrefWatcher::LogModulePrefWatcher() {}
|
|
|
|
void LogModulePrefWatcher::RegisterPrefWatcher() {
|
|
RefPtr<LogModulePrefWatcher> prefWatcher = new LogModulePrefWatcher();
|
|
Preferences::AddStrongObserver(prefWatcher, kLoggingPrefPrefix);
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
mozilla::services::GetObserverService();
|
|
if (observerService && XRE_IsParentProcess()) {
|
|
observerService->AddObserver(prefWatcher,
|
|
"browser-delayed-startup-finished", false);
|
|
}
|
|
|
|
LoadExistingPrefs();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
LogModulePrefWatcher::Observe(nsISupports* aSubject, const char* aTopic,
|
|
const char16_t* aData) {
|
|
if (strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic) == 0) {
|
|
NS_LossyConvertUTF16toASCII prefName(aData);
|
|
LoadPrefValue(prefName.get());
|
|
} else if (strcmp("browser-delayed-startup-finished", aTopic) == 0) {
|
|
bool clear = Preferences::GetBool(kLoggingPrefClearOnStartup, true);
|
|
if (clear) {
|
|
ResetExistingPrefs();
|
|
}
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
mozilla::services::GetObserverService();
|
|
if (observerService) {
|
|
observerService->RemoveObserver(this, "browser-delayed-startup-finished");
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
} // namespace mozilla
|