Bug 767275 - Add more detailed cache lock telemetry, r=michal, r=nfroyd

--HG--
extra : rebase_source : 60962876704a945ba83dc8ccfde938aa1957cb96
This commit is contained in:
Brian Smith 2012-06-29 16:20:34 -07:00
parent 52928f6820
commit f9ebaf0336
8 changed files with 158 additions and 70 deletions

View File

@ -51,7 +51,7 @@ nsCacheEntryDescriptor::GetClientID(char ** result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETCLIENTID));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
return ClientIDFromCacheKey(*(mCacheEntry->Key()), result);
@ -62,7 +62,7 @@ NS_IMETHODIMP
nsCacheEntryDescriptor::GetDeviceID(char ** aDeviceID)
{
NS_ENSURE_ARG_POINTER(aDeviceID);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETDEVICEID));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
const char* deviceID = mCacheEntry->GetDeviceID();
@ -79,7 +79,7 @@ nsCacheEntryDescriptor::GetDeviceID(char ** aDeviceID)
NS_IMETHODIMP
nsCacheEntryDescriptor::GetKey(nsACString &result)
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETKEY));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
return ClientKeyFromCacheKey(*(mCacheEntry->Key()), result);
@ -90,7 +90,7 @@ NS_IMETHODIMP
nsCacheEntryDescriptor::GetFetchCount(PRInt32 *result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETFETCHCOUNT));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->FetchCount();
@ -102,7 +102,7 @@ NS_IMETHODIMP
nsCacheEntryDescriptor::GetLastFetched(PRUint32 *result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETLASTFETCHED));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->LastFetched();
@ -114,7 +114,7 @@ NS_IMETHODIMP
nsCacheEntryDescriptor::GetLastModified(PRUint32 *result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETLASTMODIFIED));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->LastModified();
@ -126,7 +126,7 @@ NS_IMETHODIMP
nsCacheEntryDescriptor::GetExpirationTime(PRUint32 *result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETEXPIRATIONTIME));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->ExpirationTime();
@ -137,7 +137,7 @@ nsCacheEntryDescriptor::GetExpirationTime(PRUint32 *result)
NS_IMETHODIMP
nsCacheEntryDescriptor::SetExpirationTime(PRUint32 expirationTime)
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETEXPIRATIONTIME));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
mCacheEntry->SetExpirationTime(expirationTime);
@ -149,7 +149,7 @@ nsCacheEntryDescriptor::SetExpirationTime(PRUint32 expirationTime)
NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(bool *result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_ISSTREAMBASED));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->IsStreamData();
@ -159,7 +159,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(bool *result)
NS_IMETHODIMP nsCacheEntryDescriptor::GetPredictedDataSize(PRInt64 *result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETPREDICTEDDATASIZE));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->PredictedDataSize();
@ -169,7 +169,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetPredictedDataSize(PRInt64 *result)
NS_IMETHODIMP nsCacheEntryDescriptor::SetPredictedDataSize(PRInt64
predictedSize)
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETPREDICTEDDATASIZE));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
mCacheEntry->SetPredictedDataSize(predictedSize);
@ -179,7 +179,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::SetPredictedDataSize(PRInt64
NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(PRUint32 *result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETDATASIZE));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
const char* val = mCacheEntry->GetMetaDataElement("uncompressed-len");
@ -196,7 +196,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(PRUint32 *result)
NS_IMETHODIMP nsCacheEntryDescriptor::GetStorageDataSize(PRUint32 *result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETSTORAGEDATASIZE));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->DataSize();
@ -208,7 +208,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetStorageDataSize(PRUint32 *result)
nsresult
nsCacheEntryDescriptor::RequestDataSizeChange(PRInt32 deltaSize)
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_REQUESTDATASIZECHANGE));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
nsresult rv;
@ -226,7 +226,7 @@ nsCacheEntryDescriptor::RequestDataSizeChange(PRInt32 deltaSize)
NS_IMETHODIMP
nsCacheEntryDescriptor::SetDataSize(PRUint32 dataSize)
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETDATASIZE));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
// XXX review for signed/unsigned math errors
@ -254,7 +254,7 @@ nsCacheEntryDescriptor::OpenInputStream(PRUint32 offset, nsIInputStream ** resul
NS_ENSURE_ARG_POINTER(result);
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_OPENINPUTSTREAM));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
if (!mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_NOT_STREAM;
@ -283,7 +283,7 @@ nsCacheEntryDescriptor::OpenOutputStream(PRUint32 offset, nsIOutputStream ** res
NS_ENSURE_ARG_POINTER(result);
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_OPENOUTPUTSTREAM));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
if (!mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_NOT_STREAM;
@ -316,7 +316,7 @@ NS_IMETHODIMP
nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETCACHEELEMENT));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM;
@ -328,7 +328,7 @@ nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result)
NS_IMETHODIMP
nsCacheEntryDescriptor::SetCacheElement(nsISupports * cacheElement)
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETCACHEELEMENT));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM;
@ -349,7 +349,7 @@ NS_IMETHODIMP
nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETSTORAGEPOLICY));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->StoragePolicy();
@ -360,7 +360,7 @@ nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result)
NS_IMETHODIMP
nsCacheEntryDescriptor::SetStoragePolicy(nsCacheStoragePolicy policy)
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETSTORAGEPOLICY));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
// XXX validate policy against session?
@ -387,7 +387,7 @@ NS_IMETHODIMP
nsCacheEntryDescriptor::GetFile(nsIFile ** result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETFILE));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
return nsCacheService::GetFileForEntry(mCacheEntry, result);
@ -398,7 +398,7 @@ NS_IMETHODIMP
nsCacheEntryDescriptor::GetSecurityInfo(nsISupports ** result)
{
NS_ENSURE_ARG_POINTER(result);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETSECURITYINFO));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = mCacheEntry->SecurityInfo();
@ -410,7 +410,7 @@ nsCacheEntryDescriptor::GetSecurityInfo(nsISupports ** result)
NS_IMETHODIMP
nsCacheEntryDescriptor::SetSecurityInfo(nsISupports * securityInfo)
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETSECURITYINFO));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
mCacheEntry->SetSecurityInfo(securityInfo);
@ -422,7 +422,7 @@ nsCacheEntryDescriptor::SetSecurityInfo(nsISupports * securityInfo)
NS_IMETHODIMP
nsCacheEntryDescriptor::Doom()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_DOOM));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
return nsCacheService::DoomEntry(mCacheEntry);
@ -432,7 +432,7 @@ nsCacheEntryDescriptor::Doom()
NS_IMETHODIMP
nsCacheEntryDescriptor::DoomAndFailPendingRequests(nsresult status)
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_DOOMANDFAILPENDINGREQUESTS));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_NOT_IMPLEMENTED;
@ -442,7 +442,7 @@ nsCacheEntryDescriptor::DoomAndFailPendingRequests(nsresult status)
NS_IMETHODIMP
nsCacheEntryDescriptor::MarkValid()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_MARKVALID));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
nsresult rv = nsCacheService::ValidateEntry(mCacheEntry);
@ -453,7 +453,7 @@ nsCacheEntryDescriptor::MarkValid()
NS_IMETHODIMP
nsCacheEntryDescriptor::Close()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_CLOSE));
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
// XXX perhaps closing descriptors should clear/sever transports
@ -472,7 +472,7 @@ nsCacheEntryDescriptor::GetMetaDataElement(const char *key, char **result)
NS_ENSURE_ARG_POINTER(key);
*result = nsnull;
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETMETADATAELEMENT));
NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_NOT_AVAILABLE);
const char *value;
@ -492,7 +492,7 @@ nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value)
{
NS_ENSURE_ARG_POINTER(key);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETMETADATAELEMENT));
NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_NOT_AVAILABLE);
// XXX allow null value, for clearing key?
@ -507,7 +507,8 @@ nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value)
NS_IMETHODIMP
nsCacheEntryDescriptor::VisitMetaData(nsICacheMetaDataVisitor * visitor)
{
nsCacheServiceAutoLock lock; // XXX check callers, we're calling out of module
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_VISITMETADATA));
// XXX check callers, we're calling out of module
NS_ENSURE_ARG_POINTER(visitor);
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
@ -526,7 +527,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheEntryDescriptor::nsInputStreamWrapper,
nsresult nsCacheEntryDescriptor::
nsInputStreamWrapper::LazyInit()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSINPUTSTREAMWRAPPER_LAZYINIT));
nsCacheAccessMode mode;
nsresult rv = mDescriptor->GetAccessGranted(&mode);
@ -739,7 +740,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheEntryDescriptor::nsOutputStreamWrapper,
nsresult nsCacheEntryDescriptor::
nsOutputStreamWrapper::LazyInit()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSOUTPUTSTREAMWRAPPER_LAZYINIT));
nsCacheAccessMode mode;
nsresult rv = mDescriptor->GetAccessGranted(&mode);

View File

@ -157,7 +157,7 @@ private:
// XXX _HACK_ the storage stream needs this!
Close();
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSOUTPUTSTREAMWRAPPER_CLOSE));
mDescriptor->mOutput = nsnull;
}
NS_RELEASE(mDescriptor);

View File

@ -35,7 +35,6 @@
#include "nsNetCID.h"
#include <math.h> // for log()
#include "mozilla/Services.h"
#include "mozilla/Telemetry.h"
#include "nsITimer.h"
#include "mozilla/FunctionTimer.h"
@ -191,7 +190,7 @@ public:
NS_IMETHOD Notify(nsITimer* aTimer) {
if (nsCacheService::gService) {
nsCacheServiceAutoLock autoLock;
nsCacheServiceAutoLock autoLock(LOCK_TELEM(NSSETDISKSMARTSIZECALLBACK_NOTIFY));
nsCacheService::gService->SetDiskSmartSize_Locked();
nsCacheService::gService->mSmartSizeTimer = nsnull;
}
@ -271,7 +270,7 @@ public:
}
NS_IMETHOD Run()
{
nsCacheServiceAutoLock autoLock;
nsCacheServiceAutoLock autoLock(LOCK_TELEM(NSBLOCKONCACHETHREADEVENT_RUN));
#ifdef PR_LOGGING
CACHE_LOG_DEBUG(("nsBlockOnCacheThreadEvent [%p]\n", this));
#endif
@ -944,7 +943,7 @@ public:
NS_ASSERTION(mRequest->mListener,
"Sync OpenCacheEntry() posted to background thread!");
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSPROCESSREQUESTEVENT_RUN));
rv = nsCacheService::gService->ProcessRequest(mRequest,
false,
nsnull);
@ -1013,7 +1012,7 @@ public:
NS_IMETHOD Run()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSDOOMEVENT_RUN));
bool foundActive = true;
nsresult status = NS_ERROR_NOT_AVAILABLE;
@ -1178,7 +1177,7 @@ nsCacheService::Shutdown()
nsCOMPtr<nsIFile> parentDir;
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SHUTDOWN));
NS_ASSERTION(mInitialized,
"can't shutdown nsCacheService unless it has been initialized.");
@ -1337,7 +1336,7 @@ nsCacheService::EvictEntriesForClient(const char * clientID,
nsRefPtr<EvictionNotifierRunnable> r = new EvictionNotifierRunnable(this);
NS_DispatchToMainThread(r);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_EVICTENTRIESFORCLIENT));
nsresult res = NS_OK;
if (storagePolicy == nsICache::STORE_ANYWHERE ||
@ -1386,7 +1385,7 @@ nsCacheService::IsStorageEnabledForPolicy(nsCacheStoragePolicy storagePolicy,
bool * result)
{
if (gService == nsnull) return NS_ERROR_NOT_AVAILABLE;
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ISSTORAGEENABLEDFORPOLICY));
*result = gService->IsStorageEnabledForPolicy_Locked(storagePolicy);
return NS_OK;
@ -1435,7 +1434,7 @@ NS_IMETHODIMP nsCacheService::VisitEntries(nsICacheVisitor *visitor)
{
NS_ENSURE_ARG_POINTER(visitor);
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_VISITENTRIES));
if (!(mEnableDiskDevice || mEnableMemoryDevice))
return NS_ERROR_NOT_AVAILABLE;
@ -1488,7 +1487,7 @@ NS_IMETHODIMP nsCacheService::GetCacheIOTarget(nsIEventTarget * *aCacheIOTarget)
// read from the main thread without the lock. This is useful to prevent
// blocking the main thread on other cache operations.
if (!NS_IsMainThread()) {
Lock();
Lock(LOCK_TELEM(NSCACHESERVICE_GETCACHEIOTARGET));
}
nsresult rv;
@ -1803,7 +1802,7 @@ nsCacheService::ProcessRequest(nsCacheRequest * request,
// XXX this is probably wrong...
Unlock();
rv = request->WaitForValidation();
Lock();
Lock(LOCK_TELEM(NSCACHESERVICE_PROCESSREQUEST));
}
PR_REMOVE_AND_INIT_LINK(request);
@ -1916,7 +1915,7 @@ nsCacheService::OpenCacheEntry(nsCacheSession * session,
}
else {
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_OPENCACHEENTRY));
rv = gService->ProcessRequest(request, true, result);
// delete requests that have completed
@ -2225,7 +2224,7 @@ nsCacheService::OnProfileShutdown(bool cleanse)
// a reference to it. Ignore this call.
return;
}
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILESHUTDOWN));
gService->mClearingEntries = true;
gService->DoomActiveEntries(nsnull);
@ -2270,7 +2269,7 @@ nsCacheService::OnProfileChanged()
CACHE_LOG_DEBUG(("nsCacheService::OnProfileChanged"));
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILECHANGED));
gService->mEnableDiskDevice = gService->mObserver->DiskCacheEnabled();
gService->mEnableOfflineDevice = gService->mObserver->OfflineCacheEnabled();
@ -2324,7 +2323,7 @@ void
nsCacheService::SetDiskCacheEnabled(bool enabled)
{
if (!gService) return;
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHEENABLED));
gService->mEnableDiskDevice = enabled;
}
@ -2333,7 +2332,7 @@ void
nsCacheService::SetDiskCacheCapacity(PRInt32 capacity)
{
if (!gService) return;
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHECAPACITY));
if (gService->mDiskDevice) {
gService->mDiskDevice->SetCapacity(capacity);
@ -2347,7 +2346,7 @@ void
nsCacheService::SetDiskCacheMaxEntrySize(PRInt32 maxSize)
{
if (!gService) return;
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHEMAXENTRYSIZE));
if (gService->mDiskDevice) {
gService->mDiskDevice->SetMaxEntrySize(maxSize);
@ -2358,7 +2357,7 @@ void
nsCacheService::SetMemoryCacheMaxEntrySize(PRInt32 maxSize)
{
if (!gService) return;
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETMEMORYCACHEMAXENTRYSIZE));
if (gService->mMemoryDevice) {
gService->mMemoryDevice->SetMaxEntrySize(maxSize);
@ -2369,7 +2368,7 @@ void
nsCacheService::SetOfflineCacheEnabled(bool enabled)
{
if (!gService) return;
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETOFFLINECACHEENABLED));
gService->mEnableOfflineDevice = enabled;
}
@ -2377,7 +2376,7 @@ void
nsCacheService::SetOfflineCacheCapacity(PRInt32 capacity)
{
if (!gService) return;
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETOFFLINECACHECAPACITY));
if (gService->mOfflineDevice) {
gService->mOfflineDevice->SetCapacity(capacity);
@ -2394,7 +2393,7 @@ nsCacheService::SetMemoryCache()
CACHE_LOG_DEBUG(("nsCacheService::SetMemoryCache"));
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETMEMORYCACHE));
gService->mEnableMemoryDevice = gService->mObserver->MemoryCacheEnabled();
@ -2484,15 +2483,32 @@ nsCacheService::OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize)
}
void
nsCacheService::Lock()
nsCacheService::Lock(mozilla::Telemetry::ID mainThreadLockerID)
{
mozilla::Telemetry::ID lockerID;
mozilla::Telemetry::ID generalID;
bool on;
if (NS_IsMainThread()) {
Telemetry::AutoTimer<Telemetry::CACHE_SERVICE_LOCK_WAIT_MAINTHREAD> timer;
gService->mLock.Lock();
lockerID = mainThreadLockerID;
generalID = mozilla::Telemetry::CACHE_SERVICE_LOCK_WAIT_MAINTHREAD;
} else {
Telemetry::AutoTimer<Telemetry::CACHE_SERVICE_LOCK_WAIT> timer;
gService->mLock.Lock();
lockerID = mozilla::Telemetry::HistogramCount;
generalID = mozilla::Telemetry::CACHE_SERVICE_LOCK_WAIT;
}
TimeStamp start(TimeStamp::Now());
gService->mLock.Lock();
TimeStamp stop(TimeStamp::Now());
// Telemetry isn't thread safe on its own, but this is OK because we're
// protecting it with the cache lock.
if (lockerID != mozilla::Telemetry::HistogramCount) {
mozilla::Telemetry::AccumulateTimeDelta(lockerID, start, stop);
}
mozilla::Telemetry::AccumulateTimeDelta(generalID, start, stop);
}
void
@ -2843,7 +2859,7 @@ nsCacheService::LogCacheStatistics()
nsresult
nsCacheService::SetDiskSmartSize()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKSMARTSIZE));
if (!gService) return NS_ERROR_NOT_AVAILABLE;
@ -2886,7 +2902,7 @@ IsEntryPrivate(nsCacheEntry* entry)
void
nsCacheService::LeavePrivateBrowsing()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_LEAVEPRIVATEBROWSING));
gService->DoomActiveEntries(IsEntryPrivate);

View File

@ -20,6 +20,7 @@
#include "nsRefPtrHashtable.h"
#include "mozilla/CondVar.h"
#include "mozilla/Mutex.h"
#include "mozilla/Telemetry.h"
class nsCacheRequest;
class nsCacheProfilePrefObserver;
@ -188,7 +189,7 @@ private:
* Internal Methods
*/
static void Lock();
static void Lock(::mozilla::Telemetry::ID mainThreadLockerID);
static void Unlock();
nsresult CreateDiskDevice();
@ -311,12 +312,15 @@ private:
* nsCacheServiceAutoLock
******************************************************************************/
#define LOCK_TELEM(x) \
(::mozilla::Telemetry::CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_##x)
// Instantiate this class to acquire the cache service lock for a particular
// execution scope.
class nsCacheServiceAutoLock {
public:
nsCacheServiceAutoLock() {
nsCacheService::Lock();
nsCacheServiceAutoLock(mozilla::Telemetry::ID mainThreadLockerID) {
nsCacheService::Lock(mainThreadLockerID);
}
~nsCacheServiceAutoLock() {
nsCacheService::Unlock();

View File

@ -87,7 +87,7 @@ nsDiskCacheBinding::~nsDiskCacheBinding()
// Grab the cache lock since the binding is stored in nsCacheEntry::mData
// and it is released using nsCacheService::ReleaseObject_Locked() which
// releases the object outside the cache lock.
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSDISKCACHEBINDING_DESTRUCTOR));
NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "binding deleted while still on list");
if (!PR_CLIST_IS_EMPTY(this))

View File

@ -65,7 +65,7 @@ public:
NS_IMETHOD Run()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSDISKCACHEDEVICEDEACTIVATEENTRYEVENT_RUN));
#ifdef PR_LOGGING
CACHE_LOG_DEBUG(("nsDiskCacheDeviceDeactivateEntryEvent[%p]\n", this));
#endif
@ -90,7 +90,7 @@ public:
NS_IMETHOD Run()
{
nsCacheServiceAutoLock lock;
nsCacheServiceAutoLock lock(LOCK_TELEM(NSEVICTDISKCACHEENTRIESEVENT_RUN));
mDevice->EvictDiskCacheEntries(mDevice->mCacheCapacity);
return NS_OK;
}

View File

@ -464,7 +464,7 @@ nsDiskCacheStreamIO::ClearBinding()
nsresult
nsDiskCacheStreamIO::CloseOutputStream(nsDiskCacheOutputStream * outputStream)
{
nsCacheServiceAutoLock lock; // grab service lock
nsCacheServiceAutoLock lock(LOCK_TELEM(NSDISKCACHESTREAMIO_CLOSEOUTPUTSTREAM)); // grab service lock
return CloseOutputStreamInternal(outputStream);
}
@ -596,7 +596,7 @@ nsDiskCacheStreamIO::Write( const char * buffer,
PRUint32 * bytesWritten)
{
nsresult rv = NS_OK;
nsCacheServiceAutoLock lock; // grab service lock
nsCacheServiceAutoLock lock(LOCK_TELEM(NSDISKCACHESTREAMIO_WRITE)); // grab service lock
if (!mBinding) return NS_ERROR_NOT_AVAILABLE;
if (mInStreamCount) {

View File

@ -209,6 +209,73 @@ HISTOGRAM(CACHE_LM_INCONSISTENT, 0, 1, 2, BOOLEAN, "Cache discovered inconsiste
HISTOGRAM(CACHE_SERVICE_LOCK_WAIT, 1, 10000, 10000, LINEAR, "Time spent waiting on the cache service lock (ms)")
HISTOGRAM(CACHE_SERVICE_LOCK_WAIT_MAINTHREAD, 1, 10000, 10000, LINEAR, "Time spent waiting on the cache service lock on the main thread (ms)")
#define CACHE_LOCK_HISTOGRAM(x) \
HISTOGRAM(CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_##x, 1, 10 * 1000, 50, EXPONENTIAL, "Time spent waiting on the cache service lock (ms) on the main thread in " #x)
CACHE_LOCK_HISTOGRAM(NSSETDISKSMARTSIZECALLBACK_NOTIFY)
CACHE_LOCK_HISTOGRAM(NSPROCESSREQUESTEVENT_RUN)
CACHE_LOCK_HISTOGRAM(NSOUTPUTSTREAMWRAPPER_LAZYINIT)
CACHE_LOCK_HISTOGRAM(NSOUTPUTSTREAMWRAPPER_CLOSE)
CACHE_LOCK_HISTOGRAM(NSINPUTSTREAMWRAPPER_LAZYINIT)
CACHE_LOCK_HISTOGRAM(NSEVICTDISKCACHEENTRIESEVENT_RUN)
CACHE_LOCK_HISTOGRAM(NSDOOMEVENT_RUN)
CACHE_LOCK_HISTOGRAM(NSDISKCACHESTREAMIO_WRITE)
CACHE_LOCK_HISTOGRAM(NSDISKCACHESTREAMIO_CLOSEOUTPUTSTREAM)
CACHE_LOCK_HISTOGRAM(NSDISKCACHEDEVICEDEACTIVATEENTRYEVENT_RUN)
CACHE_LOCK_HISTOGRAM(NSDISKCACHEBINDING_DESTRUCTOR)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_SHUTDOWN)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_SETOFFLINECACHEENABLED)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_SETOFFLINECACHECAPACITY)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_SETMEMORYCACHE)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_SETDISKSMARTSIZE)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_SETDISKCACHEMAXENTRYSIZE)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_SETMEMORYCACHEMAXENTRYSIZE)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_SETDISKCACHEENABLED)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_SETDISKCACHECAPACITY)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_OPENCACHEENTRY)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_ONPROFILESHUTDOWN)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_ONPROFILECHANGED)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_LEAVEPRIVATEBROWSING)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_ISSTORAGEENABLEDFORPOLICY)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_GETCACHEIOTARGET)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_EVICTENTRIESFORCLIENT)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_DOOM)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_SETPREDICTEDDATASIZE)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETDATASIZE)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETSTORAGEDATASIZE)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_REQUESTDATASIZECHANGE)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_SETDATASIZE)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_OPENINPUTSTREAM)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_OPENOUTPUTSTREAM)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETCACHEELEMENT)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_SETCACHEELEMENT)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETSTORAGEPOLICY)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_SETSTORAGEPOLICY)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETFILE)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETSECURITYINFO)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_SETSECURITYINFO)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_DOOMANDFAILPENDINGREQUESTS)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_MARKVALID)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_CLOSE)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETMETADATAELEMENT)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_SETMETADATAELEMENT)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_VISITMETADATA)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_SETEXPIRATIONTIME)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_ISSTREAMBASED)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETLASTMODIFIED)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETEXPIRATIONTIME)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETKEY)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETFETCHCOUNT)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETDEVICEID)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_PROCESSREQUEST)
CACHE_LOCK_HISTOGRAM(NSCACHESERVICE_VISITENTRIES)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETPREDICTEDDATASIZE)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETLASTFETCHED)
CACHE_LOCK_HISTOGRAM(NSCACHEENTRYDESCRIPTOR_GETCLIENTID)
CACHE_LOCK_HISTOGRAM(NSBLOCKONCACHETHREADEVENT_RUN)
#undef CACHE_LOCK_HISTOGRAM
// DNS_LOOKUP_METHOD was renamed to DNS_LOOKUP_METHOD2 as the old version did not use enumerated values
HISTOGRAM_ENUMERATED_VALUES(DNS_LOOKUP_METHOD2, 16, "DNS Lookup Type (hit, renewal, negative-hit, literal, overflow, network-first, network-shared)")
HISTOGRAM(DNS_CLEANUP_AGE, 1, 1440, 50, EXPONENTIAL, "DNS Cache Entry Age at Removal Time (minutes)")