Commit f3d4c691 authored by Willie Koomson's avatar Willie Koomson Committed by Commit Bot

Reland "Refactor dependency on memory_instrumentation.mojom out of process.mojom"

This is a reland of 9e12e07d

Original change's description:
> Refactor dependency on memory_instrumentation.mojom out of process.mojom
>
> Deprecates use of memory_instrumentation.mojom.GlobalMemoryDump struct
> in process.mojom and ArcProcessService. Uses new struct ArcMemoryDump
> instead.
>
> manager for Android memory footprint
>
> Bug: b:139190852
> Test: Build cheet_x86 and flash betty-arcnext, check Chrome OS task
> Change-Id: Ib21dfcf8ab7c23dfd60573341dfdddbcb744f166
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1749456
> Commit-Queue: Willie Koomson <wvk@google.com>
> Reviewed-by: Scott Violet <sky@chromium.org>
> Reviewed-by: Dominick Ng <dominickn@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#688212}

Bug: b:139190852
Change-Id: I956b640fae3127e65c148ae40c474142ad685ee8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761292Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Willie Koomson <wvk@google.com>
Cr-Commit-Position: refs/heads/master@{#688580}
parent 97a41382
......@@ -34,8 +34,6 @@
#include "components/arc/arc_util.h"
#include "components/arc/session/arc_bridge_service.h"
#include "content/public/browser/browser_thread.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/global_memory_dump.h"
#include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h"
namespace arc {
......@@ -224,20 +222,18 @@ std::vector<ArcProcess> UpdateAndReturnProcessList(
return FilterProcessList(pid_map, std::move(processes));
}
std::unique_ptr<memory_instrumentation::GlobalMemoryDump>
UpdateAndReturnMemoryInfo(
std::vector<mojom::ArcMemoryDumpPtr> UpdateAndReturnMemoryInfo(
scoped_refptr<ArcProcessService::NSPidToPidMap> nspid_map,
memory_instrumentation::mojom::GlobalMemoryDumpPtr dump) {
std::vector<mojom::ArcMemoryDumpPtr> process_dumps) {
if (!arc::IsArcVmEnabled()) {
ArcProcessService::NSPidToPidMap& pid_map = *nspid_map;
// Cleanup dead processes in pid_map
// TODO(wvk) should we be cleaning dead processes here too ?
base::flat_set<ProcessId> nspid_to_remove;
for (const auto& entry : pid_map)
nspid_to_remove.insert(entry.first);
bool unmapped_nspid = false;
for (const auto& proc : dump->process_dumps) {
for (const auto& proc : process_dumps) {
// erase() returns 0 if couldn't find the key (new process)
if (nspid_to_remove.erase(proc->pid) == 0) {
pid_map[proc->pid] = base::kNullProcessId;
......@@ -251,14 +247,14 @@ UpdateAndReturnMemoryInfo(
UpdateNspidToPidMap(nspid_map);
// Return memory info only for processes that have a mapping nspid->pid
for (auto& proc : dump->process_dumps) {
for (auto& proc : process_dumps) {
auto it = pid_map.find(proc->pid);
proc->pid = it == pid_map.end() ? kNullProcessId : it->second;
}
base::EraseIf(dump->process_dumps,
base::EraseIf(process_dumps,
[](const auto& proc) { return proc->pid == kNullProcessId; });
}
return memory_instrumentation::GlobalMemoryDump::MoveFrom(std::move(dump));
return process_dumps;
}
void Reset(scoped_refptr<ArcProcessService::NSPidToPidMap> pid_map) {
......@@ -399,12 +395,12 @@ void ArcProcessService::OnReceiveProcessList(
void ArcProcessService::OnReceiveMemoryInfo(
RequestMemoryInfoCallback callback,
memory_instrumentation::mojom::GlobalMemoryDumpPtr dump) {
std::vector<mojom::ArcMemoryDumpPtr> process_dumps) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
base::PostTaskAndReplyWithResult(
task_runner_.get(), FROM_HERE,
base::BindOnce(&UpdateAndReturnMemoryInfo, nspid_to_pid_,
std::move(dump)),
std::move(process_dumps)),
std::move(callback));
}
......
......@@ -72,8 +72,8 @@ class ArcProcessService : public KeyedService,
using OptionalArcProcessList = base::Optional<std::vector<ArcProcess>>;
using RequestProcessListCallback =
base::OnceCallback<void(OptionalArcProcessList)>;
using RequestMemoryInfoCallback = base::OnceCallback<void(
std::unique_ptr<memory_instrumentation::GlobalMemoryDump>)>;
using RequestMemoryInfoCallback =
base::OnceCallback<void(std::vector<mojom::ArcMemoryDumpPtr>)>;
ArcProcessService(content::BrowserContext* context,
ArcBridgeService* bridge_service);
......@@ -124,9 +124,8 @@ class ArcProcessService : public KeyedService,
void OnReceiveProcessList(
RequestProcessListCallback callback,
std::vector<mojom::RunningAppProcessInfoPtr> processes);
void OnReceiveMemoryInfo(
RequestMemoryInfoCallback callback,
memory_instrumentation::mojom::GlobalMemoryDumpPtr dump);
void OnReceiveMemoryInfo(RequestMemoryInfoCallback callback,
std::vector<mojom::ArcMemoryDumpPtr> process_dumps);
void OnGetSystemProcessList(RequestMemoryInfoCallback callback,
std::vector<ArcProcess> processes);
// ConnectionObserver<mojom::ProcessInstance> overrides.
......
......@@ -71,7 +71,7 @@ void ArcSharedSampler::Refresh() {
void ArcSharedSampler::OnReceiveMemoryDump(
int type,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump) {
std::vector<arc::mojom::ArcMemoryDumpPtr> process_dump) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
pending_memory_dump_types_ &= ~type;
......@@ -80,14 +80,11 @@ void ArcSharedSampler::OnReceiveMemoryDump(
else
last_system_refresh = base::Time::Now();
if (!dump)
return;
for (const auto& pmd : dump->process_dumps()) {
auto it = callbacks_.find(pmd.pid());
for (const auto& proc : process_dump) {
auto it = callbacks_.find(proc->pid);
if (it == callbacks_.end())
continue;
const MemoryFootprintBytes result =
pmd.os_dump().private_footprint_kb * 1024;
const MemoryFootprintBytes result = proc->private_footprint_kb * 1024;
it->second.Run(base::make_optional<MemoryFootprintBytes>(result));
}
}
......
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_TASK_MANAGER_SAMPLING_ARC_SHARED_SAMPLER_H_
#include <stdint.h>
#include <map>
#include "base/callback.h"
......@@ -13,7 +14,7 @@
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/process/process_handle.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"
#include "components/arc/mojom/process.mojom.h"
namespace task_manager {
......@@ -45,7 +46,7 @@ class ArcSharedSampler {
// Called when ArcProcessService returns memory dump.
void OnReceiveMemoryDump(
int dump_type,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);
std::vector<arc::mojom::ArcMemoryDumpPtr> process_dumps);
// Holds callbacks registered by TaskGroup objects.
CallbacksMap callbacks_;
......
......@@ -17,12 +17,15 @@
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/task_manager/providers/task.h"
#include "chrome/browser/task_manager/sampling/arc_shared_sampler.h"
#include "chrome/browser/task_manager/sampling/shared_sampler.h"
#include "chrome/browser/task_manager/sampling/task_group_sampler.h"
#include "chrome/browser/task_manager/task_manager_observer.h"
#include "components/nacl/common/buildflags.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/task_manager/sampling/arc_shared_sampler.h"
#endif // defined(OS_CHROMEOS)
namespace gpu {
struct VideoMemoryUsageStats;
}
......
......@@ -20,13 +20,16 @@
#include "base/time/time.h"
#include "chrome/browser/task_manager/providers/task_provider.h"
#include "chrome/browser/task_manager/providers/task_provider_observer.h"
#include "chrome/browser/task_manager/sampling/arc_shared_sampler.h"
#include "chrome/browser/task_manager/sampling/task_group.h"
#include "chrome/browser/task_manager/task_manager_interface.h"
#include "gpu/ipc/common/memory_stats.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/global_memory_dump.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/task_manager/sampling/arc_shared_sampler.h"
#endif // defined(OS_CHROMEOS)
namespace task_manager {
class SharedSampler;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Next MinVersion: 8
// Next MinVersion: 9
module arc.mojom;
......@@ -109,7 +109,19 @@ struct RunningAppProcessInfo {
int64 last_activity_time;
};
// Next Method ID: 8
// Describes the memory usage of an ARC process.
struct ArcMemoryDump {
// PID (within ARC's PID namespace) of the process.
uint32 pid;
// Resident Set Size (RSS) in kilobytes
uint32 resident_set_kb = 0;
// Private footprint (RSS + swap usage) in kilobytes
uint32 private_footprint_kb = 0;
};
// Next Method ID: 10
interface ProcessInstance {
// Requests ARC instance to kill a process.
[MinVersion=1]
......@@ -120,11 +132,22 @@ interface ProcessInstance {
// Requests memory usage dumps for all ARC application processes.
[MinVersion=7]
RequestApplicationProcessMemoryInfo@6()
RequestApplicationProcessMemoryInfoDeprecated@6()
=> (memory_instrumentation.mojom.GlobalMemoryDump dump);
// Requests memory usage dumps for all ARC system processes.
[MinVersion=7]
RequestSystemProcessMemoryInfo@7(array<uint32> nspids)
RequestSystemProcessMemoryInfoDeprecated@7(array<uint32> nspids)
=> (memory_instrumentation.mojom.GlobalMemoryDump dump);
// Requests memory usage dumps for all ARC application processes.
[MinVersion=8]
RequestApplicationProcessMemoryInfo@8()
=> (array<ArcMemoryDump> process_dumps);
// Requests memory usage dumps for all ARC system processes.
[MinVersion=8]
RequestSystemProcessMemoryInfo@9(array<uint32> nspids)
=> (array<ArcMemoryDump> process_dumps);
};
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