|
4 | 4 |
|
5 | 5 | #include "application_runner.h" |
6 | 6 |
|
| 7 | +#include <zircon/types.h> |
| 8 | + |
| 9 | +#include <sstream> |
7 | 10 | #include <utility> |
8 | 11 |
|
9 | 12 | #include "flutter/lib/ui/text/font_collection.h" |
10 | 13 | #include "fuchsia_font_manager.h" |
11 | | -#include "third_party/skia/include/core/SkGraphics.h" |
12 | 14 | #include "lib/icu_data/cpp/icu_data.h" |
| 15 | +#include "third_party/skia/include/core/SkGraphics.h" |
13 | 16 |
|
14 | 17 | namespace flutter { |
15 | 18 |
|
| 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 | + |
16 | 48 | ApplicationRunner::ApplicationRunner(fxl::Closure on_termination_callback) |
17 | 49 | : on_termination_callback_(std::move(on_termination_callback)), |
18 | 50 | host_context_(component::ApplicationContext::CreateFromStartupInfo()) { |
19 | | - |
20 | 51 | SkGraphics::Init(); |
21 | 52 |
|
22 | 53 | SetupICU(); |
23 | 54 |
|
24 | 55 | SetupGlobalFonts(); |
25 | 56 |
|
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"); |
29 | 60 |
|
30 | 61 | host_context_->outgoing_services()->AddService<component::ApplicationRunner>( |
31 | 62 | std::bind(&ApplicationRunner::RegisterApplication, this, |
@@ -55,6 +86,12 @@ void ApplicationRunner::StartApplication( |
55 | 86 | std::move(startup_info), // startup info |
56 | 87 | std::move(controller) // controller request |
57 | 88 | ); |
| 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 | + |
58 | 95 | active_applications_[thread_application_pair.second.get()] = |
59 | 96 | std::move(thread_application_pair); |
60 | 97 | } |
|
0 commit comments