Commit b9dd7823 authored by Eric Rahm's avatar Eric Rahm
Browse files

Bug 1162336 - Part 2: Wrap expensive calls in PR_LOG_TEST. r=froydnj

Check that logging is enabled before performing potentially expensive
operations.
parent ba22eb7f
Loading
Loading
Loading
Loading
+20 −14
Original line number Original line Diff line number Diff line
@@ -257,10 +257,12 @@ nsLoadGroup::Cancel(nsresult status)
            continue;
            continue;
        }
        }


        if (PR_LOG_TEST(gLoadGroupLog, PR_LOG_DEBUG)) {
            nsAutoCString nameStr;
            nsAutoCString nameStr;
            request->GetName(nameStr);
            request->GetName(nameStr);
            LOG(("LOADGROUP [%x]: Canceling request %x %s.\n",
            LOG(("LOADGROUP [%x]: Canceling request %x %s.\n",
                 this, request, nameStr.get()));
                 this, request, nameStr.get()));
        }


        //
        //
        // Remove the request from the load group...  This may cause
        // Remove the request from the load group...  This may cause
@@ -323,10 +325,12 @@ nsLoadGroup::Suspend()
        if (!request)
        if (!request)
            continue;
            continue;


        if (PR_LOG_TEST(gLoadGroupLog, PR_LOG_DEBUG)) {
            nsAutoCString nameStr;
            nsAutoCString nameStr;
            request->GetName(nameStr);
            request->GetName(nameStr);
            LOG(("LOADGROUP [%x]: Suspending request %x %s.\n",
            LOG(("LOADGROUP [%x]: Suspending request %x %s.\n",
                this, request, nameStr.get()));
                this, request, nameStr.get()));
        }


        // Suspend the request...
        // Suspend the request...
        rv = request->Suspend();
        rv = request->Suspend();
@@ -373,10 +377,12 @@ nsLoadGroup::Resume()
        if (!request)
        if (!request)
            continue;
            continue;


        if (PR_LOG_TEST(gLoadGroupLog, PR_LOG_DEBUG)) {
            nsAutoCString nameStr;
            nsAutoCString nameStr;
            request->GetName(nameStr);
            request->GetName(nameStr);
            LOG(("LOADGROUP [%x]: Resuming request %x %s.\n",
            LOG(("LOADGROUP [%x]: Resuming request %x %s.\n",
                this, request, nameStr.get()));
                this, request, nameStr.get()));
        }


        // Resume the request...
        // Resume the request...
        rv = request->Resume();
        rv = request->Resume();
@@ -460,7 +466,7 @@ nsLoadGroup::AddRequest(nsIRequest *request, nsISupports* ctxt)
{
{
    nsresult rv;
    nsresult rv;


    {
    if (PR_LOG_TEST(gLoadGroupLog, PR_LOG_DEBUG)) {
        nsAutoCString nameStr;
        nsAutoCString nameStr;
        request->GetName(nameStr);
        request->GetName(nameStr);
        LOG(("LOADGROUP [%x]: Adding request %x %s (count=%d).\n",
        LOG(("LOADGROUP [%x]: Adding request %x %s (count=%d).\n",
@@ -557,7 +563,7 @@ nsLoadGroup::RemoveRequest(nsIRequest *request, nsISupports* ctxt,
    NS_ENSURE_ARG_POINTER(request);
    NS_ENSURE_ARG_POINTER(request);
    nsresult rv;
    nsresult rv;


    {
    if (PR_LOG_TEST(gLoadGroupLog, PR_LOG_DEBUG)) {
        nsAutoCString nameStr;
        nsAutoCString nameStr;
        request->GetName(nameStr);
        request->GetName(nameStr);
        LOG(("LOADGROUP [%x]: Removing request %x %s status %x (count=%d).\n",
        LOG(("LOADGROUP [%x]: Removing request %x %s status %x (count=%d).\n",
+6 −4
Original line number Original line Diff line number Diff line
@@ -1767,10 +1767,12 @@ nsCacheService::CreateCustomOfflineDevice(nsIFile *aProfileDir,
{
{
    NS_ENSURE_ARG(aProfileDir);
    NS_ENSURE_ARG(aProfileDir);


    if (PR_LOG_TEST(gCacheLog, PR_LOG_ALWAYS)) {
      nsAutoCString profilePath;
      nsAutoCString profilePath;
      aProfileDir->GetNativePath(profilePath);
      aProfileDir->GetNativePath(profilePath);
      CACHE_LOG_ALWAYS(("Creating custom offline device, %s, %d",
      CACHE_LOG_ALWAYS(("Creating custom offline device, %s, %d",
                        profilePath.BeginReading(), aQuota));
                        profilePath.BeginReading(), aQuota));
    }


    if (!mInitialized)         return NS_ERROR_NOT_AVAILABLE;
    if (!mInitialized)         return NS_ERROR_NOT_AVAILABLE;
    if (!mEnableOfflineDevice) return NS_ERROR_NOT_AVAILABLE;
    if (!mEnableOfflineDevice) return NS_ERROR_NOT_AVAILABLE;
+5 −3
Original line number Original line Diff line number Diff line
@@ -225,9 +225,11 @@ nsOfflineCacheEvictionFunction::Apply()
  LOG(("nsOfflineCacheEvictionFunction::Apply\n"));
  LOG(("nsOfflineCacheEvictionFunction::Apply\n"));


  for (int32_t i = 0; i < mItems.Count(); i++) {
  for (int32_t i = 0; i < mItems.Count(); i++) {
    if (PR_LOG_TEST(gCacheLog, PR_LOG_DEBUG)) {
      nsAutoCString path;
      nsAutoCString path;
      mItems[i]->GetNativePath(path);
      mItems[i]->GetNativePath(path);
      LOG(("  removing %s\n", path.get()));
      LOG(("  removing %s\n", path.get()));
    }


    mItems[i]->Remove(false);
    mItems[i]->Remove(false);
  }
  }
+13 −9
Original line number Original line Diff line number Diff line
@@ -3199,12 +3199,14 @@ CacheFileIOManager::RemoveTrashInternal()
      if (isDir) {
      if (isDir) {
        NS_WARNING("Found a directory in a trash directory! It will be removed "
        NS_WARNING("Found a directory in a trash directory! It will be removed "
                   "recursively, but this can block IO thread for a while!");
                   "recursively, but this can block IO thread for a while!");
        if (LOG_ENABLED()) {
          nsAutoCString path;
          nsAutoCString path;
          file->GetNativePath(path);
          file->GetNativePath(path);
          LOG(("CacheFileIOManager::RemoveTrashInternal() - Found a directory in a trash "
          LOG(("CacheFileIOManager::RemoveTrashInternal() - Found a directory in a trash "
              "directory! It will be removed recursively, but this can block IO "
              "directory! It will be removed recursively, but this can block IO "
              "thread for a while! [file=%s]", path.get()));
              "thread for a while! [file=%s]", path.get()));
        }
        }
      }
      file->Remove(isDir);
      file->Remove(isDir);
    }
    }
  }
  }
@@ -3757,10 +3759,12 @@ CacheFileIOManager::SyncRemoveDir(nsIFile *aFile, const char *aDir)
    }
    }
  }
  }


  if (LOG_ENABLED()) {
    nsAutoCString path;
    nsAutoCString path;
    file->GetNativePath(path);
    file->GetNativePath(path);
    LOG(("CacheFileIOManager::SyncRemoveDir() - Removing directory %s",
    LOG(("CacheFileIOManager::SyncRemoveDir() - Removing directory %s",
         path.get()));
         path.get()));
  }


  rv = file->Remove(true);
  rv = file->Remove(true);
  if (NS_WARN_IF(NS_FAILED(rv))) {
  if (NS_WARN_IF(NS_FAILED(rv))) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -12,6 +12,7 @@ namespace net {


extern PRLogModuleInfo* GetCache2Log();
extern PRLogModuleInfo* GetCache2Log();
#define LOG(x)  PR_LOG(GetCache2Log(), PR_LOG_DEBUG, x)
#define LOG(x)  PR_LOG(GetCache2Log(), PR_LOG_DEBUG, x)
#define LOG_ENABLED() PR_LOG_TEST(GetCache2Log(), PR_LOG_DEBUG)


} // net
} // net
} // mozilla
} // mozilla
Loading