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

Commit 48b856a3 authored by Ugo Yu's avatar Ugo Yu Committed by android-build-merger
Browse files

Merge "Print HwBinder thread performance to dumpsys"

am: c413fec5

Change-Id: I6901bfa16154557f89289863217f192a5018d77b
parents b4f5e640 c413fec5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@
#include "osi/include/osi.h"
#include "osi/include/wakelock.h"
#include "stack/gatt/connection_manager.h"
#include "stack/include/btu.h"
#include "stack_manager.h"

using bluetooth::hearing_aid::HearingAidInterface;
@@ -319,6 +320,7 @@ static void dump(int fd, const char** arguments) {
  btif_debug_av_dump(fd);
  bta_debug_av_dump(fd);
  stack_debug_avdtp_api_dump(fd);
  stack_debug_hwbinder_thread_dump(fd);
  bluetooth::avrcp::AvrcpService::DebugDump(fd);
  btif_debug_config_dump(fd);
  BTA_HfClientDumpStatistics(fd);
+65 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "btif/include/btif_common.h"
#include "common/message_loop_thread.h"
#include "common/once_timer.h"
#include "common/time_util.h"
#include "osi/include/osi.h"
#include "stack/btm/btm_int.h"
#include "stack/include/btu.h"
@@ -46,6 +47,39 @@
using bluetooth::common::MessageLoopThread;
using bluetooth::common::OnceTimer;

/* Define utils for HwBinder timer dumpsys */
typedef struct {
  uint64_t counter_5ms = 0;
  uint64_t counter_20ms = 0;
  uint64_t counter_50ms = 0;
  uint64_t counter_100ms = 0;
  uint64_t counter_250ms = 0;
  uint64_t counter_max_ms = 0;
  void addTime(uint64_t time) {
    if (time < 5) {
      counter_5ms++;
    } else if (time < 20) {
      counter_20ms++;
    } else if (time < 50) {
      counter_50ms++;
    } else if (time < 100) {
      counter_100ms++;
    } else if (time < 250) {
      counter_250ms++;
    } else {
      counter_max_ms++;
    }
  }
} hwbinder_timer_collector_t;

typedef struct {
  uint64_t start_time_ms;
  std::string from_here;
} hwbinder_timestamp_t;

std::map<std::string, hwbinder_timer_collector_t> timer_map;
hwbinder_timestamp_t hwbinder_timestamp;

/* Define BTU storage area */
uint8_t btu_trace_level = HCI_INITIAL_TRACE_LEVEL;

@@ -118,6 +152,10 @@ void main_thread_hwbinder_timer_start(const base::Location& from_here) {
          base::TimeDelta::FromMilliseconds(HWBINDER_TIMEOUT_MS))) {
    LOG(FATAL) << __func__ << ": failed from " << from_here.ToString();
  }

  hwbinder_timestamp.start_time_ms =
      bluetooth::common::time_get_os_boottime_ms();
  hwbinder_timestamp.from_here = from_here.ToString();
}

void main_thread_hwbinder_timer_stop() {
@@ -125,6 +163,33 @@ void main_thread_hwbinder_timer_stop() {
    LOG(FATAL) << __func__ << ": hwbinder_timer is not scheduled!";
  }
  hwbinder_timer.CancelAndWait();

  uint64_t delta_time = bluetooth::common::time_get_os_boottime_ms() -
                        hwbinder_timestamp.start_time_ms;
  auto it = timer_map.find(hwbinder_timestamp.from_here);
  if (it == timer_map.end()) {
    hwbinder_timer_collector_t collector;
    collector.addTime(delta_time);
    timer_map.emplace(hwbinder_timestamp.from_here, collector);
  } else {
    it->second.addTime(delta_time);
  }
}

void stack_debug_hwbinder_thread_dump(int fd) {
  dprintf(fd, "\nHwBinder Thread Timer:\n");
  for (auto it = timer_map.begin(); it != timer_map.end(); it++) {
    dprintf(fd, "  %s:\n", it->first.c_str());
    std::stringstream ss;
    ss << "    Invoke Counts (5ms/20ms/50ms/100ms/250ms/Over 250ms) : "
       << std::to_string(it->second.counter_5ms) << " / "
       << std::to_string(it->second.counter_20ms) << " / "
       << std::to_string(it->second.counter_50ms) << " / "
       << std::to_string(it->second.counter_100ms) << " / "
       << std::to_string(it->second.counter_250ms) << " / "
       << std::to_string(it->second.counter_max_ms);
    dprintf(fd, "%s\n", ss.str().c_str());
  }
}

void btu_task_start_up(UNUSED_ATTR void* context) {
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ bt_status_t do_in_main_thread(const base::Location& from_here,
                              base::OnceClosure task);
void main_thread_hwbinder_timer_start(const base::Location& from_here);
void main_thread_hwbinder_timer_stop();
void stack_debug_hwbinder_thread_dump(int fd);

void BTU_StartUp(void);
void BTU_ShutDown(void);