Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: shell/android/main.cc

Issue 1067023003: Add shell::Tracer object and wire up to --trace-startup on Android (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: review comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « shell/BUILD.gn ('k') | shell/desktop/main.cc » ('j') | shell/tracer.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: shell/android/main.cc
diff --git a/shell/android/main.cc b/shell/android/main.cc
index aa26a13086d497f86368728544981a546fbd3e0f..8b643ec180c1cbdd98903454752f1fb009f6017c 100644
--- a/shell/android/main.cc
+++ b/shell/android/main.cc
@@ -19,6 +19,7 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/simple_thread.h"
+#include "base/trace_event/trace_event.h"
#include "jni/ShellMain_jni.h"
#include "mojo/common/message_pump_mojo.h"
#include "shell/android/android_handler_loader.h"
@@ -29,6 +30,8 @@
#include "shell/command_line_util.h"
#include "shell/context.h"
#include "shell/init.h"
+#include "shell/switches.h"
+#include "shell/tracer.h"
#include "ui/gl/gl_surface_egl.h"
using base::LazyInstance;
@@ -69,7 +72,7 @@ LazyInstance<scoped_ptr<MojoShellRunner>> g_shell_runner =
LazyInstance<scoped_ptr<base::DelegateSimpleThread>> g_shell_thread =
LAZY_INSTANCE_INITIALIZER;
-LazyInstance<base::android::ScopedJavaGlobalRef<jobject>> g_main_activiy =
+LazyInstance<base::android::ScopedJavaGlobalRef<jobject>> g_main_activity =
LAZY_INSTANCE_INITIALIZER;
void ConfigureAndroidServices(Context* context) {
@@ -97,7 +100,7 @@ void QuitShellThread() {
g_shell_thread.Get()->Join();
g_shell_thread.Pointer()->reset();
Java_ShellMain_finishActivity(base::android::AttachCurrentThread(),
- g_main_activiy.Get().obj());
+ g_main_activity.Get().obj());
exit(0);
}
@@ -145,13 +148,12 @@ static void Init(JNIEnv* env,
jobjectArray jparameters,
jstring j_local_apps_directory,
jstring j_tmp_dir) {
- g_main_activiy.Get().Reset(env, activity);
+ g_main_activity.Get().Reset(env, activity);
+ std::string tmp_dir = base::android::ConvertJavaStringToUTF8(env, j_tmp_dir);
// Setting the TMPDIR environment variable so that applications can use it.
// TODO(qsr) We will need our subprocesses to inherit this.
- int return_value =
- setenv("TMPDIR",
- base::android::ConvertJavaStringToUTF8(env, j_tmp_dir).c_str(), 1);
+ int return_value = setenv("TMPDIR", tmp_dir.c_str(), 1);
DCHECK_EQ(return_value, 0);
base::android::ScopedJavaLocalRef<jobject> scoped_activity(env, activity);
@@ -163,7 +165,13 @@ static void Init(JNIEnv* env,
base::android::AppendJavaStringArrayToStringVector(env, jparameters,
&parameters);
base::CommandLine::Init(0, nullptr);
- base::CommandLine::ForCurrentProcess()->InitFromArgv(parameters);
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ command_line->InitFromArgv(parameters);
+ Tracer tracer;
+ bool trace_startup = command_line->HasSwitch(switches::kTraceStartup);
+ if (trace_startup)
+ tracer.Start(command_line->GetSwitchValueASCII(switches::kTraceStartup));
+
g_shell_runner.Get().reset(new MojoShellRunner(parameters));
InitializeLogging();
@@ -181,6 +189,14 @@ static void Init(JNIEnv* env,
g_java_message_loop.Get().reset(new base::MessageLoopForUI);
base::MessageLoopForUI::current()->Start();
+ if (trace_startup) {
+ g_java_message_loop.Get()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&Tracer::StopAndFlushToFile, base::Unretained(&tracer),
qsr 2015/04/08 08:55:57 I am missing something here. tracer is a stack var
+ tmp_dir + "/mojo_shell.trace"),
+ base::TimeDelta::FromSeconds(5));
+ }
+
// TODO(abarth): At which point should we switch to cross-platform
// initialization?
« no previous file with comments | « shell/BUILD.gn ('k') | shell/desktop/main.cc » ('j') | shell/tracer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698