Update WatchdogPerfService to use UidStatsCollector.
- WatchdogPerfService triggers the performance data collection and
processing. Update this class to use UidStatsCollector instead of
directly using process or I/O stats collectors.
- Mark const methods with the const keyword.
Test: atest libwatchdog_test
Bug: 199782126
Change-Id: I79e3c5d466657ff9589b8bbb9606ccb496c8c76a
diff --git a/cpp/watchdog/server/src/WatchdogPerfService.cpp b/cpp/watchdog/server/src/WatchdogPerfService.cpp
index bf7480f..2761b34 100644
--- a/cpp/watchdog/server/src/WatchdogPerfService.cpp
+++ b/cpp/watchdog/server/src/WatchdogPerfService.cpp
@@ -370,7 +370,7 @@
<< kEndCustomCollectionFlag << " flags";
}
-Result<void> WatchdogPerfService::onDump(int fd) {
+Result<void> WatchdogPerfService::onDump(int fd) const {
Mutex::Autolock lock(mMutex);
if (mCurrCollectionEvent == EventType::TERMINATED) {
ALOGW("%s not active. Dumping cached data", kServiceName);
@@ -407,7 +407,7 @@
return {};
}
-bool WatchdogPerfService::dumpHelpText(int fd) {
+bool WatchdogPerfService::dumpHelpText(int fd) const {
return WriteStringToFd(StringPrintf(kHelpText, kServiceName, kStartCustomCollectionFlag,
kIntervalFlag,
std::chrono::duration_cast<std::chrono::seconds>(
@@ -421,12 +421,11 @@
fd);
}
-Result<void> WatchdogPerfService::dumpCollectorsStatusLocked(int fd) {
- if (!mUidIoStats->enabled() &&
- !WriteStringToFd(StringPrintf("UidIoStats collector failed to access the file %s",
- mUidIoStats->filePath().c_str()),
+Result<void> WatchdogPerfService::dumpCollectorsStatusLocked(int fd) const {
+ if (!mUidStatsCollector->enabled() &&
+ !WriteStringToFd(StringPrintf("UidStatsCollector failed to access proc and I/O files"),
fd)) {
- return Error() << "Failed to write UidIoStats collector status";
+ return Error() << "Failed to write UidStatsCollector status";
}
if (!mProcStat->enabled() &&
!WriteStringToFd(StringPrintf("ProcStat collector failed to access the file %s",
@@ -434,12 +433,6 @@
fd)) {
return Error() << "Failed to write ProcStat collector status";
}
- if (!mProcPidStat->enabled() &&
- !WriteStringToFd(StringPrintf("ProcPidStat collector failed to access the directory %s",
- mProcPidStat->dirPath().c_str()),
- fd)) {
- return Error() << "Failed to write ProcPidStat collector status";
- }
return {};
}
@@ -620,15 +613,15 @@
}
Result<void> WatchdogPerfService::collectLocked(WatchdogPerfService::EventMetadata* metadata) {
- if (!mUidIoStats->enabled() && !mProcStat->enabled() && !mProcPidStat->enabled()) {
+ if (!mUidStatsCollector->enabled() && !mProcStat->enabled()) {
return Error() << "No collectors enabled";
}
time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
- if (mUidIoStats->enabled()) {
- if (const auto result = mUidIoStats->collect(); !result.ok()) {
- return Error() << "Failed to collect per-uid I/O usage: " << result.error();
+ if (mUidStatsCollector->enabled()) {
+ if (const auto result = mUidStatsCollector->collect(); !result.ok()) {
+ return Error() << "Failed to collect per-uid proc and I/O stats: " << result.error();
}
}
@@ -638,25 +631,19 @@
}
}
- if (mProcPidStat->enabled()) {
- if (const auto result = mProcPidStat->collect(); !result.ok()) {
- return Error() << "Failed to collect process stats: " << result.error();
- }
- }
-
for (const auto& processor : mDataProcessors) {
Result<void> result;
switch (mCurrCollectionEvent) {
case EventType::BOOT_TIME_COLLECTION:
- result = processor->onBoottimeCollection(now, mUidIoStats, mProcStat, mProcPidStat);
+ result = processor->onBoottimeCollection(now, mUidStatsCollector, mProcStat);
break;
case EventType::PERIODIC_COLLECTION:
- result = processor->onPeriodicCollection(now, mSystemState, mUidIoStats, mProcStat,
- mProcPidStat);
+ result = processor->onPeriodicCollection(now, mSystemState, mUidStatsCollector,
+ mProcStat);
break;
case EventType::CUSTOM_COLLECTION:
result = processor->onCustomCollection(now, mSystemState, metadata->filterPackages,
- mUidIoStats, mProcStat, mProcPidStat);
+ mUidStatsCollector, mProcStat);
break;
default:
result = Error() << "Invalid collection event " << toString(mCurrCollectionEvent);
diff --git a/cpp/watchdog/server/src/WatchdogPerfService.h b/cpp/watchdog/server/src/WatchdogPerfService.h
index 7ff9e56..8fdf303 100644
--- a/cpp/watchdog/server/src/WatchdogPerfService.h
+++ b/cpp/watchdog/server/src/WatchdogPerfService.h
@@ -19,9 +19,8 @@
#include "LooperWrapper.h"
#include "ProcDiskStats.h"
-#include "ProcPidStat.h"
#include "ProcStat.h"
-#include "UidIoStats.h"
+#include "UidStatsCollector.h"
#include <android-base/chrono_utils.h>
#include <android-base/result.h>
@@ -64,7 +63,7 @@
GARAGE_MODE = 1,
};
-/*
+/**
* DataProcessor defines methods that must be implemented in order to process the data collected
* by |WatchdogPerfService|.
*/
@@ -73,29 +72,30 @@
IDataProcessorInterface() {}
virtual ~IDataProcessorInterface() {}
// Returns the name of the data processor.
- virtual std::string name() = 0;
+ virtual std::string name() const = 0;
// Callback to initialize the data processor.
virtual android::base::Result<void> init() = 0;
// Callback to terminate the data processor.
virtual void terminate() = 0;
// Callback to process the data collected during boot-time.
virtual android::base::Result<void> onBoottimeCollection(
- time_t time, const android::wp<UidIoStats>& uidIoStats,
- const android::wp<ProcStat>& procStat, const android::wp<ProcPidStat>& procPidStat) = 0;
+ time_t time, const android::wp<UidStatsCollectorInterface>& uidStatsCollector,
+ const android::wp<ProcStat>& procStat) = 0;
// Callback to process the data collected periodically post boot complete.
virtual android::base::Result<void> onPeriodicCollection(
- time_t time, SystemState systemState, const android::wp<UidIoStats>& uidIoStats,
- const android::wp<ProcStat>& procStat, const android::wp<ProcPidStat>& procPidStat) = 0;
- /*
+ time_t time, SystemState systemState,
+ const android::wp<UidStatsCollectorInterface>& uidStatsCollector,
+ const android::wp<ProcStat>& procStat) = 0;
+ /**
* Callback to process the data collected on custom collection and filter the results only to
* the specified |filterPackages|.
*/
virtual android::base::Result<void> onCustomCollection(
time_t time, SystemState systemState,
const std::unordered_set<std::string>& filterPackages,
- const android::wp<UidIoStats>& uidIoStats, const android::wp<ProcStat>& procStat,
- const android::wp<ProcPidStat>& procPidStat) = 0;
- /*
+ const android::wp<UidStatsCollectorInterface>& uidStatsCollector,
+ const android::wp<ProcStat>& procStat) = 0;
+ /**
* Callback to periodically monitor the collected data and trigger the given |alertHandler|
* on detecting resource overuse.
*/
@@ -103,8 +103,8 @@
time_t time, const android::wp<IProcDiskStatsInterface>& procDiskStats,
const std::function<void()>& alertHandler) = 0;
// Callback to dump the boot-time collected and periodically collected data.
- virtual android::base::Result<void> onDump(int fd) = 0;
- /*
+ virtual android::base::Result<void> onDump(int fd) const = 0;
+ /**
* Callback to dump the custom collected data. When fd == -1, clear the custom collection cache.
*/
virtual android::base::Result<void> onCustomCollectionDump(int fd) = 0;
@@ -127,20 +127,20 @@
};
enum SwitchMessage {
- /*
+ /**
* On receiving this message, collect the last boot-time record and start periodic collection
* and monitor.
*/
END_BOOTTIME_COLLECTION = EventType::LAST_EVENT + 1,
- /*
+ /**
* On receiving this message, ends custom collection, discard collected data and start periodic
* collection and monitor.
*/
END_CUSTOM_COLLECTION,
};
-/*
+/**
* WatchdogPerfServiceInterface collects performance data during boot-time and periodically post
* boot complete. It exposes APIs that the main thread and binder service can call to start a
* collection, switch the collection type, and generate collection dumps.
@@ -150,7 +150,7 @@
// Register a data processor to process the data collected by |WatchdogPerfService|.
virtual android::base::Result<void> registerDataProcessor(
android::sp<IDataProcessorInterface> processor) = 0;
- /*
+ /**
* Starts the boot-time collection in the looper handler on a new thread and returns
* immediately. Must be called only once. Otherwise, returns an error.
*/
@@ -161,7 +161,7 @@
virtual void setSystemState(SystemState systemState) = 0;
// Ends the boot-time collection by switching to periodic collection and returns immediately.
virtual android::base::Result<void> onBootFinished() = 0;
- /*
+ /**
* Depending on the arguments, it either:
* 1. Starts a custom collection.
* 2. Or ends the current custom collection and dumps the collected data.
@@ -170,9 +170,9 @@
virtual android::base::Result<void> onCustomCollection(
int fd, const Vector<android::String16>& args) = 0;
// Generates a dump from the boot-time and periodic collection events.
- virtual android::base::Result<void> onDump(int fd) = 0;
+ virtual android::base::Result<void> onDump(int fd) const = 0;
// Dumps the help text.
- virtual bool dumpHelpText(int fd) = 0;
+ virtual bool dumpHelpText(int fd) const = 0;
};
class WatchdogPerfService final : public WatchdogPerfServiceInterface {
@@ -185,9 +185,8 @@
mCustomCollection({}),
mPeriodicMonitor({}),
mCurrCollectionEvent(EventType::INIT),
- mUidIoStats(android::sp<UidIoStats>::make()),
+ mUidStatsCollector(android::sp<UidStatsCollector>::make()),
mProcStat(android::sp<ProcStat>::make()),
- mProcPidStat(android::sp<ProcPidStat>::make()),
mProcDiskStats(android::sp<ProcDiskStats>::make()),
mDataProcessors({}) {}
@@ -207,9 +206,9 @@
android::base::Result<void> onCustomCollection(int fd,
const Vector<android::String16>& args) override;
- android::base::Result<void> onDump(int fd) override;
+ android::base::Result<void> onDump(int fd) const override;
- bool dumpHelpText(int fd) override;
+ bool dumpHelpText(int fd) const override;
private:
struct EventMetadata {
@@ -226,9 +225,9 @@
};
// Dumps the collectors' status when they are disabled.
- android::base::Result<void> dumpCollectorsStatusLocked(int fd);
+ android::base::Result<void> dumpCollectorsStatusLocked(int fd) const;
- /*
+ /**
* Starts a custom collection on the looper handler, temporarily stops the periodic collection
* (won't discard the collected data), and returns immediately. Returns any error observed
* during this process.
@@ -243,7 +242,7 @@
std::chrono::nanoseconds interval, std::chrono::nanoseconds maxDuration,
const std::unordered_set<std::string>& filterPackages);
- /*
+ /**
* Ends the current custom collection, generates a dump, sends a looper message to start the
* periodic collection, and returns immediately. Returns an error when there is no custom
* collection running or when a dump couldn't be generated from the custom collection.
@@ -262,7 +261,7 @@
// Processes the monitor events received by |handleMessage|.
android::base::Result<void> processMonitorEvent(EventMetadata* metadata);
- /*
+ /**
* Returns the metadata for the current collection based on |mCurrCollectionEvent|. Returns
* nullptr on invalid collection event.
*/
@@ -272,7 +271,7 @@
std::thread mCollectionThread;
// Makes sure only one collection is running at any given time.
- Mutex mMutex;
+ mutable Mutex mMutex;
// Handler lopper to execute different collection events on the collection thread.
android::sp<LooperWrapper> mHandlerLooper GUARDED_BY(mMutex);
@@ -295,21 +294,18 @@
// Info for the |EventType::PERIODIC| monitor event.
EventMetadata mPeriodicMonitor GUARDED_BY(mMutex);
- /*
+ /**
* Tracks either the WatchdogPerfService's state or current collection event. Updated on
* |start|, |onBootComplete|, |startCustomCollection|, |endCustomCollection|, and |terminate|.
*/
EventType mCurrCollectionEvent GUARDED_BY(mMutex);
- // Collector/parser for `/proc/uid_io/stats`.
- android::sp<UidIoStats> mUidIoStats GUARDED_BY(mMutex);
+ // Collector for UID process and I/O stats.
+ android::sp<UidStatsCollectorInterface> mUidStatsCollector GUARDED_BY(mMutex);
// Collector/parser for `/proc/stat`.
android::sp<ProcStat> mProcStat GUARDED_BY(mMutex);
- // Collector/parser for `/proc/PID/*` stat files.
- android::sp<ProcPidStat> mProcPidStat GUARDED_BY(mMutex);
-
// Collector/parser for `/proc/diskstats` file.
android::sp<IProcDiskStatsInterface> mProcDiskStats GUARDED_BY(mMutex);
diff --git a/cpp/watchdog/server/tests/MockDataProcessor.h b/cpp/watchdog/server/tests/MockDataProcessor.h
index d9a2600..b9ea48c 100644
--- a/cpp/watchdog/server/tests/MockDataProcessor.h
+++ b/cpp/watchdog/server/tests/MockDataProcessor.h
@@ -30,24 +30,22 @@
MockDataProcessor() {
EXPECT_CALL(*this, name()).WillRepeatedly(::testing::Return("MockedDataProcessor"));
}
- MOCK_METHOD(std::string, name, (), (override));
+ MOCK_METHOD(std::string, name, (), (const, override));
MOCK_METHOD(android::base::Result<void>, init, (), (override));
MOCK_METHOD(void, terminate, (), (override));
MOCK_METHOD(android::base::Result<void>, onBoottimeCollection,
- (time_t, const wp<UidIoStats>&, const wp<ProcStat>&, const wp<ProcPidStat>&),
- (override));
+ (time_t, const wp<UidStatsCollectorInterface>&, const wp<ProcStat>&), (override));
MOCK_METHOD(android::base::Result<void>, onPeriodicCollection,
- (time_t, SystemState, const wp<UidIoStats>&, const wp<ProcStat>&,
- const wp<ProcPidStat>&),
+ (time_t, SystemState, const wp<UidStatsCollectorInterface>&, const wp<ProcStat>&),
(override));
MOCK_METHOD(android::base::Result<void>, onCustomCollection,
- (time_t, SystemState, const std::unordered_set<std::string>&, const wp<UidIoStats>&,
- const wp<ProcStat>&, const wp<ProcPidStat>&),
+ (time_t, SystemState, const std::unordered_set<std::string>&,
+ const wp<UidStatsCollectorInterface>&, const wp<ProcStat>&),
(override));
MOCK_METHOD(android::base::Result<void>, onPeriodicMonitor,
(time_t, const android::wp<IProcDiskStatsInterface>&, const std::function<void()>&),
(override));
- MOCK_METHOD(android::base::Result<void>, onDump, (int), (override));
+ MOCK_METHOD(android::base::Result<void>, onDump, (int), (const, override));
MOCK_METHOD(android::base::Result<void>, onCustomCollectionDump, (int), (override));
};
diff --git a/cpp/watchdog/server/tests/MockWatchdogPerfService.h b/cpp/watchdog/server/tests/MockWatchdogPerfService.h
index 6f0fb51..114c308 100644
--- a/cpp/watchdog/server/tests/MockWatchdogPerfService.h
+++ b/cpp/watchdog/server/tests/MockWatchdogPerfService.h
@@ -40,8 +40,8 @@
MOCK_METHOD(android::base::Result<void>, onBootFinished, (), (override));
MOCK_METHOD(android::base::Result<void>, onCustomCollection,
(int fd, const Vector<android::String16>& args), (override));
- MOCK_METHOD(android::base::Result<void>, onDump, (int fd), (override));
- MOCK_METHOD(bool, dumpHelpText, (int fd), (override));
+ MOCK_METHOD(android::base::Result<void>, onDump, (int fd), (const, override));
+ MOCK_METHOD(bool, dumpHelpText, (int fd), (const, override));
MOCK_METHOD(void, handleMessage, (const Message&), (override));
};
diff --git a/cpp/watchdog/server/tests/WatchdogPerfServiceTest.cpp b/cpp/watchdog/server/tests/WatchdogPerfServiceTest.cpp
index 2bc9803..864d6d1 100644
--- a/cpp/watchdog/server/tests/WatchdogPerfServiceTest.cpp
+++ b/cpp/watchdog/server/tests/WatchdogPerfServiceTest.cpp
@@ -17,13 +17,10 @@
#include "LooperStub.h"
#include "MockDataProcessor.h"
#include "MockProcDiskStats.h"
-#include "MockProcPidStat.h"
#include "MockProcStat.h"
-#include "MockUidIoStats.h"
-#include "ProcPidDir.h"
-#include "ProcPidStat.h"
+#include "MockUidStatsCollector.h"
#include "ProcStat.h"
-#include "UidIoStats.h"
+#include "UidStatsCollector.h"
#include "WatchdogPerfService.h"
#include <WatchdogProperties.sysprop.h>
@@ -42,12 +39,10 @@
using ::android::sp;
using ::android::String16;
using ::android::wp;
-using ::android::automotive::watchdog::internal::PowerCycle;
using ::android::automotive::watchdog::testing::LooperStub;
using ::android::base::Error;
using ::android::base::Result;
using ::testing::_;
-using ::testing::DefaultValue;
using ::testing::InSequence;
using ::testing::Mock;
using ::testing::NiceMock;
@@ -71,19 +66,17 @@
void injectFakes() {
looperStub = sp<LooperStub>::make();
- mockUidIoStats = sp<NiceMock<MockUidIoStats>>::make();
+ mockUidStatsCollector = sp<MockUidStatsCollector>::make();
mockProcDiskStats = sp<NiceMock<MockProcDiskStats>>::make();
mockProcStat = sp<NiceMock<MockProcStat>>::make();
- mockProcPidStat = sp<NiceMock<MockProcPidStat>>::make();
mockDataProcessor = sp<StrictMock<MockDataProcessor>>::make();
{
Mutex::Autolock lock(service->mMutex);
service->mHandlerLooper = looperStub;
- service->mUidIoStats = mockUidIoStats;
+ service->mUidStatsCollector = mockUidStatsCollector;
service->mProcDiskStats = mockProcDiskStats;
service->mProcStat = mockProcStat;
- service->mProcPidStat = mockProcPidStat;
}
EXPECT_CALL(*mockDataProcessor, init()).Times(1);
ASSERT_RESULT_OK(service->registerDataProcessor(mockDataProcessor));
@@ -114,19 +107,17 @@
}
void verifyAndClearExpectations() {
- Mock::VerifyAndClearExpectations(mockUidIoStats.get());
+ Mock::VerifyAndClearExpectations(mockUidStatsCollector.get());
Mock::VerifyAndClearExpectations(mockProcStat.get());
- Mock::VerifyAndClearExpectations(mockProcPidStat.get());
Mock::VerifyAndClearExpectations(mockDataProcessor.get());
}
sp<WatchdogPerfService> service;
// Below fields are populated only on injectFakes.
sp<LooperStub> looperStub;
- sp<MockUidIoStats> mockUidIoStats;
+ sp<MockUidStatsCollector> mockUidStatsCollector;
sp<MockProcDiskStats> mockProcDiskStats;
sp<MockProcStat> mockProcStat;
- sp<MockProcPidStat> mockProcPidStat;
sp<MockDataProcessor> mockDataProcessor;
};
@@ -139,13 +130,13 @@
ASSERT_RESULT_OK(servicePeer->start());
- EXPECT_CALL(*servicePeer->mockUidIoStats, collect()).Times(2);
+ EXPECT_CALL(*servicePeer->mockUidStatsCollector, collect()).Times(2);
EXPECT_CALL(*servicePeer->mockProcStat, collect()).Times(2);
- EXPECT_CALL(*servicePeer->mockProcPidStat, collect()).Times(2);
EXPECT_CALL(*servicePeer->mockDataProcessor,
- onBoottimeCollection(_, wp<UidIoStats>(servicePeer->mockUidIoStats),
- wp<ProcStat>(servicePeer->mockProcStat),
- wp<ProcPidStat>(servicePeer->mockProcPidStat)))
+ onBoottimeCollection(_,
+ wp<UidStatsCollectorInterface>(
+ servicePeer->mockUidStatsCollector),
+ wp<ProcStat>(servicePeer->mockProcStat)))
.Times(2);
// Make sure the collection event changes from EventType::INIT to
@@ -206,17 +197,15 @@
ASSERT_RESULT_OK(servicePeer.start());
- wp<UidIoStats> uidIoStats(servicePeer.mockUidIoStats);
+ wp<UidStatsCollectorInterface> uidStatsCollector(servicePeer.mockUidStatsCollector);
wp<IProcDiskStatsInterface> procDiskStats(servicePeer.mockProcDiskStats);
wp<ProcStat> procStat(servicePeer.mockProcStat);
- wp<ProcPidStat> procPidStat(servicePeer.mockProcPidStat);
// #1 Boot-time collection
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).Times(1);
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockProcStat, collect()).Times(1);
- EXPECT_CALL(*servicePeer.mockProcPidStat, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onBoottimeCollection(_, uidIoStats, procStat, procPidStat))
+ onBoottimeCollection(_, uidStatsCollector, procStat))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -228,11 +217,10 @@
servicePeer.verifyAndClearExpectations();
// #2 Boot-time collection
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).Times(1);
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockProcStat, collect()).Times(1);
- EXPECT_CALL(*servicePeer.mockProcPidStat, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onBoottimeCollection(_, uidIoStats, procStat, procPidStat))
+ onBoottimeCollection(_, uidStatsCollector, procStat))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -245,11 +233,10 @@
servicePeer.verifyAndClearExpectations();
// #3 Last boot-time collection
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).Times(1);
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockProcStat, collect()).Times(1);
- EXPECT_CALL(*servicePeer.mockProcPidStat, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onBoottimeCollection(_, uidIoStats, procStat, procPidStat))
+ onBoottimeCollection(_, uidStatsCollector, procStat))
.Times(1);
ASSERT_RESULT_OK(service->onBootFinished());
@@ -286,12 +273,10 @@
servicePeer.verifyAndClearExpectations();
// #6 Periodic collection
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).Times(1);
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockProcStat, collect()).Times(1);
- EXPECT_CALL(*servicePeer.mockProcPidStat, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onPeriodicCollection(_, SystemState::NORMAL_MODE, uidIoStats, procStat,
- procPidStat))
+ onPeriodicCollection(_, SystemState::NORMAL_MODE, uidStatsCollector, procStat))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -312,12 +297,10 @@
ASSERT_RESULT_OK(service->onCustomCollection(-1, args));
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).Times(1);
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockProcStat, collect()).Times(1);
- EXPECT_CALL(*servicePeer.mockProcPidStat, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onCustomCollection(_, SystemState::NORMAL_MODE, _, uidIoStats, procStat,
- procPidStat))
+ onCustomCollection(_, SystemState::NORMAL_MODE, _, uidStatsCollector, procStat))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -329,12 +312,10 @@
servicePeer.verifyAndClearExpectations();
// #8 Custom collection
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).Times(1);
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockProcStat, collect()).Times(1);
- EXPECT_CALL(*servicePeer.mockProcPidStat, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onCustomCollection(_, SystemState::NORMAL_MODE, _, uidIoStats, procStat,
- procPidStat))
+ onCustomCollection(_, SystemState::NORMAL_MODE, _, uidStatsCollector, procStat))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -362,12 +343,10 @@
<< "Invalid collection event";
// #10 Switch to periodic collection
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).Times(1);
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockProcStat, collect()).Times(1);
- EXPECT_CALL(*servicePeer.mockProcPidStat, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onPeriodicCollection(_, SystemState::NORMAL_MODE, uidIoStats, procStat,
- procPidStat))
+ onPeriodicCollection(_, SystemState::NORMAL_MODE, uidStatsCollector, procStat))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -398,9 +377,8 @@
ASSERT_RESULT_OK(servicePeer.start());
- ON_CALL(*servicePeer.mockUidIoStats, enabled()).WillByDefault(Return(false));
+ ON_CALL(*servicePeer.mockUidStatsCollector, enabled()).WillByDefault(Return(false));
ON_CALL(*servicePeer.mockProcStat, enabled()).WillByDefault(Return(false));
- ON_CALL(*servicePeer.mockProcPidStat, enabled()).WillByDefault(Return(false));
// Collection should terminate and call data processor's terminate method on error.
EXPECT_CALL(*servicePeer.mockDataProcessor, terminate()).Times(1);
@@ -422,7 +400,7 @@
// Inject data collector error.
Result<void> errorRes = Error() << "Failed to collect data";
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).WillOnce(Return(errorRes));
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).WillOnce(Return(errorRes));
// Collection should terminate and call data processor's terminate method on error.
EXPECT_CALL(*servicePeer.mockDataProcessor, terminate()).Times(1);
@@ -447,9 +425,10 @@
// Inject data processor error.
Result<void> errorRes = Error() << "Failed to process data";
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onBoottimeCollection(_, wp<UidIoStats>(servicePeer.mockUidIoStats),
- wp<ProcStat>(servicePeer.mockProcStat),
- wp<ProcPidStat>(servicePeer.mockProcPidStat)))
+ onBoottimeCollection(_,
+ wp<UidStatsCollectorInterface>(
+ servicePeer.mockUidStatsCollector),
+ wp<ProcStat>(servicePeer.mockProcStat)))
.WillOnce(Return(errorRes));
// Collection should terminate and call data processor's terminate method on error.
@@ -484,16 +463,15 @@
int maxIterations = static_cast<int>(kTestCustomCollectionDuration.count() /
kTestCustomCollectionInterval.count());
for (int i = 0; i <= maxIterations; ++i) {
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).Times(1);
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockProcStat, collect()).Times(1);
- EXPECT_CALL(*servicePeer.mockProcPidStat, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockDataProcessor,
onCustomCollection(_, SystemState::NORMAL_MODE,
UnorderedElementsAreArray(
{"android.car.cts", "system_server"}),
- wp<UidIoStats>(servicePeer.mockUidIoStats),
- wp<ProcStat>(servicePeer.mockProcStat),
- wp<ProcPidStat>(servicePeer.mockProcPidStat)))
+ wp<UidStatsCollectorInterface>(
+ servicePeer.mockUidStatsCollector),
+ wp<ProcStat>(servicePeer.mockProcStat)))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -529,10 +507,9 @@
ASSERT_NO_FATAL_FAILURE(startPeriodicCollection(&servicePeer));
- wp<UidIoStats> uidIoStats(servicePeer.mockUidIoStats);
+ wp<UidStatsCollectorInterface> uidStatsCollector(servicePeer.mockUidStatsCollector);
wp<IProcDiskStatsInterface> procDiskStats(servicePeer.mockProcDiskStats);
wp<ProcStat> procStat(servicePeer.mockProcStat);
- wp<ProcPidStat> procPidStat(servicePeer.mockProcPidStat);
// Periodic monitor issuing an alert to start new collection.
EXPECT_CALL(*servicePeer.mockProcDiskStats, collect()).Times(1);
@@ -549,12 +526,10 @@
<< " seconds interval";
servicePeer.verifyAndClearExpectations();
- EXPECT_CALL(*servicePeer.mockUidIoStats, collect()).Times(1);
+ EXPECT_CALL(*servicePeer.mockUidStatsCollector, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockProcStat, collect()).Times(1);
- EXPECT_CALL(*servicePeer.mockProcPidStat, collect()).Times(1);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onPeriodicCollection(_, SystemState::NORMAL_MODE, uidIoStats, procStat,
- procPidStat))
+ onPeriodicCollection(_, SystemState::NORMAL_MODE, uidStatsCollector, procStat))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -575,7 +550,7 @@
ASSERT_NO_FATAL_FAILURE(skipPeriodicMonitorEvents(&servicePeer));
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onPeriodicCollection(_, SystemState::NORMAL_MODE, _, _, _))
+ onPeriodicCollection(_, SystemState::NORMAL_MODE, _, _))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -587,7 +562,7 @@
service->setSystemState(SystemState::GARAGE_MODE);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onPeriodicCollection(_, SystemState::GARAGE_MODE, _, _, _))
+ onPeriodicCollection(_, SystemState::GARAGE_MODE, _, _))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());
@@ -599,7 +574,7 @@
service->setSystemState(SystemState::NORMAL_MODE);
EXPECT_CALL(*servicePeer.mockDataProcessor,
- onPeriodicCollection(_, SystemState::NORMAL_MODE, _, _, _))
+ onPeriodicCollection(_, SystemState::NORMAL_MODE, _, _))
.Times(1);
ASSERT_RESULT_OK(servicePeer.looperStub->pollCache());