Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6620eaf authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "MediaMetrics: Prune audio analytics dump" into main

parents b98daa99 e4117009
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -555,22 +555,24 @@ status_t AudioAnalytics::submit(
}

std::pair<std::string, int32_t> AudioAnalytics::dump(
        int32_t lines, int64_t sinceNs, const char *prefix) const
        bool details, int32_t lines, int64_t sinceNs, const char *prefix) const
{
    std::stringstream ss;
    int32_t ll = lines;

    if (ll > 0) {
        auto [s, l] = mAnalyticsState->dump(ll, sinceNs, prefix);
        auto [s, l] = mAnalyticsState->dump(details, ll, sinceNs, prefix);
        ss << s;
        ll -= l;
    }
    if (ll > 0) {

    // use details to dump prior state.
    if (details && ll > 0) {
        ss << "Prior audioserver state:\n";
        --ll;
    }
    if (ll > 0) {
        auto [s, l] = mPreviousAnalyticsState->dump(ll, sinceNs, prefix);
    if (details && ll > 0) {
        auto [s, l] = mPreviousAnalyticsState->dump(details, ll, sinceNs, prefix);
        ss << s;
        ll -= l;
    }
+5 −7
Original line number Diff line number Diff line
@@ -49,12 +49,9 @@ using mediametrics::startsWith;
// (0 for either of these disables that threshold)
//
static constexpr nsecs_t kMaxRecordAgeNs = 28 * 3600 * NANOS_PER_SECOND;
// 2019/6: average daily per device is currently 375-ish;
// setting this to 2000 is large enough to catch most devices
// we'll lose some data on very very media-active devices, but only for
// the gms collection; statsd will have already covered those for us.
// This also retains enough information to help with bugreports
static constexpr size_t kMaxRecords = 2000;

// Max records to keep in queue which dump out for bugreports.
static constexpr size_t kMaxRecords = 2500;

// max we expire in a single call, to constrain how long we hold the
// mutex, which also constrains how long a client might wait.
@@ -311,7 +308,8 @@ status_t MediaMetricsService::dump(int fd, const Vector<String16>& args)

            // TODO: maybe consider a better way of dumping audio analytics info.
            const int32_t linesToDump = all ? INT32_MAX : 1000;
            auto [ dumpString, lines ] = mAudioAnalytics.dump(linesToDump, sinceNs, prefixptr);
            auto [ dumpString, lines ] = mAudioAnalytics.dump(
                    all, linesToDump, sinceNs, prefixptr);
            result << dumpString;
            if (lines == linesToDump) {
                result << "-- some lines may be truncated --\n";
+4 −3
Original line number Diff line number Diff line
@@ -83,11 +83,12 @@ public:
     * different locks, so may not be 100% consistent with the last data
     * delivered.
     *
     * \param details dumps the detailed internal state.
     * \param lines the maximum number of lines in the string returned.
     * \param sinceNs the nanoseconds since Unix epoch to start dump (0 shows all)
     * \param prefix the desired key prefix to match (nullptr shows all)
     */
    std::pair<std::string, int32_t> dump(
    std::pair<std::string, int32_t> dump(bool details,
            int32_t lines = INT32_MAX, int64_t sinceNs = 0, const char *prefix = nullptr) const {
        std::stringstream ss;
        int32_t ll = lines;
@@ -96,7 +97,7 @@ public:
            ss << "TransactionLog: gc(" << mTransactionLog.getGarbageCollectionCount() << ")\n";
            --ll;
        }
        if (ll > 0) {
        if (details && ll > 0) {
            auto [s, l] = mTransactionLog.dump(ll, sinceNs, prefix);
            ss << s;
            ll -= l;
@@ -105,7 +106,7 @@ public:
            ss << "TimeMachine: gc(" << mTimeMachine.getGarbageCollectionCount() << ")\n";
            --ll;
        }
        if (ll > 0) {
        if (details && ll > 0) {
            auto [s, l] = mTimeMachine.dump(ll, sinceNs, prefix);
            ss << s;
            ll -= l;
+2 −1
Original line number Diff line number Diff line
@@ -67,11 +67,12 @@ public:
     * different locks, so may not be 100% consistent with the last data
     * delivered.
     *
     * \param details dumps the detailed internal state.
     * \param lines the maximum number of lines in the string returned.
     * \param sinceNs the nanoseconds since Unix epoch to start dump (0 shows all)
     * \param prefix the desired key prefix to match (nullptr shows all)
     */
    std::pair<std::string, int32_t> dump(
    std::pair<std::string, int32_t> dump(bool details,
            int32_t lines = INT32_MAX, int64_t sinceNs = 0, const char *prefix = nullptr) const;

    /**
+6 −6
Original line number Diff line number Diff line
@@ -850,14 +850,14 @@ TEST(mediametrics_tests, audio_analytics_permission) {

  // TODO: Verify contents of AudioAnalytics.
  // Currently there is no getter API in AudioAnalytics besides dump.
  ASSERT_EQ(10, audioAnalytics.dump(1000).second /* lines */);
  ASSERT_EQ(10, audioAnalytics.dump(true /* details */, 1000).second /* lines */);

  ASSERT_EQ(NO_ERROR, audioAnalytics.submit(item, true /* isTrusted */));
  // untrusted entities can add to an existing key
  ASSERT_EQ(NO_ERROR, audioAnalytics.submit(item2, false /* isTrusted */));

  // Check that we have some info in the dump.
  ASSERT_LT(9, audioAnalytics.dump(1000).second /* lines */);
  ASSERT_LT(9, audioAnalytics.dump(true /* details */, 1000).second /* lines */);
}

TEST(mediametrics_tests, audio_analytics_permission2) {
@@ -888,14 +888,14 @@ TEST(mediametrics_tests, audio_analytics_permission2) {

  // TODO: Verify contents of AudioAnalytics.
  // Currently there is no getter API in AudioAnalytics besides dump.
  ASSERT_EQ(10, audioAnalytics.dump(1000).second /* lines */);
  ASSERT_EQ(10, audioAnalytics.dump(true /* details */, 1000).second /* lines */);

  ASSERT_EQ(NO_ERROR, audioAnalytics.submit(item, true /* isTrusted */));
  // untrusted entities can add to an existing key
  ASSERT_EQ(NO_ERROR, audioAnalytics.submit(item2, false /* isTrusted */));

  // Check that we have some info in the dump.
  ASSERT_LT(9, audioAnalytics.dump(1000).second /* lines */);
  ASSERT_LT(9, audioAnalytics.dump(true /* details */, 1000).second /* lines */);
}

TEST(mediametrics_tests, audio_analytics_dump) {
@@ -922,13 +922,13 @@ TEST(mediametrics_tests, audio_analytics_dump) {
  ASSERT_EQ(NO_ERROR, audioAnalytics.submit(item3, true /* isTrusted */));

  // find out how many lines we have.
  auto [string, lines] = audioAnalytics.dump(1000);
  auto [string, lines] = audioAnalytics.dump(true /* details */, 1000);
  ASSERT_EQ(lines, (int32_t) countNewlines(string.c_str()));

  printf("AudioAnalytics: %s", string.c_str());
  // ensure that dump operates over those lines.
  for (int32_t ll = 0; ll < lines; ++ll) {
      auto [s, l] = audioAnalytics.dump(ll);
      auto [s, l] = audioAnalytics.dump(true /* details */, ll);
      ASSERT_EQ(ll, l);
      ASSERT_EQ(ll, (int32_t) countNewlines(s.c_str()));
  }