Skip to content

Commit

Permalink
Update flutter runner process name to reflect last running shell. (fl…
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored Apr 26, 2018
1 parent ad9826c commit 131349f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions content_handler/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ Application::Application(

Application::~Application() = default;

const std::string& Application::GetDebugLabel() const {
return debug_label_;
}

void Application::AttemptVMLaunchWithCurrentSettings(
const blink::Settings& settings) const {
if (blink::DartVM::ForProcessIfInitialized()) {
Expand Down
2 changes: 2 additions & 0 deletions content_handler/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Application final : public Engine::Delegate,
// may be collected after.
~Application();

const std::string& GetDebugLabel() const;

private:
blink::Settings settings_;
Delegate& delegate_;
Expand Down
47 changes: 42 additions & 5 deletions content_handler/application_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,59 @@

#include "application_runner.h"

#include <zircon/types.h>

#include <sstream>
#include <utility>

#include "flutter/lib/ui/text/font_collection.h"
#include "fuchsia_font_manager.h"
#include "third_party/skia/include/core/SkGraphics.h"
#include "lib/icu_data/cpp/icu_data.h"
#include "third_party/skia/include/core/SkGraphics.h"

namespace flutter {

static void SetProcessName(const std::string& process_name) {
zx::process::self().set_property(ZX_PROP_NAME, process_name.c_str(),
process_name.size());
}

static void SetThreadName(const std::string& thread_name) {
zx::thread::self().set_property(ZX_PROP_NAME, thread_name.c_str(),
thread_name.size());
}

static void SetProcessName(const std::string& label, size_t app_count) {
// Format: "flutter.<label_truncated_to_fit>+<app_count>"
// "flutter" in case of error.

const std::string prefix = "flutter.";
const std::string suffix =
app_count == 0 ? "" : "+" + std::to_string(app_count);

if ((prefix.size() + suffix.size()) > ZX_MAX_NAME_LEN) {
SetProcessName("flutter");
return;
}

auto truncated_label =
label.substr(0, ZX_MAX_NAME_LEN - 1 - (prefix.size() + suffix.size()));

SetProcessName(prefix + truncated_label + suffix);
}

ApplicationRunner::ApplicationRunner(fxl::Closure on_termination_callback)
: on_termination_callback_(std::move(on_termination_callback)),
host_context_(component::ApplicationContext::CreateFromStartupInfo()) {

SkGraphics::Init();

SetupICU();

SetupGlobalFonts();

const std::string process_label = "flutter";
zx::process::self().set_property(ZX_PROP_NAME, process_label.c_str(),
process_label.size());
SetProcessName("application_runner", 0);

SetThreadName("io.flutter.application_runner");

host_context_->outgoing_services()->AddService<component::ApplicationRunner>(
std::bind(&ApplicationRunner::RegisterApplication, this,
Expand Down Expand Up @@ -55,6 +86,12 @@ void ApplicationRunner::StartApplication(
std::move(startup_info), // startup info
std::move(controller) // controller request
);

// Update the process label so that "ps" will will list the last appication
// started by the runner plus the count of applications hosted by this runner.
SetProcessName(thread_application_pair.second->GetDebugLabel(),
active_applications_.size());

active_applications_[thread_application_pair.second.get()] =
std::move(thread_application_pair);
}
Expand Down

0 comments on commit 131349f

Please sign in to comment.