Skip to content

Commit 131349f

Browse files
authored
Update flutter runner process name to reflect last running shell. (#5102)
1 parent ad9826c commit 131349f

3 files changed

Lines changed: 48 additions & 5 deletions

File tree

‎content_handler/application.cc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ Application::Application(
163163

164164
Application::~Application() = default;
165165

166+
const std::string& Application::GetDebugLabel() const {
167+
return debug_label_;
168+
}
169+
166170
void Application::AttemptVMLaunchWithCurrentSettings(
167171
const blink::Settings& settings) const {
168172
if (blink::DartVM::ForProcessIfInitialized()) {

‎content_handler/application.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Application final : public Engine::Delegate,
4949
// may be collected after.
5050
~Application();
5151

52+
const std::string& GetDebugLabel() const;
53+
5254
private:
5355
blink::Settings settings_;
5456
Delegate& delegate_;

‎content_handler/application_runner.cc‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,59 @@
44

55
#include "application_runner.h"
66

7+
#include <zircon/types.h>
8+
9+
#include <sstream>
710
#include <utility>
811

912
#include "flutter/lib/ui/text/font_collection.h"
1013
#include "fuchsia_font_manager.h"
11-
#include "third_party/skia/include/core/SkGraphics.h"
1214
#include "lib/icu_data/cpp/icu_data.h"
15+
#include "third_party/skia/include/core/SkGraphics.h"
1316

1417
namespace flutter {
1518

19+
static void SetProcessName(const std::string& process_name) {
20+
zx::process::self().set_property(ZX_PROP_NAME, process_name.c_str(),
21+
process_name.size());
22+
}
23+
24+
static void SetThreadName(const std::string& thread_name) {
25+
zx::thread::self().set_property(ZX_PROP_NAME, thread_name.c_str(),
26+
thread_name.size());
27+
}
28+
29+
static void SetProcessName(const std::string& label, size_t app_count) {
30+
// Format: "flutter.<label_truncated_to_fit>+<app_count>"
31+
// "flutter" in case of error.
32+
33+
const std::string prefix = "flutter.";
34+
const std::string suffix =
35+
app_count == 0 ? "" : "+" + std::to_string(app_count);
36+
37+
if ((prefix.size() + suffix.size()) > ZX_MAX_NAME_LEN) {
38+
SetProcessName("flutter");
39+
return;
40+
}
41+
42+
auto truncated_label =
43+
label.substr(0, ZX_MAX_NAME_LEN - 1 - (prefix.size() + suffix.size()));
44+
45+
SetProcessName(prefix + truncated_label + suffix);
46+
}
47+
1648
ApplicationRunner::ApplicationRunner(fxl::Closure on_termination_callback)
1749
: on_termination_callback_(std::move(on_termination_callback)),
1850
host_context_(component::ApplicationContext::CreateFromStartupInfo()) {
19-
2051
SkGraphics::Init();
2152

2253
SetupICU();
2354

2455
SetupGlobalFonts();
2556

26-
const std::string process_label = "flutter";
27-
zx::process::self().set_property(ZX_PROP_NAME, process_label.c_str(),
28-
process_label.size());
57+
SetProcessName("application_runner", 0);
58+
59+
SetThreadName("io.flutter.application_runner");
2960

3061
host_context_->outgoing_services()->AddService<component::ApplicationRunner>(
3162
std::bind(&ApplicationRunner::RegisterApplication, this,
@@ -55,6 +86,12 @@ void ApplicationRunner::StartApplication(
5586
std::move(startup_info), // startup info
5687
std::move(controller) // controller request
5788
);
89+
90+
// Update the process label so that "ps" will will list the last appication
91+
// started by the runner plus the count of applications hosted by this runner.
92+
SetProcessName(thread_application_pair.second->GetDebugLabel(),
93+
active_applications_.size());
94+
5895
active_applications_[thread_application_pair.second.get()] =
5996
std::move(thread_application_pair);
6097
}

0 commit comments

Comments
 (0)