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

Commit beab6511 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "IsoManager: Add additional statistics" am: 8b48d18d am: 9f11803d am: 464084ed

parents be309025 464084ed
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
@@ -63,6 +63,21 @@ struct iso_base {
  std::atomic_uint8_t state_flags;
  uint32_t sdu_itv;
  std::atomic_uint16_t used_credits;

  struct credits_stats {
    size_t credits_underflow_bytes = 0;
    size_t credits_underflow_count = 0;
    uint64_t credits_last_underflow_us = 0;
  };

  struct event_stats {
    size_t evt_lost_count = 0;
    size_t seq_nb_mismatch_count = 0;
    uint64_t evt_last_lost_us = 0;
  };

  credits_stats cr_stats;
  event_stats evt_stats;
};

typedef iso_base iso_cis;
@@ -435,6 +450,11 @@ struct iso_impl {
    iso->sync_info.seq_nb = (ts - iso->sync_info.first_sync_ts) / iso->sdu_itv;

    if (iso_credits_ == 0 || data_len > iso_buffer_size_) {
      iso->cr_stats.credits_underflow_bytes += data_len;
      iso->cr_stats.credits_underflow_count++;
      iso->cr_stats.credits_last_underflow_us =
          bluetooth::common::time_get_os_boottime_us();

      LOG(WARNING) << __func__ << ", dropping ISO packet, len: "
                   << static_cast<int>(data_len)
                   << ", iso credits: " << static_cast<int>(iso_credits_)
@@ -714,6 +734,10 @@ struct iso_impl {
    } else {
      evt.evt_lost = new_calc_seq_nb - iso->sync_info.seq_nb - 1;
      if (evt.evt_lost > 0) {
        iso->evt_stats.evt_lost_count += evt.evt_lost;
        iso->evt_stats.evt_last_lost_us =
            bluetooth::common::time_get_os_boottime_us();

        LOG(WARNING) << evt.evt_lost << " packets possibly lost.";
      }

@@ -722,6 +746,8 @@ struct iso_impl {
                        "Adjusting own time reference point.";
        iso->sync_info.first_sync_ts = ts - (seq_nb * iso->sdu_itv);
        new_calc_seq_nb = seq_nb;

        iso->evt_stats.seq_nb_mismatch_count++;
      }
    }
    iso->sync_info.seq_nb = new_calc_seq_nb;
@@ -767,6 +793,35 @@ struct iso_impl {
    return (bis_it != conn_hdl_to_bis_map_.cend());
  }

  static void dump_credits_stats(int fd, const iso_base::credits_stats& stats) {
    uint64_t now_us = bluetooth::common::time_get_os_boottime_us();

    dprintf(fd, "        Credits Stats:\n");
    dprintf(fd, "          Credits underflow (count): %zu\n",
            stats.credits_underflow_count);
    dprintf(fd, "          Credits underflow (bytes): %zu\n",
            stats.credits_underflow_bytes);
    dprintf(
        fd, "          Last underflow time ago (ms): %llu\n",
        (stats.credits_last_underflow_us > 0
             ? (unsigned long long)(now_us - stats.credits_last_underflow_us) /
                   1000
             : 0llu));
  }

  static void dump_event_stats(int fd, const iso_base::event_stats& stats) {
    uint64_t now_us = bluetooth::common::time_get_os_boottime_us();

    dprintf(fd, "        Event Stats:\n");
    dprintf(fd, "          Sequence number mismatch (count): %zu\n",
            stats.seq_nb_mismatch_count);
    dprintf(fd, "          Event lost (count): %zu\n", stats.evt_lost_count);
    dprintf(fd, "          Last event lost time ago (ms): %llu\n",
            (stats.evt_last_lost_us > 0
                 ? (unsigned long long)(now_us - stats.evt_last_lost_us) / 1000
                 : 0llu));
  }

  void dump(int fd) const {
    dprintf(fd, "  ----------------\n ");
    dprintf(fd, "  ISO Manager:\n");
@@ -781,6 +836,8 @@ struct iso_impl {
      dprintf(fd, "        SDU Interval: %d\n", cis_pair.second->sdu_itv);
      dprintf(fd, "        State Flags: 0x%02hx\n",
              cis_pair.second->state_flags.load());
      dump_credits_stats(fd, cis_pair.second->cr_stats);
      dump_event_stats(fd, cis_pair.second->evt_stats);
    }
    dprintf(fd, "    BISes:\n");
    for (auto const& cis_pair : conn_hdl_to_bis_map_) {
@@ -791,6 +848,8 @@ struct iso_impl {
      dprintf(fd, "        SDU Interval: %d\n", cis_pair.second->sdu_itv);
      dprintf(fd, "        State Flags: 0x%02hx\n",
              cis_pair.second->state_flags.load());
      dump_credits_stats(fd, cis_pair.second->cr_stats);
      dump_event_stats(fd, cis_pair.second->evt_stats);
    }
    dprintf(fd, "  ----------------\n ");
  }