diff --git a/mozglue/baseprofiler/core/ProfileBufferEntry.cpp b/mozglue/baseprofiler/core/ProfileBufferEntry.cpp index bddacc323ed8..5778ef1469d9 100644 --- a/mozglue/baseprofiler/core/ProfileBufferEntry.cpp +++ b/mozglue/baseprofiler/core/ProfileBufferEntry.cpp @@ -656,11 +656,11 @@ void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, unsigned long long pcULL = (unsigned long long)(uintptr_t)pc; SprintfLiteral(buf, "%#llx", pcULL); - // If the "MOZ_PROFILER_SYMBOLICATE" env-var is set, we add a local - // symbolication description to the PC address. This is off by + // If the "MOZ_BASE_PROFILER_SYMBOLICATE" env-var is set, we add a + // local symbolication description to the PC address. This is off by // default, and mainly intended for local development. static const bool preSymbolicate = []() { - const char* symbolicate = getenv("MOZ_PROFILER_SYMBOLICATE"); + const char* symbolicate = getenv("MOZ_BASE_PROFILER_SYMBOLICATE"); return symbolicate && symbolicate[0] != '\0'; }(); if (preSymbolicate) { diff --git a/mozglue/baseprofiler/core/platform.cpp b/mozglue/baseprofiler/core/platform.cpp index 5536200260b0..0fa93d3fd740 100644 --- a/mozglue/baseprofiler/core/platform.cpp +++ b/mozglue/baseprofiler/core/platform.cpp @@ -60,7 +60,6 @@ # include "prtime.h" # include -# include # include # include # include @@ -191,7 +190,7 @@ static uint32_t DefaultFeatures() { ProfilerFeature::StackWalk | ProfilerFeature::Threads; } -// Extra default features when MOZ_PROFILER_STARTUP is set (even if not +// Extra default features when MOZ_BASE_PROFILER_STARTUP is set (even if not // available). static uint32_t StartupExtraDefaultFeatures() { // Enable mainthreadio by default for startup profiles as startup is heavy on @@ -1809,53 +1808,52 @@ static void PrintUsageThenExit(int aExitCode) { "\n" " MOZ_BASE_PROFILER_HELP\n" " If set to any value, prints this message.\n" - " (Only BaseProfiler features are known here; Use MOZ_PROFILER_HELP\n" - " for Gecko Profiler help, with more features).\n" + " Use MOZ_PROFILER_HELP for Gecko Profiler help.\n" "\n" " MOZ_BASE_PROFILER_{,DEBUG_,VERBOSE}LOGGING\n" - " Enables BaseProfiler logging to stdout. The levels of logging\n" - " available are MOZ_BASE_PROFILER_LOGGING' (least verbose),\n" - " '..._DEBUG_LOGGING', '..._VERBOSE_LOGGING' (most verbose)\n" + " Enables logging to stdout. The levels of logging available are\n" + " 'MOZ_BASE_PROFILER_LOGGING' (least verbose), '..._DEBUG_LOGGING',\n" + " '..._VERBOSE_LOGGING' (most verbose)\n" "\n" - " MOZ_PROFILER_STARTUP\n" + " MOZ_BASE_PROFILER_STARTUP\n" " If set to any value other than '' or '0'/'N'/'n', starts the\n" " profiler immediately on start-up.\n" " Useful if you want profile code that runs very early.\n" "\n" - " MOZ_PROFILER_STARTUP_ENTRIES=<1..>\n" - " If MOZ_PROFILER_STARTUP is set, specifies the number of entries\n" + " MOZ_BASE_PROFILER_STARTUP_ENTRIES=<1..>\n" + " If MOZ_BASE_PROFILER_STARTUP is set, specifies the number of entries\n" " per process in the profiler's circular buffer when the profiler is\n" " first started.\n" " If unset, the platform default is used:\n" - " %u entries per process, or %u when MOZ_PROFILER_STARTUP is set.\n" + " %u entries per process, or %u when MOZ_BASE_PROFILER_STARTUP is set.\n" " (8 bytes per entry -> %u or %u total bytes per process)\n" "\n" - " MOZ_PROFILER_STARTUP_DURATION=<1..>\n" - " If MOZ_PROFILER_STARTUP is set, specifies the maximum life time\n" + " MOZ_BASE_PROFILER_STARTUP_DURATION=<1..>\n" + " If MOZ_BASE_PROFILER_STARTUP is set, specifies the maximum life time\n" " of entries in the the profiler's circular buffer when the profiler\n" " is first started, in seconds.\n" " If unset, the life time of the entries will only be restricted by\n" - " MOZ_PROFILER_STARTUP_ENTRIES (or its default value), and no\n" + " MOZ_BASE_PROFILER_STARTUP_ENTRIES (or its default value), and no\n" " additional time duration restriction will be applied.\n" "\n" - " MOZ_PROFILER_STARTUP_INTERVAL=<1..1000>\n" - " If MOZ_PROFILER_STARTUP is set, specifies the sample interval,\n" + " MOZ_BASE_PROFILER_STARTUP_INTERVAL=<1..1000>\n" + " If MOZ_BASE_PROFILER_STARTUP is set, specifies the sample interval,\n" " measured in milliseconds, when the profiler is first started.\n" " If unset, the platform default is used.\n" "\n" - " MOZ_PROFILER_STARTUP_FEATURES_BITFIELD=\n" - " If MOZ_PROFILER_STARTUP is set, specifies the profiling\n" + " MOZ_BASE_PROFILER_STARTUP_FEATURES_BITFIELD=\n" + " If MOZ_BASE_PROFILER_STARTUP is set, specifies the profiling\n" " features, as the integer value of the features bitfield.\n" - " If unset, the value from MOZ_PROFILER_STARTUP_FEATURES is used.\n" + " If unset, the value from MOZ_BASE_PROFILER_STARTUP_FEATURES is used.\n" "\n" - " MOZ_PROFILER_STARTUP_FEATURES=\n" - " If MOZ_PROFILER_STARTUP is set, specifies the profiling\n" + " MOZ_BASE_PROFILER_STARTUP_FEATURES=\n" + " If MOZ_BASE_PROFILER_STARTUP is set, specifies the profiling\n" " features, as a comma-separated list of strings.\n" - " Ignored if MOZ_PROFILER_STARTUP_FEATURES_BITFIELD is set.\n" + " Ignored if MOZ_BASE_PROFILER_STARTUP_FEATURES_BITFIELD is set.\n" " If unset, the platform default is used.\n" "\n" " Features: (x=unavailable, D/d=default/unavailable,\n" - " S/s=MOZ_PROFILER_STARTUP extra " + " S/s=MOZ_BASE_PROFILER_STARTUP extra " "default/unavailable)\n", unsigned(BASE_PROFILER_DEFAULT_ENTRIES.Value()), unsigned(BASE_PROFILER_DEFAULT_STARTUP_ENTRIES.Value()), @@ -1874,22 +1872,22 @@ static void PrintUsageThenExit(int aExitCode) { printf( " - \"default\" (All above D+S defaults)\n" "\n" - " MOZ_PROFILER_STARTUP_FILTERS=\n" - " If MOZ_PROFILER_STARTUP is set, specifies the thread filters, as " + " MOZ_BASE_PROFILER_STARTUP_FILTERS=\n" + " If MOZ_BASE_PROFILER_STARTUP is set, specifies the thread filters, as " "a\n" " comma-separated list of strings. A given thread will be sampled if\n" " any of the filters is a case-insensitive substring of the thread\n" " name. If unset, a default is used.\n" "\n" - " MOZ_PROFILER_SHUTDOWN\n" + " MOZ_BASE_PROFILER_SHUTDOWN\n" " If set, the profiler saves a profile to the named file on shutdown.\n" "\n" - " MOZ_PROFILER_SYMBOLICATE\n" + " MOZ_BASE_PROFILER_SYMBOLICATE\n" " If set, the profiler will pre-symbolicate profiles.\n" " *Note* This will add a significant pause when gathering data, and\n" " is intended mainly for local development.\n" "\n" - " MOZ_PROFILER_LUL_TEST\n" + " MOZ_BASE_PROFILER_LUL_TEST\n" " If set to any value, runs LUL unit tests at startup.\n" "\n" " This platform %s native unwinding.\n" @@ -2255,8 +2253,7 @@ static uint32_t ParseFeature(const char* aFeature, bool aIsStartup) { # undef PARSE_FEATURE_BIT printf("\nUnrecognized feature \"%s\".\n\n", aFeature); - // Since we may have an old feature we don't implement anymore, don't exit - PrintUsageThenExit(0); + PrintUsageThenExit(1); return 0; } @@ -2388,7 +2385,7 @@ void profiler_init(void* aStackTop) { // startup, even if no profiling is actually to be done. So, instead, it is // created on demand at the first call to PlatformStart(). - const char* startupEnv = getenv("MOZ_PROFILER_STARTUP"); + const char* startupEnv = getenv("MOZ_BASE_PROFILER_STARTUP"); if (!startupEnv || startupEnv[0] == '\0' || ((startupEnv[0] == '0' || startupEnv[0] == 'N' || startupEnv[0] == 'n') && @@ -2396,12 +2393,12 @@ void profiler_init(void* aStackTop) { return; } - LOG("- MOZ_PROFILER_STARTUP is set"); + LOG("- MOZ_BASE_PROFILER_STARTUP is set"); // Startup default capacity may be different. capacity = BASE_PROFILER_DEFAULT_STARTUP_ENTRIES; - const char* startupCapacity = getenv("MOZ_PROFILER_STARTUP_ENTRIES"); + const char* startupCapacity = getenv("MOZ_BASE_PROFILER_STARTUP_ENTRIES"); if (startupCapacity && startupCapacity[0] != '\0') { errno = 0; long capacityLong = strtol(startupCapacity, nullptr, 10); @@ -2412,61 +2409,67 @@ void profiler_init(void* aStackTop) { static_cast(capacityLong) <= static_cast(INT32_MAX)) { capacity = PowerOfTwo32(static_cast(capacityLong)); - LOG("- MOZ_PROFILER_STARTUP_ENTRIES = %u", unsigned(capacity.Value())); + LOG("- MOZ_BASE_PROFILER_STARTUP_ENTRIES = %u", + unsigned(capacity.Value())); } else { - LOG("- MOZ_PROFILER_STARTUP_ENTRIES not a valid integer: %s", + LOG("- MOZ_BASE_PROFILER_STARTUP_ENTRIES not a valid integer: %s", startupCapacity); PrintUsageThenExit(1); } } - const char* startupDuration = getenv("MOZ_PROFILER_STARTUP_DURATION"); + const char* startupDuration = getenv("MOZ_BASE_PROFILER_STARTUP_DURATION"); if (startupDuration && startupDuration[0] != '\0') { - errno = 0; - double durationVal = strtod(startupDuration, nullptr); - if (errno == 0 && durationVal >= 0.0 && durationVal < HUGE_VAL) { - if (durationVal > 0.0) { - duration = Some(durationVal); - } - LOG("- MOZ_PROFILER_STARTUP_DURATION = %f", durationVal); - } else { - LOG("- MOZ_PROFILER_STARTUP_DURATION not a valid float: %s", - startupDuration); - PrintUsageThenExit(1); - } + // TODO implement if needed + MOZ_CRASH("MOZ_BASE_PROFILER_STARTUP_DURATION unsupported"); + // errno = 0; + // double durationVal = PR_strtod(startupDuration, nullptr); + // if (errno == 0 && durationVal >= 0.0) { + // if (durationVal > 0.0) { + // duration = Some(durationVal); + // } + // LOG("- MOZ_BASE_PROFILER_STARTUP_DURATION = %f", durationVal); + // } else { + // LOG("- MOZ_BASE_PROFILER_STARTUP_DURATION not a valid float: %s", + // startupDuration); + // PrintUsageThenExit(1); + // } } - const char* startupInterval = getenv("MOZ_PROFILER_STARTUP_INTERVAL"); + const char* startupInterval = getenv("MOZ_BASE_PROFILER_STARTUP_INTERVAL"); if (startupInterval && startupInterval[0] != '\0') { - errno = 0; - interval = strtod(startupInterval, nullptr); - if (errno == 0 && interval > 0.0 && interval <= 1000.0) { - LOG("- MOZ_PROFILER_STARTUP_INTERVAL = %f", interval); - } else { - LOG("- MOZ_PROFILER_STARTUP_INTERVAL not a valid float: %s", - startupInterval); - PrintUsageThenExit(1); - } + // TODO implement if needed + MOZ_CRASH("MOZ_BASE_PROFILER_STARTUP_INTERVAL unsupported"); + // errno = 0; + // interval = PR_strtod(startupInterval, nullptr); + // if (errno == 0 && interval > 0.0 && interval <= 1000.0) { + // LOG("- MOZ_BASE_PROFILER_STARTUP_INTERVAL = %f", interval); + // } else { + // LOG("- MOZ_BASE_PROFILER_STARTUP_INTERVAL not a valid float: %s", + // startupInterval); + // PrintUsageThenExit(1); + // } } features |= StartupExtraDefaultFeatures() & AvailableFeatures(); const char* startupFeaturesBitfield = - getenv("MOZ_PROFILER_STARTUP_FEATURES_BITFIELD"); + getenv("MOZ_BASE_PROFILER_STARTUP_FEATURES_BITFIELD"); if (startupFeaturesBitfield && startupFeaturesBitfield[0] != '\0') { errno = 0; features = strtol(startupFeaturesBitfield, nullptr, 10); if (errno == 0 && features != 0) { - LOG("- MOZ_PROFILER_STARTUP_FEATURES_BITFIELD = %d", features); + LOG("- MOZ_BASE_PROFILER_STARTUP_FEATURES_BITFIELD = %d", features); } else { - LOG("- MOZ_PROFILER_STARTUP_FEATURES_BITFIELD not a valid " + LOG("- MOZ_BASE_PROFILER_STARTUP_FEATURES_BITFIELD not a valid " "integer: " "%s", startupFeaturesBitfield); PrintUsageThenExit(1); } } else { - const char* startupFeatures = getenv("MOZ_PROFILER_STARTUP_FEATURES"); + const char* startupFeatures = + getenv("MOZ_BASE_PROFILER_STARTUP_FEATURES"); if (startupFeatures && startupFeatures[0] != '\0') { // Interpret startupFeatures as a list of feature strings, separated by // commas. @@ -2476,14 +2479,14 @@ void profiler_init(void* aStackTop) { features = ParseFeaturesFromStringArray(featureStringArray.begin(), featureStringArray.length(), /* aIsStartup */ true); - LOG("- MOZ_PROFILER_STARTUP_FEATURES = %d", features); + LOG("- MOZ_BASE_PROFILER_STARTUP_FEATURES = %d", features); } } - const char* startupFilters = getenv("MOZ_PROFILER_STARTUP_FILTERS"); + const char* startupFilters = getenv("MOZ_BASE_PROFILER_STARTUP_FILTERS"); if (startupFilters && startupFilters[0] != '\0') { filters = SplitAtCommas(startupFilters, filterStorage); - LOG("- MOZ_PROFILER_STARTUP_FILTERS = %s", startupFilters); + LOG("- MOZ_BASE_PROFILER_STARTUP_FILTERS = %s", startupFilters); } locked_profiler_start(lock, capacity, interval, features, filters.begin(), @@ -2521,7 +2524,7 @@ void profiler_shutdown() { // Save the profile on shutdown if requested. if (ActivePS::Exists(lock)) { - const char* filename = getenv("MOZ_PROFILER_SHUTDOWN"); + const char* filename = getenv("MOZ_BASE_PROFILER_SHUTDOWN"); if (filename) { locked_profiler_save_profile_to_file(lock, filename, /* aIsShuttingDown */ true); @@ -2645,24 +2648,24 @@ void GetProfilerEnvVarsForChildProcess( PSAutoLock lock; if (!ActivePS::Exists(lock)) { - aSetEnv("MOZ_PROFILER_STARTUP", ""); + aSetEnv("MOZ_BASE_PROFILER_STARTUP", ""); return; } - aSetEnv("MOZ_PROFILER_STARTUP", "1"); + aSetEnv("MOZ_BASE_PROFILER_STARTUP", "1"); auto capacityString = Smprintf("%u", unsigned(ActivePS::Capacity(lock).Value())); - aSetEnv("MOZ_PROFILER_STARTUP_ENTRIES", capacityString.get()); + aSetEnv("MOZ_BASE_PROFILER_STARTUP_ENTRIES", capacityString.get()); // Use AppendFloat instead of Smprintf with %f because the decimal // separator used by %f is locale-dependent. But the string we produce needs // to be parseable by strtod, which only accepts the period character as a // decimal separator. AppendFloat always uses the period character. std::string intervalString = std::to_string(ActivePS::Interval(lock)); - aSetEnv("MOZ_PROFILER_STARTUP_INTERVAL", intervalString.c_str()); + aSetEnv("MOZ_BASE_PROFILER_STARTUP_INTERVAL", intervalString.c_str()); auto featuresString = Smprintf("%d", ActivePS::Features(lock)); - aSetEnv("MOZ_PROFILER_STARTUP_FEATURES_BITFIELD", featuresString.get()); + aSetEnv("MOZ_BASE_PROFILER_STARTUP_FEATURES_BITFIELD", featuresString.get()); std::string filtersString; const Vector& filters = ActivePS::Filters(lock); @@ -2672,7 +2675,7 @@ void GetProfilerEnvVarsForChildProcess( filtersString += ","; } } - aSetEnv("MOZ_PROFILER_STARTUP_FILTERS", filtersString.c_str()); + aSetEnv("MOZ_BASE_PROFILER_STARTUP_FILTERS", filtersString.c_str()); } void profiler_received_exit_profile(const std::string& aExitProfile) { diff --git a/mozglue/baseprofiler/public/BaseProfiler.h b/mozglue/baseprofiler/public/BaseProfiler.h index 433e4e2af7fa..735e4abdbbb5 100644 --- a/mozglue/baseprofiler/public/BaseProfiler.h +++ b/mozglue/baseprofiler/public/BaseProfiler.h @@ -252,8 +252,8 @@ static constexpr PowerOfTwo32 BASE_PROFILER_DEFAULT_STARTUP_ENTRIES = # define BASE_PROFILER_DEFAULT_DURATION 20 # define BASE_PROFILER_DEFAULT_INTERVAL 1 -// Initialize the profiler. If MOZ_PROFILER_STARTUP is set the profiler will -// also be started. This call must happen before any other profiler calls +// Initialize the profiler. If MOZ_BASE_PROFILER_STARTUP is set the profiler +// will also be started. This call must happen before any other profiler calls // (except profiler_start(), which will call profiler_init() if it hasn't // already run). MFBT_API void profiler_init(void* stackTop); @@ -1015,7 +1015,7 @@ class MOZ_RAII AutoProfilerTracing { const Maybe mInnerWindowID; }; -// Get the MOZ_PROFILER_STARTUP* environment variables that should be +// Get the MOZ_BASE_PROFILER_STARTUP* environment variables that should be // supplied to a child process that is about to be launched, in order // to make that child process start with the same profiler settings as // in the current process. The given function is invoked once for diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index a5c0d8b0dfc2..59be000e675a 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -3890,12 +3890,30 @@ void GetProfilerEnvVarsForChildProcess( std::string filtersString; const Vector& filters = ActivePS::Filters(lock); for (uint32_t i = 0; i < filters.length(); ++i) { - if (i != 0) { + filtersString += filters[i]; + if (i != filters.length() - 1) { filtersString += ","; } - filtersString += filters[i]; } aSetEnv("MOZ_PROFILER_STARTUP_FILTERS", filtersString.c_str()); + +#ifdef MOZ_BASE_PROFILER + // Blindly copy MOZ_BASE_PROFILER_STARTUP* env-vars. + auto copyEnv = [&](const char* aName) { + const char* env = getenv(aName); + if (!env) { + return; + } + aSetEnv(aName, env); + }; + copyEnv("MOZ_BASE_PROFILER_STARTUP"); + copyEnv("MOZ_BASE_PROFILER_STARTUP_ENTRIES"); + copyEnv("MOZ_BASE_PROFILER_STARTUP_DURATION"); + copyEnv("MOZ_BASE_PROFILER_STARTUP_INTERVAL"); + copyEnv("MOZ_BASE_PROFILER_STARTUP_FEATURES_BITFIELD"); + copyEnv("MOZ_BASE_PROFILER_STARTUP_FEATURES"); + copyEnv("MOZ_BASE_PROFILER_STARTUP_FILTERS"); +#endif } } // namespace mozilla @@ -4064,7 +4082,7 @@ static void locked_profiler_start(PSLockRef aLock, PowerOfTwo32 aCapacity, if (baseprofiler::profiler_is_active()) { // Note that we still hold the lock, so the sampler cannot run yet and // interact negatively with the still-active BaseProfiler sampler. - // Assume that Base Profiler is active because of MOZ_PROFILER_STARTUP. + // Assume that Base Profiler is active because of MOZ_BASE_PROFILER_STARTUP. // Capture the Base Profiler startup profile threads (if any). baseprofile = baseprofiler::profiler_get_profile( /* aSinceTime */ 0, /* aIsShuttingDown */ false,