コード例 #1
0
static bool
InitLog(const char* aEnvVar, const char* aMsg, FILE** aResult)
{
  const char* value = getenv(aEnvVar);
  if (value) {
    if (nsCRT::strcmp(value, "1") == 0) {
      *aResult = stdout;
      fprintf(stdout, "### %s defined -- logging %s to stdout\n",
              aEnvVar, aMsg);
      return true;
    } else if (nsCRT::strcmp(value, "2") == 0) {
      *aResult = stderr;
      fprintf(stdout, "### %s defined -- logging %s to stderr\n",
              aEnvVar, aMsg);
      return true;
    } else {
      FILE* stream;
      nsAutoCString fname(value);
      if (!XRE_IsParentProcess()) {
        bool hasLogExtension =
          fname.RFind(".log", true, -1, 4) == kNotFound ? false : true;
        if (hasLogExtension) {
          fname.Cut(fname.Length() - 4, 4);
        }
        fname.Append('_');
        fname.Append((char*)XRE_ChildProcessTypeToString(XRE_GetProcessType()));
        fname.AppendLiteral("_pid");
        fname.AppendInt((uint32_t)getpid());
        if (hasLogExtension) {
          fname.AppendLiteral(".log");
        }
      }
      stream = ::fopen(fname.get(), "w" FOPEN_NO_INHERIT);
      if (stream) {
        MozillaRegisterDebugFD(fileno(stream));
        *aResult = stream;
        fprintf(stdout, "### %s defined -- logging %s to %s\n",
                aEnvVar, aMsg, fname.get());
      } else {
        fprintf(stdout, "### %s defined -- unable to log %s to %s\n",
                aEnvVar, aMsg, fname.get());
        MOZ_ASSERT(false, "Tried and failed to create an XPCOM log");
      }
      return stream != nullptr;
    }
  }
  return false;
}
コード例 #2
0
static bool InitLog(const char* envVar, const char* msg, FILE* *result)
{
  const char* value = getenv(envVar);
  if (value) {
    if (nsCRT::strcmp(value, "1") == 0) {
      *result = stdout;
      fprintf(stdout, "### %s defined -- logging %s to stdout\n",
              envVar, msg);
      return true;
    }
    else if (nsCRT::strcmp(value, "2") == 0) {
      *result = stderr;
      fprintf(stdout, "### %s defined -- logging %s to stderr\n",
              envVar, msg);
      return true;
    }
    else {
      FILE *stream;
      nsAutoCString fname(value);
      if (XRE_GetProcessType() != GeckoProcessType_Default) {
        bool hasLogExtension = 
            fname.RFind(".log", true, -1, 4) == kNotFound ? false : true;
        if (hasLogExtension)
          fname.Cut(fname.Length() - 4, 4);
        fname.AppendLiteral("_");
        fname.Append((char*)XRE_ChildProcessTypeToString(XRE_GetProcessType()));
        fname.AppendLiteral("_pid");
        fname.AppendInt((uint32_t)getpid());
        if (hasLogExtension)
          fname.AppendLiteral(".log");
      }
      stream = ::fopen(fname.get(), "w" FOPEN_NO_INHERIT);
      if (stream != NULL) {
        MozillaRegisterDebugFD(fileno(stream));
        *result = stream;
        fprintf(stdout, "### %s defined -- logging %s to %s\n",
                envVar, msg, fname.get());
      }
      else {
        fprintf(stdout, "### %s defined -- unable to log %s to %s\n",
                envVar, msg, fname.get());
      }
      return stream != NULL;
    }
  }
  return false;
}
コード例 #3
0
  bool PrintDumpHeader(FILE* out, const char* msg, nsTraceRefcntImpl::StatisticsType type) {
    fprintf(out, "\n== BloatView: %s, %s process %d\n", msg,
            XRE_ChildProcessTypeToString(XRE_GetProcessType()), getpid());
    nsTraceRefcntStats& stats =
      (type == nsTraceRefcntImpl::NEW_STATS) ? mNewStats : mAllStats;
    if (gLogLeaksOnly && !HaveLeaks(&stats))
      return false;

    fprintf(out,
        "\n" \
        "     |<----------------Class--------------->|<-----Bytes------>|<----------------Objects---------------->|<--------------References-------------->|\n" \
        "                                              Per-Inst   Leaked    Total      Rem      Mean       StdDev     Total      Rem      Mean       StdDev\n");

    this->DumpTotal(out);

    return true;
  }
コード例 #4
0
  bool PrintDumpHeader(FILE* aOut, const char* aMsg)
  {
    fprintf(aOut, "\n== BloatView: %s, %s process %d\n", aMsg,
            XRE_ChildProcessTypeToString(XRE_GetProcessType()), getpid());
    if (gLogLeaksOnly && !mStats.HaveLeaks()) {
      return false;
    }

    fprintf(aOut,
            "\n" \
            "     |<----------------Class--------------->|<-----Bytes------>|<----Objects---->|\n" \
            "     |                                      | Per-Inst   Leaked|   Total      Rem|\n");

    this->DumpTotal(aOut);

    return true;
  }
コード例 #5
0
  bool PrintDumpHeader(FILE* aOut, const char* aMsg,
                       nsTraceRefcnt::StatisticsType aType)
  {
    fprintf(aOut, "\n== BloatView: %s, %s process %d\n", aMsg,
            XRE_ChildProcessTypeToString(XRE_GetProcessType()), getpid());
    nsTraceRefcntStats& stats =
      (aType == nsTraceRefcnt::NEW_STATS) ? mNewStats : mAllStats;
    if (gLogLeaksOnly && !HaveLeaks(&stats)) {
      return false;
    }

    fprintf(aOut,
            "\n" \
            "     |<----------------Class--------------->|<-----Bytes------>|<----Objects---->|\n" \
            "                                              Per-Inst   Leaked    Total      Rem\n");

    this->DumpTotal(aOut);

    return true;
  }
コード例 #6
0
// If MOZ_DMD_SHUTDOWN_LOG is set, dump a DMD report to a file.
// The value of this environment variable is used as the prefix
// of the file name, so you probably want something like "/tmp/".
// By default, this is run in all processes, but you can record a
// log only for a specific process type by setting MOZ_DMD_LOG_PROCESS
// to the process type you want to log, such as "default" or "tab".
// This method can't use the higher level XPCOM file utilities
// because it is run very late in shutdown to avoid recording
// information about refcount logging entries.
static void
LogDMDFile()
{
  const char* dmdFilePrefix = PR_GetEnv("MOZ_DMD_SHUTDOWN_LOG");
  if (!dmdFilePrefix) {
    return;
  }

  const char* logProcessEnv = PR_GetEnv("MOZ_DMD_LOG_PROCESS");
  if (logProcessEnv && !!strcmp(logProcessEnv, XRE_ChildProcessTypeToString(XRE_GetProcessType()))) {
    return;
  }

  nsPrintfCString fileName("%sdmd-%d.log.gz", dmdFilePrefix, base::GetCurrentProcId());
  FILE* logFile = fopen(fileName.get(), "w");
  if (NS_WARN_IF(!logFile)) {
    return;
  }

  nsMemoryInfoDumper::DumpDMDToFile(logFile);
}