Statsd

The Statsd module includes statsd, a native service that runs in the background collecting metrics, and the Java service StatsCompanionService, which runs in the system process and bridges statsd and Java. This module is updatable, meaning it can receive updates to functionality (such as updates to the metrics used in data collection) outside of the normal Android release cycle.

Module boundary

Statsd is the primary touchpoint between the platform and launch-safety data collection. The statsd module includes the following code.

  • statsd, located in frameworks/base/cmds/statsd

  • StatsCompanionService, located in frameworks/base/services/core/java/com/android/server/stats/StatsCompanionService.java

  • A subset of the platform protobuf structures, located primarily in frameworks/base/core/proto

As a native service, statsd can outlive the framework and detect crashes in the system_server itself.

In Android 12, the Statsd module code is moved from frameworks/base/cmds/StatsD, frameworks/base/apex/StatsD, and system/core/libstats.

New project structure

  • system/core/libstatspackages/modules/StatsD/lib/libstats
    • system/core/libstats/socketpackages/modules/StatsD/lib/libstatssocket
    • system/core/libstats/pullpackages/modules/StatsD/lib/libstatspull
  • frameworks/base/cmds/StatsDpackages/modules/StatsD/bin
  • frameworks/base/apex/StatsD
    • Copy top level as is
    • Move jni into framework/jni
    • Move toplevel files into /apex directory
      • frameworks/base/apex/StatsD/\*packages/modules/StatsD/apex/\*
      • frameworks/base/apex/StatsD/jnipackages/modules/StatsD/apex/framework/jni
  • cts/hostsidetests/StatsDpackages/modules/StatsD/tests

Patch move sample commands

Apply the changes to the following branches:

  • goog/mainline-prod
  • goog/main
  • goog/\*-plus-aosp
  • aosp/main

The history for the files within Statsd should be preserved.

Module format

The statsd module (com.android.os.statsd) is in APEX format and is available for devices running Android 11 or higher.

Module dependencies

The Statsd module presents a set of @hide APIs to log events from the system. For Java code, most @hide APIs are refactored to be built on a smaller set of @SystemApi tagged methods, with some small generated glue code built in. For native code, existing native functions are refactored to be official VNDK C APIs, with generated glue.

Customization

The Statsd module doesn't support customization.

Testing

The Android Compatibility Test Suite (CTS) verifies the functionality of statsd and the atoms on which release management depends.