// Read env vars at startup, so as to set sUnwindMode and sInterval. void read_profiler_env_vars() { bool nativeAvail = is_native_unwinding_avail(); /* Set defaults */ sUnwindMode = nativeAvail ? UnwCOMBINED : UnwPSEUDO; sUnwindInterval = 0; /* We'll have to look elsewhere */ sProfileEntries = 0; const char* stackMode = PR_GetEnv(PROFILER_MODE); const char* interval = PR_GetEnv(PROFILER_INTERVAL); const char* entries = PR_GetEnv(PROFILER_ENTRIES); const char* scanCount = PR_GetEnv(PROFILER_STACK); if (!set_profiler_mode(stackMode) || !set_profiler_interval(interval) || !set_profiler_entries(entries) || !set_profiler_scan(scanCount)) { profiler_usage(); } else { LOG( "SPS:"); LOGF("SPS: Unwind mode = %s", name_UnwMode(sUnwindMode)); LOGF("SPS: Sampling interval = %d ms (zero means \"platform default\")", (int)sUnwindInterval); LOGF("SPS: Entry store size = %d (zero means \"platform default\")", (int)sProfileEntries); LOGF("SPS: UnwindStackScan = %d (max dubious frames per unwind).", (int)sUnwindStackScan); LOG( "SPS: Use env var MOZ_PROFILER_MODE=help for further information."); LOG( "SPS:"); } }
void profiler_usage() { LOG( "SPS: "); LOG( "SPS: Environment variable usage:"); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_MODE=native for native unwind only"); LOG( "SPS: MOZ_PROFILER_MODE=pseudo for pseudo unwind only"); LOG( "SPS: MOZ_PROFILER_MODE=combined for combined native & pseudo unwind"); LOG( "SPS: If unset, default is 'combined' on native-capable"); LOG( "SPS: platforms, 'pseudo' on others."); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_INTERVAL=<number> (milliseconds, 1 to 1000)"); LOG( "SPS: If unset, platform default is used."); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_ENTRIES=<number> (count, minimum of 1)"); LOG( "SPS: If unset, platform default is used."); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_VERBOSE"); LOG( "SPS: If set to any value, increases verbosity (recommended)."); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_STACK_SCAN=<number> (default is zero)"); LOG( "SPS: The number of dubious (stack-scanned) frames allowed"); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_NEW"); LOG( "SPS: Needs to be set to use Breakpad-based unwinding."); LOG( "SPS: "); LOGF("SPS: This platform %s native unwinding.", is_native_unwinding_avail() ? "supports" : "does not support"); LOG( "SPS: "); /* Re-set defaults */ sUnwindMode = is_native_unwinding_avail() ? UnwCOMBINED : UnwPSEUDO; sUnwindInterval = 0; /* We'll have to look elsewhere */ sProfileEntries = 0; sUnwindStackScan = 0; LOG( "SPS:"); LOGF("SPS: Unwind mode = %s", name_UnwMode(sUnwindMode)); LOGF("SPS: Sampling interval = %d ms (zero means \"platform default\")", (int)sUnwindInterval); LOGF("SPS: Entry store size = %d (zero means \"platform default\")", (int)sProfileEntries); LOGF("SPS: UnwindStackScan = %d (max dubious frames per unwind).", (int)sUnwindStackScan); LOG( "SPS: Use env var MOZ_PROFILER_MODE=help for further information."); LOG( "SPS:"); return; }
// Read env vars at startup, so as to set sUnwindMode and sInterval. void read_profiler_env_vars() { bool nativeAvail = false; # if defined(HAVE_NATIVE_UNWIND) nativeAvail = true; # endif MOZ_ASSERT(sUnwindMode == UnwINVALID); MOZ_ASSERT(sUnwindInterval == 0); /* Set defaults */ sUnwindMode = nativeAvail ? UnwCOMBINED : UnwPSEUDO; sUnwindInterval = 0; /* We'll have to look elsewhere */ const char* strM = PR_GetEnv("MOZ_PROFILER_MODE"); const char* strI = PR_GetEnv("MOZ_PROFILER_INTERVAL"); const char* strF = PR_GetEnv("MOZ_PROFILER_STACK_SCAN"); if (strM) { if (0 == strcmp(strM, "pseudo")) sUnwindMode = UnwPSEUDO; else if (0 == strcmp(strM, "native") && nativeAvail) sUnwindMode = UnwNATIVE; else if (0 == strcmp(strM, "combined") && nativeAvail) sUnwindMode = UnwCOMBINED; else goto usage; } if (strI) { errno = 0; long int n = strtol(strI, (char**)NULL, 10); if (errno == 0 && n >= 1 && n <= 1000) { sUnwindInterval = n; } else goto usage; } if (strF) { errno = 0; long int n = strtol(strF, (char**)NULL, 10); if (errno == 0 && n >= 0 && n <= 100) { sUnwindStackScan = n; } else goto usage; } goto out; usage: LOG( "SPS: "); LOG( "SPS: Environment variable usage:"); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_MODE=native for native unwind only"); LOG( "SPS: MOZ_PROFILER_MODE=pseudo for pseudo unwind only"); LOG( "SPS: MOZ_PROFILER_MODE=combined for combined native & pseudo unwind"); LOG( "SPS: If unset, default is 'combined' on native-capable"); LOG( "SPS: platforms, 'pseudo' on others."); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_INTERVAL=<number> (milliseconds, 1 to 1000)"); LOG( "SPS: If unset, platform default is used."); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_VERBOSE"); LOG( "SPS: If set to any value, increases verbosity (recommended)."); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_STACK_SCAN=<number> (default is zero)"); LOG( "SPS: The number of dubious (stack-scanned) frames allowed"); LOG( "SPS: "); LOG( "SPS: MOZ_PROFILER_NEW"); LOG( "SPS: Needs to be set to use Breakpad-based unwinding."); LOG( "SPS: "); LOGF("SPS: This platform %s native unwinding.", nativeAvail ? "supports" : "does not support"); LOG( "SPS: "); /* Re-set defaults */ sUnwindMode = nativeAvail ? UnwCOMBINED : UnwPSEUDO; sUnwindInterval = 0; /* We'll have to look elsewhere */ sUnwindStackScan = 0; out: LOG( "SPS:"); LOGF("SPS: Unwind mode = %s", name_UnwMode(sUnwindMode)); LOGF("SPS: Sampling interval = %d ms (zero means \"platform default\")", (int)sUnwindInterval); LOGF("SPS: UnwindStackScan = %d (max dubious frames per unwind).", (int)sUnwindStackScan); LOG( "SPS: Use env var MOZ_PROFILER_MODE=help for further information."); LOG( "SPS:"); return; }