summaryrefslogtreecommitdiff
path: root/pwrstats_util
diff options
context:
space:
mode:
authorBenjamin Schwartz <bsschwar@google.com>2019-07-30 13:06:12 -0700
committerBenjamin Schwartz <bsschwar@google.com>2019-07-30 14:12:06 -0700
commit8c87923f8ec77515c799583e162dcfd8c6ed2236 (patch)
tree5fc50ff7b6dd4cd2b6e6c187f5f2f86ac05361e1 /pwrstats_util
parentd14a96e65cc9e72fb40d7982d9d142d2328530a6 (diff)
pwrstats_util: Add rail energy data provider
Change-Id: If4638b3f712d9daa5c3a082e7c93af34a5033c29 Fix: 138303810 Test: adb shell pwrstats_util
Diffstat (limited to 'pwrstats_util')
-rw-r--r--pwrstats_util/Android.bp1
-rw-r--r--pwrstats_util/dataproviders/RailEnergyDataProvider.cpp84
-rw-r--r--pwrstats_util/dataproviders/RailEnergyDataProvider.h33
3 files changed, 118 insertions, 0 deletions
diff --git a/pwrstats_util/Android.bp b/pwrstats_util/Android.bp
index 647c4d4..1186b98 100644
--- a/pwrstats_util/Android.bp
+++ b/pwrstats_util/Android.bp
@@ -20,6 +20,7 @@ cc_library_static {
"pwrstats_util.cpp",
"PowerStatsAggregator.cpp",
"dataproviders/PowerEntityResidencyDataProvider.cpp",
+ "dataproviders/RailEnergyDataProvider.cpp",
],
shared_libs: [
"libhidlbase",
diff --git a/pwrstats_util/dataproviders/RailEnergyDataProvider.cpp b/pwrstats_util/dataproviders/RailEnergyDataProvider.cpp
new file mode 100644
index 0000000..5de6530
--- /dev/null
+++ b/pwrstats_util/dataproviders/RailEnergyDataProvider.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define LOG_TAG "pwrstats_util"
+
+#include "RailEnergyDataProvider.h"
+#include <android-base/logging.h>
+#include <android/hardware/power/stats/1.0/IPowerStats.h>
+
+using android::sp;
+using android::hardware::Return;
+using android::hardware::power::stats::V1_0::IPowerStats;
+using android::hardware::power::stats::V1_0::Status;
+
+int RailEnergyDataProvider::get(std::unordered_map<std::string, uint64_t>* data) {
+ // example using the power stats HAL
+ sp<IPowerStats> powerStatsService =
+ android::hardware::power::stats::V1_0::IPowerStats::getService();
+ if (powerStatsService == nullptr) {
+ LOG(ERROR) << "Unable to get power.stats HAL service.";
+ return 1;
+ }
+
+ std::unordered_map<uint32_t, std::string> railNames;
+
+ Return<void> ret;
+ Status retStatus = Status::SUCCESS;
+ ret = powerStatsService->getRailInfo([&railNames, &retStatus](auto railInfos, auto status) {
+ retStatus = status;
+ if (status != Status::SUCCESS) {
+ return;
+ }
+
+ for (auto const& info : railInfos) {
+ railNames.emplace(info.index,
+ std::string(info.subsysName) + "__" + std::string(info.railName));
+ }
+ });
+ if (retStatus == Status::NOT_SUPPORTED) {
+ LOG(WARNING) << "rail energy stats not supported";
+ return 0;
+ }
+ if (!ret.isOk() || retStatus != Status::SUCCESS) {
+ LOG(ERROR) << "no rail information available";
+ return 1;
+ }
+
+ bool resultSuccess = true;
+ ret = powerStatsService->getEnergyData(
+ {}, [&data, &railNames, &resultSuccess](auto energyData, auto status) {
+ if (status != Status::SUCCESS) {
+ LOG(ERROR) << "Error getting rail energy";
+ resultSuccess = false;
+ return;
+ }
+ for (auto const& energyDatum : energyData) {
+ auto railName = railNames.find(energyDatum.index);
+ if (railName == railNames.end()) {
+ LOG(ERROR) << "Missing one or more rail names";
+ resultSuccess = false;
+ return;
+ }
+ data->emplace(railName->second, energyDatum.energy);
+ }
+ });
+ if (!ret.isOk() || !resultSuccess) {
+ LOG(ERROR) << "Failed to get rail energy stats";
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/pwrstats_util/dataproviders/RailEnergyDataProvider.h b/pwrstats_util/dataproviders/RailEnergyDataProvider.h
new file mode 100644
index 0000000..919eacb
--- /dev/null
+++ b/pwrstats_util/dataproviders/RailEnergyDataProvider.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef RAILENERGYDATAPROVIDER_H
+#define RAILENERGYDATAPROVIDER_H
+
+#include "PowerStatsAggregator.h"
+
+/**
+ * Rail Energy data provider:
+ * Provides data via Power Stats HAL 1.0
+ * data is in units of microwatt-seconds (uWs)
+ **/
+class RailEnergyDataProvider : public IPowerStatsDataProvider {
+ public:
+ RailEnergyDataProvider() = default;
+
+ int get(std::unordered_map<std::string, uint64_t>* data) override;
+};
+
+#endif // RAILENERGYDATAPROVIDER_H