Commit f73fe4b8 authored by Albert J. Wong's avatar Albert J. Wong Committed by Commit Bot

memlog: Trace Upload threading fix; android ui.

There were some File operation threading violations in the trace
uploading that were not noticeable in release mode. This code fixes that
in android.

Also, enables the memory-internals UI in android.

Bug: 751321
Change-Id: Ic6bd47ba1d61fa601613003c2f644da458450842
Reviewed-on: https://chromium-review.googlesource.com/662017
Commit-Queue: Albert J. Wong <ajwong@chromium.org>
Reviewed-by: default avatarBrett Wilson <brettw@chromium.org>
Reviewed-by: default avatarAlbert J. Wong <ajwong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#502045}
parent 706801fd
......@@ -66,15 +66,8 @@ void OnTraceUploadComplete(TraceCrashServiceUploader* uploader,
bool success,
const std::string& feedback);
void UploadTraceToCrashServer(base::FilePath file_path,
void UploadTraceToCrashServer(std::string file_contents,
std::string trigger_name) {
std::string file_contents;
if (!base::ReadFileToStringWithMaxSize(file_path, &file_contents,
kMaxTraceSizeUploadInBytes)) {
DLOG(ERROR) << "Cannot read trace file contents.";
return;
}
base::Value rules_list(base::Value::Type::LIST);
base::Value rule(base::Value::Type::DICTIONARY);
rule.SetKey("rule", base::Value("MEMLOG"));
......@@ -100,6 +93,23 @@ void UploadTraceToCrashServer(base::FilePath file_path,
base::Bind(&OnTraceUploadComplete, base::Owned(uploader)));
}
void ReadTraceForUpload(base::FilePath file_path, std::string trigger_name) {
std::string file_contents;
bool success = base::ReadFileToStringWithMaxSize(file_path, &file_contents,
kMaxTraceSizeUploadInBytes);
base::DeleteFile(file_path, false);
if (!success) {
DLOG(ERROR) << "Cannot read trace file contents.";
return;
}
content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI)
->PostTask(FROM_HERE, base::BindOnce(&UploadTraceToCrashServer,
std::move(file_contents),
std::move(trigger_name)));
}
void OnTraceUploadComplete(TraceCrashServiceUploader* uploader,
bool success,
const std::string& feedback) {
......@@ -333,7 +343,7 @@ void ProfilingProcessHost::ConfigureBackgroundProfilingTriggers() {
}
void ProfilingProcessHost::RequestProcessDump(base::ProcessId pid,
const base::FilePath& dest,
base::FilePath dest,
base::OnceClosure done) {
if (!connector_) {
DLOG(ERROR)
......@@ -345,8 +355,8 @@ void ProfilingProcessHost::RequestProcessDump(base::ProcessId pid,
base::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()},
base::BindOnce(&ProfilingProcessHost::GetOutputFileOnBlockingThread,
base::Unretained(this), pid, dest, kNoTriggerName,
kNoUpload, std::move(done)));
base::Unretained(this), pid, std::move(dest),
kNoTriggerName, kNoUpload, std::move(done)));
}
void ProfilingProcessHost::RequestProcessReport(base::ProcessId pid,
......@@ -357,17 +367,11 @@ void ProfilingProcessHost::RequestProcessReport(base::ProcessId pid,
return;
}
base::FilePath output_path;
if (!CreateTemporaryFile(&output_path)) {
DLOG(ERROR) << "Cannot create temporary file for memory dump.";
return;
}
const bool kUpload = true;
base::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::BACKGROUND, base::MayBlock()},
base::BindOnce(&ProfilingProcessHost::GetOutputFileOnBlockingThread,
base::Unretained(this), pid, std::move(output_path),
base::Unretained(this), pid, base::FilePath(),
std::move(trigger_name), kUpload, base::OnceClosure()));
}
......@@ -409,10 +413,19 @@ void ProfilingProcessHost::LaunchAsService() {
void ProfilingProcessHost::GetOutputFileOnBlockingThread(
base::ProcessId pid,
const base::FilePath& dest,
base::FilePath dest,
std::string trigger_name,
bool upload,
base::OnceClosure done) {
base::ScopedClosureRunner done_runner(std::move(done));
if (upload) {
DCHECK(dest.empty());
if (!CreateTemporaryFile(&dest)) {
DLOG(ERROR) << "Cannot create temporary file for memory dump.";
return;
}
}
base::File file(dest,
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
content::BrowserThread::PostTask(
......@@ -420,7 +433,7 @@ void ProfilingProcessHost::GetOutputFileOnBlockingThread(
base::BindOnce(&ProfilingProcessHost::HandleDumpProcessOnIOThread,
base::Unretained(this), pid, std::move(dest),
std::move(file), std::move(trigger_name), upload,
std::move(done)));
done_runner.Release()));
}
void ProfilingProcessHost::HandleDumpProcessOnIOThread(base::ProcessId pid,
......@@ -454,13 +467,10 @@ void ProfilingProcessHost::OnProcessDumpComplete(base::FilePath file_path,
}
if (upload) {
UploadTraceToCrashServer(file_path, trigger_name);
// Uploaded file is a temporary file and must be deleted.
base::PostTaskWithTraits(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
base::BindOnce(base::IgnoreResult(&base::DeleteFile), file_path,
false));
base::BindOnce(&ReadTraceForUpload, std::move(file_path),
std::move(trigger_name)));
}
}
......
......@@ -81,7 +81,7 @@ class ProfilingProcessHost : public content::BrowserChildProcessObserver,
// Sends a message to the profiling process that it dump the given process'
// memory data to the given file.
void RequestProcessDump(base::ProcessId pid,
const base::FilePath& dest,
base::FilePath dest,
base::OnceClosure done);
// Sends a message to the profiling process that it report the given process'
......@@ -134,7 +134,7 @@ class ProfilingProcessHost : public content::BrowserChildProcessObserver,
mojo::ScopedHandle handle);
void GetOutputFileOnBlockingThread(base::ProcessId pid,
const base::FilePath& dest,
base::FilePath dest,
std::string trigger_name,
bool upload,
base::OnceClosure done);
......
......@@ -344,6 +344,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<InvalidationsUI>;
if (url.host_piece() == chrome::kChromeUILocalStateHost)
return &NewWebUI<LocalStateUI>;
if (url.host_piece() == chrome::kChromeUIMemoryInternalsHost)
return &NewWebUI<MemoryInternalsUI>;
if (url.host_piece() == chrome::kChromeUINetExportHost)
return &NewWebUI<NetExportUI>;
if (url.host_piece() == chrome::kChromeUINetInternalsHost)
......@@ -414,8 +416,6 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
// Identity API is not available on Android.
if (url.host_piece() == chrome::kChromeUIIdentityInternalsHost)
return &NewWebUI<IdentityInternalsUI>;
if (url.host_piece() == chrome::kChromeUIMemoryInternalsHost)
return &NewWebUI<MemoryInternalsUI>;
if (url.host_piece() == chrome::kChromeUINewTabHost)
return &NewWebUI<NewTabUI>;
// Settings are implemented with native UI elements on Android.
......
......@@ -183,7 +183,7 @@ void MemoryInternalsDOMHandler::HandleDumpProcess(const base::ListValue* args) {
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
base::FilePath output_path = user_data_dir.Append(default_file);
profiling::ProfilingProcessHost::GetInstance()->RequestProcessDump(
pid, output_path, base::OnceClosure());
pid, std::move(output_path), base::OnceClosure());
(void)web_ui_; // Avoid warning about not using private web_ui_ member.
#else
if (select_file_dialog_)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment