Add data source to poll IHealth (battery counters) service
This CL adds a new "power" data source to poll battery
counters (AKA Coulomb counters) from the perfetto
traced_probes service. Doing so requires making HWBinder
transactions on the Android IHealth service. This has two
drawbacks: (1) the IHealth svc and hwbinder are internal
only and not part of the NDK; (2) using hwbinder requires
pulling 6 .so(s), which adds 150 KB of private dirty memory
due to linker relocations.
Both aspects are solved as follows:
1) libperfetto_android_internal.so is loaded/unloaded
dynamically to access the the hwbinder, loading
recursively libhwbinder.so etc.
3) In standalone builds, libperfetto_android_internal.so
will not be found and the power data source will
gracefully fail.
This CL depends on SELinux CL aosp/838610.
Bug: 113076327
Change-Id: Ice56c79bb1c8eec051f6c5d0afec01570a76a0a4
diff --git a/src/traced/probes/probes_producer.cc b/src/traced/probes/probes_producer.cc
index b7d666c..07c86d3 100644
--- a/src/traced/probes/probes_producer.cc
+++ b/src/traced/probes/probes_producer.cc
@@ -35,6 +35,7 @@
#include "perfetto/tracing/ipc/producer_ipc_client.h"
#include "src/traced/probes/filesystem/inode_file_data_source.h"
#include "src/traced/probes/ftrace/ftrace_data_source.h"
+#include "src/traced/probes/power/android_power_data_source.h"
#include "src/traced/probes/probes_data_source.h"
#include "perfetto/trace/filesystem/inode_file_map.pbzero.h"
@@ -55,6 +56,7 @@
constexpr char kProcessStatsSourceName[] = "linux.process_stats";
constexpr char kInodeMapSourceName[] = "linux.inode_file_map";
constexpr char kSysStatsSourceName[] = "linux.sys_stats";
+constexpr char kAndroidPowerSourceName[] = "android.power";
} // namespace.
@@ -102,6 +104,12 @@
desc.set_name(kSysStatsSourceName);
endpoint_->RegisterDataSource(desc);
}
+
+ {
+ DataSourceDescriptor desc;
+ desc.set_name(kAndroidPowerSourceName);
+ endpoint_->RegisterDataSource(desc);
+ }
}
void ProbesProducer::OnDisconnect() {
@@ -150,6 +158,8 @@
data_source = CreateProcessStatsDataSource(session_id, instance_id, config);
} else if (config.name() == kSysStatsSourceName) {
data_source = CreateSysStatsDataSource(session_id, instance_id, config);
+ } else if (config.name() == kAndroidPowerSourceName) {
+ data_source = CreateAndroidPowerDataSource(session_id, instance_id, config);
}
if (!data_source) {
@@ -247,6 +257,17 @@
config));
}
+std::unique_ptr<AndroidPowerDataSource>
+ProbesProducer::CreateAndroidPowerDataSource(TracingSessionID session_id,
+ DataSourceInstanceID id,
+ const DataSourceConfig& config) {
+ base::ignore_result(id);
+ auto buffer_id = static_cast<BufferID>(config.target_buffer());
+ return std::unique_ptr<AndroidPowerDataSource>(
+ new AndroidPowerDataSource(config, task_runner_, session_id,
+ endpoint_->CreateTraceWriter(buffer_id)));
+}
+
std::unique_ptr<SysStatsDataSource> ProbesProducer::CreateSysStatsDataSource(
TracingSessionID session_id,
DataSourceInstanceID id,