Bug 1382910 - Add a MOZ_PROFILER_STARTUP_FEATURES_BITFIELD environment variable that lets you set the features as a number. r?njn
If set, MOZ_PROFILER_STARTUP_FEATURES_BITFIELD overrides the value set by
MOZ_PROFILER_STARTUP_FEATURES.
This means that we won't need to go through an intermediate string
representation when propagating profiler settings to a child process through
environment variables.
MozReview-Commit-ID: 49eTVMI21GJ
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -1632,19 +1632,25 @@ PrintUsageThenExit(int aExitCode)
" the profiler's circular buffer when the profiler is first started.\n"
" If unset, the platform default is used.\n"
"\n"
" MOZ_PROFILER_STARTUP_INTERVAL=<1..1000>\n"
" If MOZ_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=<Number>\n"
+ " If MOZ_PROFILER_STARTUP is set, specifies the profiling features, as\n"
+ " the integer value of the features bitfield.\n"
+ " If unset, the value from MOZ_PROFILER_STARTUP_FEATURES is used.\n"
+ "\n"
" MOZ_PROFILER_STARTUP_FEATURES=<Features>\n"
- " If MOZ_PROFILER_STARTUP is set, specifies the profiling features, as a\n"
- " comma-separated list of strings.\n"
+ " If MOZ_PROFILER_STARTUP is set, specifies the profiling features, as\n"
+ " a comma-separated list of strings.\n"
+ " Ignored if MOZ_PROFILER_STARTUP_FEATURES_BITFIELD is set.\n"
" If unset, the platform default is used.\n"
"\n"
" MOZ_PROFILER_STARTUP_FILTERS=<Filters>\n"
" If MOZ_PROFILER_STARTUP is set, specifies the thread filters, as a\n"
" comma-separated list of strings. A given thread will be sampled if any\n"
" of the filters is a case-insensitive substring of the thread name.\n"
" If unset, a default is used.\n"
"\n"
@@ -2213,24 +2219,38 @@ profiler_init(void* aStackTop)
interval = PR_strtod(startupInterval, nullptr);
if (errno == 0 && interval > 0.0 && interval <= 1000.0) {
LOG("- MOZ_PROFILER_STARTUP_INTERVAL = %f", interval);
} else {
PrintUsageThenExit(1);
}
}
- const char* startupFeatures = getenv("MOZ_PROFILER_STARTUP_FEATURES");
- if (startupFeatures) {
- UniquePtr<char[]> featureStringStorage;
- nsTArray<const char*> featureStringArray =
- SplitAtCommas(startupFeatures, featureStringStorage);
- features = ParseFeaturesFromStringArray(featureStringArray.Elements(),
- featureStringArray.Length());
- LOG("- MOZ_PROFILER_STARTUP_FEATURES = %d", features);
+ const char* startupFeaturesBitfield =
+ getenv("MOZ_PROFILER_STARTUP_FEATURES_BITFIELD");
+ if (startupFeaturesBitfield) {
+ errno = 0;
+ features = strtol(startupFeaturesBitfield, nullptr, 10);
+ if (errno == 0 && features != 0) {
+ LOG("- MOZ_PROFILER_STARTUP_FEATURES_BITFIELD = %d", features);
+ } else {
+ PrintUsageThenExit(1);
+ }
+ } else {
+ const char* startupFeatures = getenv("MOZ_PROFILER_STARTUP_FEATURES");
+ if (startupFeatures) {
+ // Interpret startupFeatures as a list of feature strings, separated by
+ // commas.
+ UniquePtr<char[]> featureStringStorage;
+ nsTArray<const char*> featureStringArray =
+ SplitAtCommas(startupFeatures, featureStringStorage);
+ features = ParseFeaturesFromStringArray(featureStringArray.Elements(),
+ featureStringArray.Length());
+ LOG("- MOZ_PROFILER_STARTUP_FEATURES = %d", features);
+ }
}
const char* startupFilters = getenv("MOZ_PROFILER_STARTUP_FILTERS");
if (startupFilters) {
filters = SplitAtCommas(startupFilters, filterStorage);
LOG("- MOZ_PROFILER_STARTUP_FILTERS = %s", startupFilters);
}