Bug 1162751 - Part 3: Wrap expensive calls in PR_LOG_TEST. r=seth

Check that logging is enabled before performing potentially expensive
operations.
This commit is contained in:
Eric Rahm 2015-05-11 13:42:30 -07:00
parent 1c11239bb2
commit 1e0ae36c9f
4 changed files with 92 additions and 72 deletions

View File

@ -164,16 +164,18 @@ ProgressTracker::Notify(IProgressObserver* aObserver)
{
MOZ_ASSERT(NS_IsMainThread());
nsRefPtr<Image> image = GetImage();
if (image && image->GetURI()) {
nsRefPtr<ImageURL> uri(image->GetURI());
nsAutoCString spec;
uri->GetSpec(spec);
LOG_FUNC_WITH_PARAM(GetImgLog(),
"ProgressTracker::Notify async", "uri", spec.get());
} else {
LOG_FUNC_WITH_PARAM(GetImgLog(),
"ProgressTracker::Notify async", "uri", "<unknown>");
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsRefPtr<Image> image = GetImage();
if (image && image->GetURI()) {
nsRefPtr<ImageURL> uri(image->GetURI());
nsAutoCString spec;
uri->GetSpec(spec);
LOG_FUNC_WITH_PARAM(GetImgLog(),
"ProgressTracker::Notify async", "uri", spec.get());
} else {
LOG_FUNC_WITH_PARAM(GetImgLog(),
"ProgressTracker::Notify async", "uri", "<unknown>");
}
}
aObserver->SetNotificationsDeferred(true);
@ -231,13 +233,15 @@ ProgressTracker::NotifyCurrentState(IProgressObserver* aObserver)
{
MOZ_ASSERT(NS_IsMainThread());
nsRefPtr<Image> image = GetImage();
nsAutoCString spec;
if (image && image->GetURI()) {
image->GetURI()->GetSpec(spec);
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsRefPtr<Image> image = GetImage();
nsAutoCString spec;
if (image && image->GetURI()) {
image->GetURI()->GetSpec(spec);
}
LOG_FUNC_WITH_PARAM(GetImgLog(),
"ProgressTracker::NotifyCurrentState", "uri", spec.get());
}
LOG_FUNC_WITH_PARAM(GetImgLog(),
"ProgressTracker::NotifyCurrentState", "uri", spec.get());
aObserver->SetNotificationsDeferred(true);

View File

@ -893,18 +893,20 @@ imgCacheEntry::UpdateCache(int32_t diff /* = 0 */)
void
imgCacheEntry::SetHasNoProxies(bool hasNoProxies)
{
nsRefPtr<ImageURL> uri;
mRequest->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
if (uri) {
uri->GetSpec(spec);
}
if (hasNoProxies) {
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgCacheEntry::SetHasNoProxies true",
"uri", spec.get());
} else {
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgCacheEntry::SetHasNoProxies false",
"uri", spec.get());
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsRefPtr<ImageURL> uri;
mRequest->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
if (uri) {
uri->GetSpec(spec);
}
if (hasNoProxies) {
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgCacheEntry::SetHasNoProxies true",
"uri", spec.get());
} else {
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgCacheEntry::SetHasNoProxies false",
"uri", spec.get());
}
}
mHasNoProxies = hasNoProxies;
@ -1075,15 +1077,17 @@ imgCacheExpirationTracker::NotifyExpired(imgCacheEntry* entry)
// mechanism doesn't.
nsRefPtr<imgCacheEntry> kungFuDeathGrip(entry);
nsRefPtr<imgRequest> req(entry->GetRequest());
if (req) {
nsRefPtr<ImageURL> uri;
req->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
uri->GetSpec(spec);
LOG_FUNC_WITH_PARAM(GetImgLog(),
"imgCacheExpirationTracker::NotifyExpired",
"entry", spec.get());
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsRefPtr<imgRequest> req(entry->GetRequest());
if (req) {
nsRefPtr<ImageURL> uri;
req->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
uri->GetSpec(spec);
LOG_FUNC_WITH_PARAM(GetImgLog(),
"imgCacheExpirationTracker::NotifyExpired",
"entry", spec.get());
}
}
// We can be called multiple times on the same entry. Don't do work multiple
@ -1509,13 +1513,15 @@ imgLoader::PutIntoCache(const ImageCacheKey& aKey, imgCacheEntry* entry)
bool
imgLoader::SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry)
{
nsRefPtr<ImageURL> uri;
aRequest->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
uri->GetSpec(spec);
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsRefPtr<ImageURL> uri;
aRequest->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
uri->GetSpec(spec);
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
"imgLoader::SetHasNoProxies", "uri", spec.get());
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
"imgLoader::SetHasNoProxies", "uri", spec.get());
}
aEntry->SetHasNoProxies(true);
@ -1599,15 +1605,17 @@ imgLoader::CheckCacheLimits(imgCacheTable& cache, imgCacheQueue& queue)
NS_ASSERTION(entry, "imgLoader::CheckCacheLimits -- NULL entry pointer");
nsRefPtr<imgRequest> req(entry->GetRequest());
if (req) {
nsRefPtr<ImageURL> uri;
req->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
uri->GetSpec(spec);
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
"imgLoader::CheckCacheLimits",
"entry", spec.get());
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsRefPtr<imgRequest> req(entry->GetRequest());
if (req) {
nsRefPtr<ImageURL> uri;
req->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
uri->GetSpec(spec);
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
"imgLoader::CheckCacheLimits",
"entry", spec.get());
}
}
if (entry) {
@ -1837,7 +1845,7 @@ imgLoader::ValidateEntry(imgCacheEntry* aEntry,
PR_LOG(GetImgLog(), PR_LOG_DEBUG,
("imgLoader::ValidateEntry validating cache entry. "
"validateRequest = %d", validateRequest));
} else if (!key) {
} else if (!key && PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsAutoCString spec;
aURI->GetSpec(spec);
@ -2864,11 +2872,13 @@ imgCacheValidator::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
uri = imageURL->ToIURI();
}
nsAutoCString spec;
uri->GetSpec(spec);
LOG_MSG_WITH_PARAM(GetImgLog(),
"imgCacheValidator::OnStartRequest creating new request",
"uri", spec.get());
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsAutoCString spec;
uri->GetSpec(spec);
LOG_MSG_WITH_PARAM(GetImgLog(),
"imgCacheValidator::OnStartRequest creating new request",
"uri", spec.get());
}
int32_t corsmode = mRequest->GetCORSMode();
ReferrerPolicy refpol = mRequest->GetReferrerPolicy();

View File

@ -258,8 +258,7 @@ imgRequest::RemoveProxy(imgRequestProxy* proxy, nsresult aStatus)
if (mLoader) {
mLoader->SetHasNoProxies(this, mCacheEntry);
}
}
else {
} else if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsAutoCString spec;
mURI->GetSpec(spec);
LOG_MSG_WITH_PARAM(GetImgLog(),

View File

@ -861,10 +861,13 @@ imgRequestProxy::Notify(int32_t aType, const mozilla::gfx::IntRect* aRect)
void
imgRequestProxy::OnLoadComplete(bool aLastPart)
{
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::OnLoadComplete",
"name", name.get());
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::OnLoadComplete",
"name", name.get());
}
// There's all sorts of stuff here that could kill us (the OnStopRequest call
// on the listener, the removal from the loadgroup, the release of the
// listener, etc). Don't let them do it.
@ -904,10 +907,12 @@ imgRequestProxy::OnLoadComplete(bool aLastPart)
void
imgRequestProxy::BlockOnload()
{
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::BlockOnload",
"name", name.get());
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::BlockOnload",
"name", name.get());
}
nsCOMPtr<imgIOnloadBlocker> blocker = do_QueryInterface(mListener);
if (blocker) {
@ -918,10 +923,12 @@ imgRequestProxy::BlockOnload()
void
imgRequestProxy::UnblockOnload()
{
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::UnblockOnload",
"name", name.get());
if (PR_LOG_TEST(GetImgLog(), PR_LOG_DEBUG)) {
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::UnblockOnload",
"name", name.get());
}
nsCOMPtr<imgIOnloadBlocker> blocker = do_QueryInterface(mListener);
if (blocker) {