Commit 468dc2e7 authored by Paul Moy's avatar Paul Moy Committed by Commit Bot

ServiceConnection: Add ProbeProcessInfo method

Add a new Mojo method to cros_healthd's probe interface for
retrieving information about a particular process. Plumb this new
method through the ServiceConnection object, and add support to the
fake for testing.

Bug: chromium:1102518
Change-Id: I73d6377565c0b5f45fe9b85f585093cc972f80b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2305549Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Paul Moy <pmoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790011}
parent 4f133fc9
......@@ -62,6 +62,11 @@ void FakeCrosHealthdClient::SetProbeTelemetryInfoResponseForTesting(
fake_service_.SetProbeTelemetryInfoResponseForTesting(info);
}
void FakeCrosHealthdClient::SetProbeProcessInfoResponseForTesting(
mojom::ProcessResultPtr& result) {
fake_service_.SetProbeProcessInfoResponseForTesting(result);
}
void FakeCrosHealthdClient::EmitAcInsertedEventForTesting() {
// Flush the receiver, so any pending observers are registered before the
// event is emitted.
......
......@@ -54,6 +54,10 @@ class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient
// ProbeTelemetryInfo IPCs received.
void SetProbeTelemetryInfoResponseForTesting(mojom::TelemetryInfoPtr& info);
// Set the ProcessResultPtr that will be used in the response to any
// ProbeProcessInfo IPCs received.
void SetProbeProcessInfoResponseForTesting(mojom::ProcessResultPtr& result);
// Calls the power event OnAcInserted on all registered power observers.
void EmitAcInsertedEventForTesting();
......
......@@ -148,6 +148,12 @@ void FakeCrosHealthdService::ProbeTelemetryInfo(
std::move(callback).Run(telemetry_response_info_.Clone());
}
void FakeCrosHealthdService::ProbeProcessInfo(
const uint32_t process_id,
ProbeProcessInfoCallback callback) {
std::move(callback).Run(process_response_.Clone());
}
void FakeCrosHealthdService::SetAvailableRoutinesForTesting(
const std::vector<mojom::DiagnosticRoutineEnum>& available_routines) {
available_routines_ = available_routines;
......@@ -168,6 +174,11 @@ void FakeCrosHealthdService::SetProbeTelemetryInfoResponseForTesting(
telemetry_response_info_.Swap(&response_info);
}
void FakeCrosHealthdService::SetProbeProcessInfoResponseForTesting(
mojom::ProcessResultPtr& result) {
process_response_.Swap(&result);
}
void FakeCrosHealthdService::EmitAcInsertedEventForTesting() {
for (auto& observer : power_observers_)
observer->OnAcInserted();
......
......@@ -93,6 +93,9 @@ class FakeCrosHealthdService final
const std::vector<mojom::ProbeCategoryEnum>& categories,
ProbeTelemetryInfoCallback callback) override;
void ProbeProcessInfo(const uint32_t process_id,
ProbeProcessInfoCallback callback) override;
// Set the list of routines that will be used in the response to any
// GetAvailableRoutines IPCs received.
void SetAvailableRoutinesForTesting(
......@@ -111,6 +114,10 @@ class FakeCrosHealthdService final
void SetProbeTelemetryInfoResponseForTesting(
mojom::TelemetryInfoPtr& response_info);
// Set the ProcessResultPtr that will be used in the response to any
// ProbeProcessInfo IPCs received.
void SetProbeProcessInfoResponseForTesting(mojom::ProcessResultPtr& result);
// Calls the power event OnAcInserted for all registered power observers.
void EmitAcInsertedEventForTesting();
......@@ -131,6 +138,9 @@ class FakeCrosHealthdService final
mojom::RoutineUpdatePtr routine_update_response_{mojom::RoutineUpdate::New()};
// Used as the response to any ProbeTelemetryInfo IPCs received.
mojom::TelemetryInfoPtr telemetry_response_info_{mojom::TelemetryInfo::New()};
// Used as the response to any ProbeProcessInfo IPCs received.
mojom::ProcessResultPtr process_response_{
mojom::ProcessResult::NewProcessInfo(mojom::ProcessInfo::New())};
// Allows the remote end to call the probe, diagnostics and event service
// methods.
......
......@@ -105,6 +105,9 @@ class ServiceConnectionImpl : public ServiceConnection {
const std::vector<mojom::ProbeCategoryEnum>& categories_to_test,
mojom::CrosHealthdProbeService::ProbeTelemetryInfoCallback callback)
override;
void ProbeProcessInfo(pid_t process_id,
mojom::CrosHealthdProbeService::ProbeProcessInfoCallback
callback) override;
void GetDiagnosticsService(
mojom::CrosHealthdDiagnosticsServiceRequest service) override;
void GetProbeService(mojom::CrosHealthdProbeServiceRequest service) override;
......@@ -330,6 +333,16 @@ void ServiceConnectionImpl::ProbeTelemetryInfo(
std::move(callback));
}
void ServiceConnectionImpl::ProbeProcessInfo(
pid_t process_id,
mojom::CrosHealthdProbeService::ProbeProcessInfoCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(process_id > 0);
BindCrosHealthdProbeServiceIfNeeded();
cros_healthd_probe_service_->ProbeProcessInfo(
static_cast<uint32_t>(process_id), std::move(callback));
}
void ServiceConnectionImpl::GetDiagnosticsService(
mojom::CrosHealthdDiagnosticsServiceRequest service) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......
......@@ -5,6 +5,8 @@
#ifndef CHROMEOS_SERVICES_CROS_HEALTHD_PUBLIC_CPP_SERVICE_CONNECTION_H_
#define CHROMEOS_SERVICES_CROS_HEALTHD_PUBLIC_CPP_SERVICE_CONNECTION_H_
#include <sys/types.h>
#include <cstdint>
#include <string>
......@@ -171,13 +173,20 @@ class ServiceConnection {
mojo::PendingRemote<mojom::CrosHealthdPowerObserver>
pending_observer) = 0;
// Gather pieces of information about the platform. See
// Gathers pieces of information about the platform. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void ProbeTelemetryInfo(
const std::vector<mojom::ProbeCategoryEnum>& categories_to_test,
mojom::CrosHealthdProbeService::ProbeTelemetryInfoCallback callback) = 0;
// Gathers information about a particular process on the device. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void ProbeProcessInfo(
pid_t process_id,
mojom::CrosHealthdProbeService::ProbeProcessInfoCallback callback) = 0;
// Binds |service| to an implementation of CrosHealthdDiagnosticsService. In
// production, this implementation is provided by cros_healthd. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
......
......@@ -4,6 +4,8 @@
#include "chromeos/services/cros_healthd/public/cpp/service_connection.h"
#include <sys/types.h>
#include <utility>
#include <vector>
......@@ -462,6 +464,21 @@ TEST_F(CrosHealthdServiceConnectionTest, ProbeTelemetryInfo) {
run_loop.Run();
}
// Test that we can request process info.
TEST_F(CrosHealthdServiceConnectionTest, ProbeProcessInfo) {
auto response =
mojom::ProcessResult::NewProcessInfo(mojom::ProcessInfo::New());
FakeCrosHealthdClient::Get()->SetProbeProcessInfoResponseForTesting(response);
base::RunLoop run_loop;
ServiceConnection::GetInstance()->ProbeProcessInfo(
/*process_id=*/13,
base::BindLambdaForTesting([&](mojom::ProcessResultPtr result) {
EXPECT_EQ(result, response);
run_loop.Quit();
}));
run_loop.Run();
}
} // namespace
} // namespace cros_healthd
} // namespace chromeos
......@@ -295,6 +295,15 @@ interface CrosHealthdEventService {
// Probe interface exposed by the cros_healthd daemon.
interface CrosHealthdProbeService {
// Returns information about a specific process running on the device.
//
// The request:
// * |process_id| - PID of the process whose information is requested.
//
// The response:
// * |process_info| - Information about the requested process.
ProbeProcessInfo(uint32 process_id) => (ProcessResult process_info);
// Returns telemetry information for the desired categories.
//
// The request:
......
......@@ -62,6 +62,56 @@ struct UInt64Value {
uint64 value;
};
// An enumeration of states a process can be in.
[Extensible]
enum ProcessState {
// The process is running.
kRunning,
// The process is sleeping in an interruptible wait.
kSleeping,
// The process is waiting in an uninterruptible disk sleep.
kWaiting,
// The process is a zombie.
kZombie,
// The process is stopped on a signal.
kStopped,
// The process is stopped by tracing.
kTracingStop,
// The process is dead.
kDead,
};
// Process probe result. Can either be populated with the ProcessInfo or an
// error retrieving the information.
union ProcessResult {
// Valid ProcessInfo.
ProcessInfo process_info;
// The error that occurred attempting to retrieve the ProcessInfo.
ProbeError error;
};
// Information related to a particular process.
struct ProcessInfo {
// Command which started the process.
string command;
// User the process is running as.
uint32 user_id;
// If the process is running a real-time scheduling policy, this field is the
// negated scheduling priority, minus one. Real-time priorities range from 1
// to 99, so this will range from -2 to -100. If the process is not running a
// real-time scheduling priority, this field will be the raw nice value, where
// 0 corresponds to the user-visible high priority nice value of -20, and 39
// corresponds to the user-visible low priority nice value of 19.
int8 priority;
// User-visible nice value of the process, from a low priority of 19 to a high
// priority of -20.
int8 nice;
// Uptime of the process, in clock ticks.
uint64 uptime_ticks;
// State of the process.
ProcessState state;
};
// Battery probe result. Can either be populated with the BatteryInfo or an
// error retrieving the information.
union BatteryResult {
......
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