0

Set better utility thread names

Thread names are useful when debugging for identifying which process is
which. While investigating some test failures I noticed that the
CrUtilityMain threads had the same name for all the different types of
utility processes.

This uses the kUtilitySubType parameter to give CrUtilityMain threads
names like audio.CrUtilityMain.

See also crrev.com/c/4127916 for test launcher thread naming.

Change-Id: I545cf22134effe415c89e4d3a97f70455c246d4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4129799
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Auto-Submit: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096056}
This commit is contained in:
Bruce Dawson
2023-01-24 07:58:53 +00:00
committed by Chromium LUCI CQ
parent 7d74066a94
commit 4977fb666b

@ -103,6 +103,18 @@ bool ShouldUseAmdGpuPolicy(sandbox::mojom::Sandbox sandbox_type) {
}
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void SetUtilityThreadName(const std::string utility_sub_type) {
// Typical utility sub-types are audio.mojom.AudioService or
// proxy_resolver.mojom.ProxyResolverFactory. Using the full sub-type as part
// of the thread name is too verbose so we take the text in front of the first
// period and use that as a prefix. This give us thread names like
// audio.CrUtilityMain and proxy_resolver.CrUtilityMain. If there is no period
// then the entire utility_sub_type string will be put in front.
auto first_period = utility_sub_type.find('.');
base::PlatformThread::SetName(
(utility_sub_type.substr(0, first_period) + ".CrUtilityMain").c_str());
}
} // namespace
// Mainline routine for running as the utility process.
@ -144,11 +156,11 @@ int UtilityMain(MainFunctionParams parameters) {
// The main task executor of the utility process.
base::SingleThreadTaskExecutor main_thread_task_executor(message_pump_type);
base::PlatformThread::SetName("CrUtilityMain");
const std::string utility_sub_type =
parameters.command_line->GetSwitchValueASCII(switches::kUtilitySubType);
SetUtilityThreadName(utility_sub_type);
if (parameters.command_line->HasSwitch(switches::kUtilityStartupDialog)) {
const std::string utility_sub_type =
parameters.command_line->GetSwitchValueASCII(switches::kUtilitySubType);
auto dialog_match = parameters.command_line->GetSwitchValueASCII(
switches::kUtilityStartupDialog);
if (dialog_match.empty() || dialog_match == utility_sub_type) {