forked from mirrors/gecko-dev
Bug 1749498 - PrintUsage doesn't exit anymore, exits are done explicitly - r=canaltinova
`PrintUsageThenExit(code)` was supposed to exit when `code` was not zero, but: - The name didn't reflect that, so it was confusing that `PrintUsageThenExit(0)` would *not* exit. - The implementation in the Base Profiler exited anyway! This caused issues with some legacy code that still used the now-removed "threads" feature. This patch renames the function to just `PrintUsage()` and never exits, leaving the caller to invoke `exit(code)` as needed -- with the added benefit that it's possible to exit with a zero code, useful in cases where an exit is not actually an error. Differential Revision: https://phabricator.services.mozilla.com/D135666
This commit is contained in:
parent
d562d1fa70
commit
67edebb322
2 changed files with 32 additions and 26 deletions
|
|
@ -1985,7 +1985,7 @@ static char FeatureCategory(uint32_t aFeature) {
|
||||||
return 'x';
|
return 'x';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PrintUsageThenExit(int aExitCode) {
|
static void PrintUsage() {
|
||||||
PrintToConsole(
|
PrintToConsole(
|
||||||
"\n"
|
"\n"
|
||||||
"Profiler environment variable usage:\n"
|
"Profiler environment variable usage:\n"
|
||||||
|
|
@ -2088,8 +2088,6 @@ static void PrintUsageThenExit(int aExitCode) {
|
||||||
"does not support"
|
"does not support"
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
exit(aExitCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -2461,8 +2459,8 @@ static uint32_t ParseFeature(const char* aFeature, bool aIsStartup) {
|
||||||
#undef PARSE_FEATURE_BIT
|
#undef PARSE_FEATURE_BIT
|
||||||
|
|
||||||
PrintToConsole("\nUnrecognized feature \"%s\".\n\n", aFeature);
|
PrintToConsole("\nUnrecognized feature \"%s\".\n\n", aFeature);
|
||||||
// Since we may have an old feature we don't implement anymore, don't exit
|
// Since we may have an old feature we don't implement anymore, don't exit.
|
||||||
PrintUsageThenExit(0);
|
PrintUsage();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2576,7 +2574,8 @@ void profiler_init(void* aStackTop) {
|
||||||
MOZ_RELEASE_ASSERT(!CorePS::Exists());
|
MOZ_RELEASE_ASSERT(!CorePS::Exists());
|
||||||
|
|
||||||
if (getenv("MOZ_BASE_PROFILER_HELP")) {
|
if (getenv("MOZ_BASE_PROFILER_HELP")) {
|
||||||
PrintUsageThenExit(0); // terminates execution
|
PrintUsage();
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedLibraryInfo::Initialize();
|
SharedLibraryInfo::Initialize();
|
||||||
|
|
@ -2652,7 +2651,8 @@ void profiler_init(void* aStackTop) {
|
||||||
PrintToConsole(
|
PrintToConsole(
|
||||||
"- MOZ_PROFILER_STARTUP_ENTRIES unit must be one of the "
|
"- MOZ_PROFILER_STARTUP_ENTRIES unit must be one of the "
|
||||||
"following: KB, KiB, MB, MiB, GB, GiB");
|
"following: KB, KiB, MB, MiB, GB, GiB");
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// `long` could be 32 or 64 bits, so we force a 64-bit comparison with
|
// `long` could be 32 or 64 bits, so we force a 64-bit comparison with
|
||||||
|
|
@ -2667,7 +2667,8 @@ void profiler_init(void* aStackTop) {
|
||||||
} else {
|
} else {
|
||||||
PrintToConsole("- MOZ_PROFILER_STARTUP_ENTRIES not a valid integer: %s",
|
PrintToConsole("- MOZ_PROFILER_STARTUP_ENTRIES not a valid integer: %s",
|
||||||
startupCapacity);
|
startupCapacity);
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2685,7 +2686,8 @@ void profiler_init(void* aStackTop) {
|
||||||
} else {
|
} else {
|
||||||
PrintToConsole("- MOZ_PROFILER_STARTUP_DURATION not a valid float: %s",
|
PrintToConsole("- MOZ_PROFILER_STARTUP_DURATION not a valid float: %s",
|
||||||
startupDuration);
|
startupDuration);
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2701,7 +2703,8 @@ void profiler_init(void* aStackTop) {
|
||||||
} else {
|
} else {
|
||||||
PrintToConsole("- MOZ_PROFILER_STARTUP_INTERVAL not a valid float: %s",
|
PrintToConsole("- MOZ_PROFILER_STARTUP_INTERVAL not a valid float: %s",
|
||||||
startupInterval);
|
startupInterval);
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2718,7 +2721,8 @@ void profiler_init(void* aStackTop) {
|
||||||
PrintToConsole(
|
PrintToConsole(
|
||||||
"- MOZ_PROFILER_STARTUP_FEATURES_BITFIELD not a valid integer: %s",
|
"- MOZ_PROFILER_STARTUP_FEATURES_BITFIELD not a valid integer: %s",
|
||||||
startupFeaturesBitfield);
|
startupFeaturesBitfield);
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const char* startupFeatures = getenv("MOZ_PROFILER_STARTUP_FEATURES");
|
const char* startupFeatures = getenv("MOZ_PROFILER_STARTUP_FEATURES");
|
||||||
|
|
|
||||||
|
|
@ -3138,8 +3138,7 @@ static char FeatureCategory(uint32_t aFeature) {
|
||||||
return 'x';
|
return 'x';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Doesn't exist if aExitCode is 0
|
static void PrintUsage() {
|
||||||
static void PrintUsageThenExit(int aExitCode) {
|
|
||||||
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
|
|
@ -3243,10 +3242,6 @@ static void PrintUsageThenExit(int aExitCode) {
|
||||||
"does not support"
|
"does not support"
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
if (aExitCode != 0) {
|
|
||||||
exit(aExitCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -4497,8 +4492,8 @@ static uint32_t ParseFeature(const char* aFeature, bool aIsStartup) {
|
||||||
#undef PARSE_FEATURE_BIT
|
#undef PARSE_FEATURE_BIT
|
||||||
|
|
||||||
printf("\nUnrecognized feature \"%s\".\n\n", aFeature);
|
printf("\nUnrecognized feature \"%s\".\n\n", aFeature);
|
||||||
// Since we may have an old feature we don't implement anymore, don't exit
|
// Since we may have an old feature we don't implement anymore, don't exit.
|
||||||
PrintUsageThenExit(0);
|
PrintUsage();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4682,7 +4677,8 @@ void profiler_init(void* aStackTop) {
|
||||||
MOZ_RELEASE_ASSERT(!CorePS::Exists());
|
MOZ_RELEASE_ASSERT(!CorePS::Exists());
|
||||||
|
|
||||||
if (getenv("MOZ_PROFILER_HELP")) {
|
if (getenv("MOZ_PROFILER_HELP")) {
|
||||||
PrintUsageThenExit(1); // terminates execution
|
PrintUsage();
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedLibraryInfo::Initialize();
|
SharedLibraryInfo::Initialize();
|
||||||
|
|
@ -4769,7 +4765,8 @@ void profiler_init(void* aStackTop) {
|
||||||
} else if (!sizeSuffix.empty()) {
|
} else if (!sizeSuffix.empty()) {
|
||||||
LOG("- MOZ_PROFILER_STARTUP_ENTRIES unit must be one of the "
|
LOG("- MOZ_PROFILER_STARTUP_ENTRIES unit must be one of the "
|
||||||
"following: KB, KiB, MB, MiB, GB, GiB");
|
"following: KB, KiB, MB, MiB, GB, GiB");
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// `long` could be 32 or 64 bits, so we force a 64-bit comparison with
|
// `long` could be 32 or 64 bits, so we force a 64-bit comparison with
|
||||||
|
|
@ -4784,7 +4781,8 @@ void profiler_init(void* aStackTop) {
|
||||||
} else {
|
} else {
|
||||||
LOG("- MOZ_PROFILER_STARTUP_ENTRIES not a valid integer: %s",
|
LOG("- MOZ_PROFILER_STARTUP_ENTRIES not a valid integer: %s",
|
||||||
startupCapacity);
|
startupCapacity);
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4800,7 +4798,8 @@ void profiler_init(void* aStackTop) {
|
||||||
} else {
|
} else {
|
||||||
LOG("- MOZ_PROFILER_STARTUP_DURATION not a valid float: %s",
|
LOG("- MOZ_PROFILER_STARTUP_DURATION not a valid float: %s",
|
||||||
startupDuration);
|
startupDuration);
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4813,7 +4812,8 @@ void profiler_init(void* aStackTop) {
|
||||||
} else {
|
} else {
|
||||||
LOG("- MOZ_PROFILER_STARTUP_INTERVAL not a valid float: %s",
|
LOG("- MOZ_PROFILER_STARTUP_INTERVAL not a valid float: %s",
|
||||||
startupInterval);
|
startupInterval);
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4829,7 +4829,8 @@ void profiler_init(void* aStackTop) {
|
||||||
} else {
|
} else {
|
||||||
LOG("- MOZ_PROFILER_STARTUP_FEATURES_BITFIELD not a valid integer: %s",
|
LOG("- MOZ_PROFILER_STARTUP_FEATURES_BITFIELD not a valid integer: %s",
|
||||||
startupFeaturesBitfield);
|
startupFeaturesBitfield);
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const char* startupFeatures = getenv("MOZ_PROFILER_STARTUP_FEATURES");
|
const char* startupFeatures = getenv("MOZ_PROFILER_STARTUP_FEATURES");
|
||||||
|
|
@ -4863,7 +4864,8 @@ void profiler_init(void* aStackTop) {
|
||||||
LOG("- MOZ_PROFILER_STARTUP_ACTIVE_TAB_ID not a valid "
|
LOG("- MOZ_PROFILER_STARTUP_ACTIVE_TAB_ID not a valid "
|
||||||
"uint64_t: %s",
|
"uint64_t: %s",
|
||||||
startupActiveTabID);
|
startupActiveTabID);
|
||||||
PrintUsageThenExit(1);
|
PrintUsage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue