Report ArtDeviceStatus as a pulled atom
The current implementation is reporting a pushed atom called
ArtDeviceDatumReported containing the the boot image status as soon as
the runtime initialization has completed. One drawback with this
approach is that, if the device is not rebooted in a long time, no atoms
will be pushed. This CL introduces a new pulled atom called
ArtDeviceStatus which will be pulled rather than pushed with a fixed
schedule set on the server side - the plan is to set the schedule to
report every 24 hours, in order to receive a device status on a daily
basis for continuous analysis.
Bug: 257028435
Test: atest ArtGtestsTargetChroot
Test: statsd_testdrive 10205
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c34231a3bd9165caa5c4b721c479a6635790ac19)
Merged-In: I68a0dfd413271c458fe930a3e6c4d17ed49f8666
Change-Id: I68a0dfd413271c458fe930a3e6c4d17ed49f8666
diff --git a/Android.mk b/Android.mk
index 7e5903a..46d2374 100644
--- a/Android.mk
+++ b/Android.mk
@@ -492,7 +492,9 @@
lib64/libicuuc.so \
PRIVATE_STATSD_APEX_DEPENDENCY_LIBS := \
+ lib/libstatspull.so \
lib/libstatssocket.so \
+ lib64/libstatspull.so \
lib64/libstatssocket.so \
# Extracts files from an APEX into a location. The APEX can be either a .apex or
diff --git a/odrefresh/Android.bp b/odrefresh/Android.bp
index 97fec58..2a020da 100644
--- a/odrefresh/Android.bp
+++ b/odrefresh/Android.bp
@@ -168,7 +168,10 @@
"odr_metrics_record.cc",
"odr_statslog_android.cc",
],
- shared_libs: ["libstatssocket"],
+ shared_libs: [
+ "libstatspull",
+ "libstatssocket",
+ ],
},
host: {
srcs: ["odr_statslog_host.cc"],
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 2ed73c1..9983c24 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -113,7 +113,8 @@
],
shared_libs: [
"libdl_android",
- "libstatssocket",
+ "libstatspull", // for pulled atoms
+ "libstatssocket", // for pulled atoms
"libz", // For adler32.
"heapprofd_client_api",
],
@@ -1215,6 +1216,7 @@
export_generated_headers: ["statslog_art.h"],
shared_libs: [
"liblog",
+ "libstatspull",
"libstatssocket",
"libutils",
],
diff --git a/runtime/metrics/statsd.cc b/runtime/metrics/statsd.cc
index 67d677b..e6d26d9 100644
--- a/runtime/metrics/statsd.cc
+++ b/runtime/metrics/statsd.cc
@@ -416,18 +416,30 @@
std::unique_ptr<MetricsBackend> CreateStatsdBackend() { return std::make_unique<StatsdBackend>(); }
-void ReportDeviceMetrics() {
- Runtime* runtime = Runtime::Current();
- int32_t boot_image_status;
- if (runtime->GetHeap()->HasBootImageSpace() && !runtime->HasImageWithProfile()) {
- boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_FULL;
- } else if (runtime->GetHeap()->HasBootImageSpace() &&
- runtime->GetHeap()->GetBootImageSpaces()[0]->GetProfileFiles().empty()) {
- boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_MINIMAL;
- } else {
- boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_NONE;
+AStatsManager_PullAtomCallbackReturn DeviceStatusCallback(int32_t atom_tag,
+ AStatsEventList* data,
+ [[maybe_unused]] void* cookie) {
+ if (atom_tag == statsd::ART_DEVICE_STATUS) {
+ Runtime* runtime = Runtime::Current();
+ int32_t boot_image_status;
+ if (runtime->GetHeap()->HasBootImageSpace() && !runtime->HasImageWithProfile()) {
+ boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_FULL;
+ } else if (runtime->GetHeap()->HasBootImageSpace() &&
+ runtime->GetHeap()->GetBootImageSpaces()[0]->GetProfileFiles().empty()) {
+ boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_MINIMAL;
+ } else {
+ boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_NONE;
+ }
+ statsd::addAStatsEvent(data, atom_tag, boot_image_status);
+ return AStatsManager_PULL_SUCCESS;
}
- statsd::stats_write(statsd::ART_DEVICE_DATUM_REPORTED, boot_image_status);
+
+ return AStatsManager_PULL_SKIP;
+}
+
+void SetupCallbackForDeviceStatus() {
+ AStatsManager_setPullAtomCallback(
+ statsd::ART_DEVICE_STATUS, /*metadata=*/nullptr, DeviceStatusCallback, /*cookie=*/nullptr);
}
} // namespace metrics
diff --git a/runtime/metrics/statsd.h b/runtime/metrics/statsd.h
index ae53a22..00bd595 100644
--- a/runtime/metrics/statsd.h
+++ b/runtime/metrics/statsd.h
@@ -29,10 +29,10 @@
// Statsd is only supported on Android
#ifdef __ANDROID__
std::unique_ptr<MetricsBackend> CreateStatsdBackend();
-void ReportDeviceMetrics();
+void SetupCallbackForDeviceStatus();
#else
inline std::unique_ptr<MetricsBackend> CreateStatsdBackend() { return nullptr; }
-inline void ReportDeviceMetrics() {}
+inline void SetupCallbackForDeviceStatus() {}
#endif
} // namespace metrics
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 0411ea5..77a1130 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1317,7 +1317,7 @@
if (!odrefresh::UploadStatsIfAvailable(&err)) {
LOG(WARNING) << "Failed to upload odrefresh metrics: " << err;
}
- metrics::ReportDeviceMetrics();
+ metrics::SetupCallbackForDeviceStatus();
}
if (LIKELY(automatically_set_jni_ids_indirection_) && CanSetJniIdType()) {
diff --git a/test/Android.bp b/test/Android.bp
index 00c5f6b..5406dfd 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -236,6 +236,7 @@
shared_libs: [
// Dependencies of `libart(d)`, that are not included in *static_defaults.
"libdl_android",
+ "libstatspull",
"libstatssocket",
"heapprofd_client_api",
],