Cleanup NNAPI platform telemetry code

This CL cleans up and renames NNAPI platform telemetry functions, files,
and comments.

Bug: 232277065
Test: mma
Test: presubmit
Change-Id: I55bb58fcd31b9615705805f9cd81701461321758
Merged-In: I55bb58fcd31b9615705805f9cd81701461321758
(cherry picked from commit 43622d6e90ece04b04b75d3758b701ebe5777b18)
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 3478d35..7bc3b1b 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -107,7 +107,7 @@
             generated_headers: ["statslog_neuralnetworks.h"],
             export_generated_headers: ["statslog_neuralnetworks.h"],
             srcs: [
-                "TelemetryWestworld.cpp",
+                "TelemetryStatsd.cpp",
             ],
             shared_libs: [
                 "libnativewindow",
diff --git a/runtime/Telemetry.cpp b/runtime/Telemetry.cpp
index c82aad3..5adf0f8 100644
--- a/runtime/Telemetry.cpp
+++ b/runtime/Telemetry.cpp
@@ -30,7 +30,7 @@
 #include "Tracing.h"
 
 #if defined(__ANDROID__) && !defined(NN_COMPATIBILITY_LIBRARY_BUILD)
-#include "TelemetryWestworld.h"
+#include "TelemetryStatsd.h"
 #endif  // defined(__ANDROID__) && !defined(NN_COMPATIBILITY_LIBRARY_BUILD)
 
 namespace android::nn::telemetry {
@@ -176,7 +176,7 @@
 
 #if defined(__ANDROID__) && !defined(NN_COMPATIBILITY_LIBRARY_BUILD)
     if (DeviceManager::get()->isPlatformTelemetryEnabled()) {
-        logCompilationToWestworld(&info);
+        logCompilationToStatsd(&info);
     }
 #endif  // defined(__ANDROID__) && !defined(NN_COMPATIBILITY_LIBRARY_BUILD)
 
@@ -233,7 +233,7 @@
 
 #if defined(__ANDROID__) && !defined(NN_COMPATIBILITY_LIBRARY_BUILD)
     if (DeviceManager::get()->isPlatformTelemetryEnabled()) {
-        logExecutionToWestworld(&info);
+        logExecutionToStatsd(&info);
     }
 #endif  // defined(__ANDROID__) && !defined(NN_COMPATIBILITY_LIBRARY_BUILD)
 
diff --git a/runtime/TelemetryWestworld.cpp b/runtime/TelemetryStatsd.cpp
similarity index 93%
rename from runtime/TelemetryWestworld.cpp
rename to runtime/TelemetryStatsd.cpp
index cc53fcc..db8318c 100644
--- a/runtime/TelemetryWestworld.cpp
+++ b/runtime/TelemetryStatsd.cpp
@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-#define LOG_TAG "TelemetryWestworld"
+#define LOG_TAG "TelemetryStatsd"
 
-#include "TelemetryWestworld.h"
+#include "TelemetryStatsd.h"
 
 #include <android-base/logging.h>
 #include <android-base/no_destructor.h>
@@ -39,10 +39,10 @@
 namespace {
 
 constexpr uint64_t kNoTimeReportedRuntime = std::numeric_limits<uint64_t>::max();
-constexpr int64_t kNoTimeReportedWestworld = std::numeric_limits<int64_t>::max();
+constexpr int64_t kNoTimeReportedStatsd = std::numeric_limits<int64_t>::max();
 constexpr size_t kInitialChannelSize = 100;
 
-// WestWorld specifies that "Atom logging frequency should not exceed once per 10 milliseconds (i.e.
+// Statsd specifies that "Atom logging frequency should not exceed once per 10 milliseconds (i.e.
 // consecutive atom calls should be at least 10 milliseconds apart)." A quiet period of 100ms is
 // chosen here to reduce the chance that the NNAPI logs too frequently, even from separate
 // applications.
@@ -55,16 +55,16 @@
 
 constexpr int64_t nanosToMillis(uint64_t time) {
     constexpr uint64_t kNanosPerMilli = 1'000'000;
-    return time == kNoTimeReportedRuntime ? kNoTimeReportedWestworld : time / kNanosPerMilli;
+    return time == kNoTimeReportedRuntime ? kNoTimeReportedStatsd : time / kNanosPerMilli;
 }
 
 constexpr int64_t nanosToMicros(uint64_t time) {
     constexpr uint64_t kNanosPerMicro = 1'000;
-    return time == kNoTimeReportedRuntime ? kNoTimeReportedWestworld : time / kNanosPerMicro;
+    return time == kNoTimeReportedRuntime ? kNoTimeReportedStatsd : time / kNanosPerMicro;
 }
 
 AtomValue::AccumulatedTiming accumulatedTimingFrom(int64_t timing) {
-    if (timing == kNoTimeReportedWestworld) {
+    if (timing == kNoTimeReportedStatsd) {
         return {};
     }
     return {
@@ -182,8 +182,8 @@
                    : ANEURALNETWORKS_OP_FAILED;
 }
 
-void logAtomToWestworld(Atom&& atom) {
-    NNTRACE_RT(NNTRACE_PHASE_UNSPECIFIED, "logAtomToWestworld");
+void logAtomToStatsd(Atom&& atom) {
+    NNTRACE_RT(NNTRACE_PHASE_UNSPECIFIED, "logAtomToStatsd");
     const auto& [key, value] = atom;
 
     if (!key.isExecution) {
@@ -234,8 +234,8 @@
     }
 }
 
-AsyncLogger& getWestworldLogger() {
-    static base::NoDestructor<AsyncLogger> logger(logAtomToWestworld, kMinimumLoggingQuietPeriod);
+AsyncLogger& getStatsdLogger() {
+    static base::NoDestructor<AsyncLogger> logger(logAtomToStatsd, kMinimumLoggingQuietPeriod);
     return *logger;
 }
 
@@ -430,14 +430,14 @@
     return atom;
 }
 
-void logCompilationToWestworld(const DiagnosticCompilationInfo* info) {
-    NNTRACE_RT(NNTRACE_PHASE_UNSPECIFIED, "logCompilationWestworld");
-    getWestworldLogger().write(createAtomFrom(info));
+void logCompilationToStatsd(const DiagnosticCompilationInfo* info) {
+    NNTRACE_RT(NNTRACE_PHASE_UNSPECIFIED, "logCompilationStatsd");
+    getStatsdLogger().write(createAtomFrom(info));
 }
 
-void logExecutionToWestworld(const DiagnosticExecutionInfo* info) {
-    NNTRACE_RT(NNTRACE_PHASE_UNSPECIFIED, "logExecutionWestworld");
-    getWestworldLogger().write(createAtomFrom(info));
+void logExecutionToStatsd(const DiagnosticExecutionInfo* info) {
+    NNTRACE_RT(NNTRACE_PHASE_UNSPECIFIED, "logExecutionStatsd");
+    getStatsdLogger().write(createAtomFrom(info));
 }
 
 }  // namespace android::nn::telemetry
diff --git a/runtime/TelemetryWestworld.h b/runtime/TelemetryStatsd.h
similarity index 89%
rename from runtime/TelemetryWestworld.h
rename to runtime/TelemetryStatsd.h
index da6df5d..d9cf2c6 100644
--- a/runtime/TelemetryWestworld.h
+++ b/runtime/TelemetryStatsd.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TELEMETRY_WESTWORLD_H
-#define ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TELEMETRY_WESTWORLD_H
+#ifndef ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TELEMETRY_STATSD_H
+#define ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TELEMETRY_STATSD_H
 
 #include <android-base/thread_annotations.h>
 
@@ -94,7 +94,7 @@
 
 void combineAtomValues(AtomValue* acculatedValue, const AtomValue& value);
 
-// Atom type to be sent to Westworld Telemetry
+// Atom type to be sent to Statsd Telemetry
 using Atom = std::pair<AtomKey, AtomValue>;
 
 // Helper class to locally aggregate and retrieve telemetry atoms.
@@ -118,8 +118,8 @@
 using LoggerFn = std::function<void(Atom&&)>;
 
 // AsyncLogger minimizes the call to `write`, so that the calling thread which handles the
-// compilation or execution is not slowed down by writing to WestWorld. Instead, AsyncLogger
-// contains a dedicated thread that will handle logging to WestWorld in the background.
+// compilation or execution is not slowed down by writing to statsd. Instead, AsyncLogger
+// contains a dedicated thread that will handle logging to statsd in the background.
 // This class is thread-safe.
 class AsyncLogger {
    public:
@@ -155,10 +155,10 @@
 Atom createAtomFrom(const DiagnosticCompilationInfo* info);
 Atom createAtomFrom(const DiagnosticExecutionInfo* info);
 
-// Log an Atom to WestWorld from a diagnostic info object.
-void logCompilationToWestworld(const DiagnosticCompilationInfo* info);
-void logExecutionToWestworld(const DiagnosticExecutionInfo* info);
+// Log an Atom to statsd from a diagnostic info object.
+void logCompilationToStatsd(const DiagnosticCompilationInfo* info);
+void logExecutionToStatsd(const DiagnosticExecutionInfo* info);
 
 }  // namespace android::nn::telemetry
 
-#endif  // ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TELEMETRY_WESTWORLD_H
+#endif  // ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TELEMETRY_STATSD_H
diff --git a/runtime/test/Android.bp b/runtime/test/Android.bp
index b094fb2..57addd9 100644
--- a/runtime/test/Android.bp
+++ b/runtime/test/Android.bp
@@ -210,7 +210,7 @@
     target: {
         android: {
             test_config: "AndroidTest_NeuralNetworksTest_static.xml",
-            srcs: ["TestWestworldTelemetry.cpp"],
+            srcs: ["TestStatsdTelemetry.cpp"],
         },
         host: {
             cflags: [
diff --git a/runtime/test/TestWestworldTelemetry.cpp b/runtime/test/TestStatsdTelemetry.cpp
similarity index 92%
rename from runtime/test/TestWestworldTelemetry.cpp
rename to runtime/test/TestStatsdTelemetry.cpp
index c8b2559..715f266 100644
--- a/runtime/test/TestWestworldTelemetry.cpp
+++ b/runtime/test/TestStatsdTelemetry.cpp
@@ -21,7 +21,7 @@
 #include <numeric>
 
 #include "Telemetry.h"
-#include "TelemetryWestworld.h"
+#include "TelemetryStatsd.h"
 
 namespace android::nn::telemetry {
 
@@ -98,18 +98,18 @@
     };
 }
 
-TEST(WestworldTelemetryTest, AtomKeyEquality) {
+TEST(StatsdTelemetryTest, AtomKeyEquality) {
     EXPECT_EQ(kExampleKey, kExampleKey);
 }
 
-TEST(WestworldTelemetryTest, AtomKeyLessThan) {
+TEST(StatsdTelemetryTest, AtomKeyLessThan) {
     const auto key1 = kExampleKey;
     auto key2 = key1;
     key2.errorCode = ANEURALNETWORKS_DEAD_OBJECT;
     EXPECT_LT(key1, key2);
 }
 
-TEST(WestworldTelemetryTest, CombineAtomValues) {
+TEST(StatsdTelemetryTest, CombineAtomValues) {
     AtomValue value1 = {
             .count = 3,
             .compilationTimeMillis = accumulatedTimingsFrom({50, 100, 150}),
@@ -127,7 +127,7 @@
     EXPECT_EQ(value1, valueResult);
 }
 
-TEST(WestworldTelemetryTest, CombineAtomValueWithLeftIdentity) {
+TEST(StatsdTelemetryTest, CombineAtomValueWithLeftIdentity) {
     AtomValue value1 = {};
     const AtomValue value2 = {
             .count = 1,
@@ -139,7 +139,7 @@
     EXPECT_EQ(value1, valueResult);
 }
 
-TEST(WestworldTelemetryTest, CombineAtomValueWithRightIdentity) {
+TEST(StatsdTelemetryTest, CombineAtomValueWithRightIdentity) {
     AtomValue value1 = {
             .count = 3,
             .compilationTimeMillis = accumulatedTimingsFrom({50, 100, 150}),
@@ -151,18 +151,18 @@
     EXPECT_EQ(value1, valueResult);
 }
 
-TEST(WestworldTelemetryTest, AtomAggregatorStartEmpty) {
+TEST(StatsdTelemetryTest, AtomAggregatorStartEmpty) {
     AtomAggregator aggregator;
     EXPECT_TRUE(aggregator.empty());
 }
 
-TEST(WestworldTelemetryTest, AtomAggregatorNotEmptyAfterPush) {
+TEST(StatsdTelemetryTest, AtomAggregatorNotEmptyAfterPush) {
     AtomAggregator aggregator;
     aggregator.push({kExampleKey, {}});
     EXPECT_FALSE(aggregator.empty());
 }
 
-TEST(WestworldTelemetryTest, AtomAggregatorEmptyAfterPop) {
+TEST(StatsdTelemetryTest, AtomAggregatorEmptyAfterPop) {
     AtomAggregator aggregator;
     aggregator.push({kExampleKey, {}});
     const auto [k, v] = aggregator.pop();
@@ -170,7 +170,7 @@
     EXPECT_EQ(k, kExampleKey);
 }
 
-TEST(WestworldTelemetryTest, AtomAggregatorTwoDifferentKeys) {
+TEST(StatsdTelemetryTest, AtomAggregatorTwoDifferentKeys) {
     const auto key1 = kExampleKey;
     auto key2 = key1;
     key2.executionMode = ExecutionMode::ASYNC;
@@ -188,7 +188,7 @@
     EXPECT_FALSE(aggregator.empty());
 }
 
-TEST(WestworldTelemetryTest, AtomAggregatorTwoSameKeys) {
+TEST(StatsdTelemetryTest, AtomAggregatorTwoSameKeys) {
     const auto key1 = kExampleKey;
     const auto value1 = AtomValue{.count = 2};
     const auto value2 = AtomValue{.count = 3};
@@ -204,7 +204,7 @@
     EXPECT_TRUE(aggregator.empty());
 }
 
-TEST(WestworldTelemetryTest, AtomAggregatorPush) {
+TEST(StatsdTelemetryTest, AtomAggregatorPush) {
     const AtomKey key1 = kExampleKey;
     AtomKey key2 = key1;
     key2.executionMode = ExecutionMode::ASYNC;
@@ -227,7 +227,7 @@
     EXPECT_TRUE(aggregator.empty());
 }
 
-TEST(WestworldTelemetryTest, AsyncLoggerTeardownWhileWaitingForData) {
+TEST(StatsdTelemetryTest, AsyncLoggerTeardownWhileWaitingForData) {
     constexpr auto fn = [](Atom&& /*atom*/) {};
     const auto start = Clock::now();
     { AsyncLogger logger(fn, kLongTime); }
@@ -235,7 +235,7 @@
     EXPECT_LT(elapsed, kLongTime);
 }
 
-TEST(WestworldTelemetryTest, AsyncLoggerTeardownDuringSleep) {
+TEST(StatsdTelemetryTest, AsyncLoggerTeardownDuringSleep) {
     Signal loggingOccurred;
     auto fn = [&loggingOccurred](Atom&& /*atom*/) mutable { loggingOccurred.signal(); };
 
@@ -250,7 +250,7 @@
     EXPECT_LT(elapsed, kLongTime);
 }
 
-TEST(WestworldTelemetryTest, AsyncLoggerVerifyQuietPeriod) {
+TEST(StatsdTelemetryTest, AsyncLoggerVerifyQuietPeriod) {
     std::atomic<uint32_t> count = 0;
     Signal loggingOccurred;
     const auto fn = [&count, &loggingOccurred](Atom&& /*atom*/) {
@@ -276,7 +276,7 @@
     EXPECT_EQ(count, 1u);
 }
 
-TEST(WestworldTelemetryTest, AsyncLoggerVerifyAllDataSent) {
+TEST(StatsdTelemetryTest, AsyncLoggerVerifyAllDataSent) {
     const uint32_t targetCount = ANEURALNETWORKS_DEAD_OBJECT - ANEURALNETWORKS_NO_ERROR + 1;
     std::atomic<uint32_t> count = 0;
     Signal allDataSent;
@@ -301,7 +301,7 @@
     EXPECT_EQ(count, targetCount);
 }
 
-TEST(WestworldTelemetryTest, createAtomFromCompilationInfoWhenNoError) {
+TEST(StatsdTelemetryTest, createAtomFromCompilationInfoWhenNoError) {
     const DiagnosticCompilationInfo info{
             .modelArchHash = kExampleModelArchHash.data(),
             .deviceId = kExampleDeviceId,
@@ -341,7 +341,7 @@
     EXPECT_EQ(value.durationHardwareMicros, kNoAggregateTiming);
 }
 
-TEST(WestworldTelemetryTest, createAtomFromCompilationInfoWhenError) {
+TEST(StatsdTelemetryTest, createAtomFromCompilationInfoWhenError) {
     const DiagnosticCompilationInfo info{
             .modelArchHash = kExampleModelArchHash.data(),
             .deviceId = kExampleDeviceId,
@@ -378,7 +378,7 @@
     EXPECT_EQ(value.durationHardwareMicros, kNoAggregateTiming);
 }
 
-TEST(WestworldTelemetryTest, createAtomFromExecutionInfoWhenNoError) {
+TEST(StatsdTelemetryTest, createAtomFromExecutionInfoWhenNoError) {
     const DiagnosticExecutionInfo info{
             .modelArchHash = kExampleModelArchHash.data(),
             .deviceId = kExampleDeviceId,
@@ -426,7 +426,7 @@
     EXPECT_EQ(value.durationHardwareMicros, durationHardwareMicros);
 }
 
-TEST(WestworldTelemetryTest, createAtomFromExecutionInfoWhenError) {
+TEST(StatsdTelemetryTest, createAtomFromExecutionInfoWhenError) {
     const DiagnosticExecutionInfo info{
             .modelArchHash = kExampleModelArchHash.data(),
             .deviceId = kExampleDeviceId,