Skip to content

Commit

Permalink
Report ArtDeviceStatus as a pulled atom
Browse files Browse the repository at this point in the history
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.

Ignore-AOSP-First: adding related changes in frameworks/proto_logging
Bug: 257028435
Test: atest ArtGtestsTargetChroot
Test: statsd_testdrive 10205
Change-Id: I68a0dfd413271c458fe930a3e6c4d17ed49f8666
  • Loading branch information
Stefano Cianciulli committed Feb 1, 2024
1 parent 8107b4c commit c34231a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ PRIVATE_I18N_APEX_DEPENDENCY_LIBS := \
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
Expand Down
5 changes: 4 additions & 1 deletion odrefresh/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ cc_library_static {
"odr_metrics_record.cc",
"odr_statslog_android.cc",
],
shared_libs: ["libstatssocket"],
shared_libs: [
"libstatspull",
"libstatssocket",
],
},
host: {
srcs: ["odr_statslog_host.cc"],
Expand Down
4 changes: 3 additions & 1 deletion runtime/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ cc_defaults {
],
shared_libs: [
"libdl_android",
"libstatssocket",
"libstatspull", // for pulled atoms
"libstatssocket", // for pulled atoms
"libz", // For adler32.
"heapprofd_client_api",
],
Expand Down Expand Up @@ -1215,6 +1216,7 @@ cc_library_static {
export_generated_headers: ["statslog_art.h"],
shared_libs: [
"liblog",
"libstatspull",
"libstatssocket",
"libutils",
],
Expand Down
34 changes: 23 additions & 11 deletions runtime/metrics/statsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,30 @@ class StatsdBackend : public MetricsBackend {

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
Expand Down
4 changes: 2 additions & 2 deletions runtime/metrics/statsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class MetricsBackend;
// 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
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ void Runtime::InitNonZygoteOrPostFork(
if (!odrefresh::UploadStatsIfAvailable(&err)) {
LOG(WARNING) << "Failed to upload odrefresh metrics: " << err;
}
metrics::ReportDeviceMetrics();
metrics::SetupCallbackForDeviceStatus();
}

if (LIKELY(automatically_set_jni_ids_indirection_) && CanSetJniIdType()) {
Expand Down
1 change: 1 addition & 0 deletions test/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ art_cc_defaults {
shared_libs: [
// Dependencies of `libart(d)`, that are not included in *static_defaults.
"libdl_android",
"libstatspull",
"libstatssocket",
"heapprofd_client_api",
],
Expand Down

0 comments on commit c34231a

Please sign in to comment.