OSDN Git Service

shim: Add l2cap per-channel network transfer metrics
authorChris Manton <cmanton@google.com>
Fri, 30 Apr 2021 17:23:27 +0000 (10:23 -0700)
committerChris Manton <cmanton@google.com>
Tue, 4 May 2021 20:37:14 +0000 (13:37 -0700)
Bug: 183374320
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I25bb743c6f9052b93a1bb8c663033c22e2bd16a8

stack/l2cap/l2c_csm.cc
stack/l2cap/l2c_int.h
stack/l2cap/l2c_main.cc

index 7cd5845..07d1d92 100644 (file)
@@ -1098,16 +1098,19 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
           p_ccb->local_cid <= L2CAP_LAST_FIXED_CHNL) {
         if (p_ccb->local_cid < L2CAP_BASE_APPL_CID) {
           if (l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL]
-                  .pL2CA_FixedData_Cb)
+                  .pL2CA_FixedData_Cb != nullptr) {
+            p_ccb->metrics.rx(static_cast<BT_HDR*>(p_data)->len);
             (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL]
                   .pL2CA_FixedData_Cb)(p_ccb->local_cid,
                                        p_ccb->p_lcb->remote_bd_addr,
                                        (BT_HDR*)p_data);
-          else
-            osi_free(p_data);
+          } else {
+            if (p_data != nullptr) osi_free_and_reset(&p_data);
+          }
           break;
         }
       }
+      if (p_data) p_ccb->metrics.rx(static_cast<BT_HDR*>(p_data)->len);
       (*p_ccb->p_rcb->api.pL2CA_DataInd_Cb)(p_ccb->local_cid, (BT_HDR*)p_data);
       break;
 
@@ -1244,9 +1247,11 @@ static void l2c_csm_open(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
       break;
 
     case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd    */
-      if ((p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_DataInd_Cb))
+      if ((p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_DataInd_Cb)) {
+        p_ccb->metrics.rx(static_cast<BT_HDR*>(p_data)->len);
         (*p_ccb->p_rcb->api.pL2CA_DataInd_Cb)(p_ccb->local_cid,
                                               (BT_HDR*)p_data);
+      }
       break;
 
     case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */
@@ -1543,6 +1548,10 @@ static const char* l2c_csm_get_event_name(tL2CEVT event) {
  *
  ******************************************************************************/
 void l2c_enqueue_peer_data(tL2C_CCB* p_ccb, BT_HDR* p_buf) {
+  CHECK(p_ccb != nullptr);
+
+  p_ccb->metrics.tx(p_buf->len);
+
   uint8_t* p;
 
   if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) {
index 4b1e7e5..7898e3f 100644 (file)
@@ -352,6 +352,28 @@ typedef struct t_l2c_ccb {
   /* used to indicate that ECOC is used */
   bool ecoc{false};
   bool reconfig_started;
+
+  struct {
+    struct {
+      unsigned bytes{0};
+      unsigned packets{0};
+      void operator()(unsigned bytes) {
+        this->bytes += bytes;
+        this->packets++;
+      }
+    } rx, tx;
+    struct {
+      struct {
+        unsigned bytes{0};
+        unsigned packets{0};
+        void operator()(unsigned bytes) {
+          this->bytes += bytes;
+          this->packets++;
+        }
+      } rx, tx;
+    } dropped;
+  } metrics;
+
 } tL2C_CCB;
 
 /***********************************************************************
index d77242c..003c8fb 100644 (file)
@@ -199,6 +199,7 @@ void l2c_rcv_acl_data(BT_HDR* p_msg) {
 
     /* If no CCB for this channel, allocate one */
     p_ccb = p_lcb->p_fixed_ccbs[rcv_cid - L2CAP_FIRST_FIXED_CHNL];
+    p_ccb->metrics.rx(p_msg->len);
 
     if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE)
       l2c_fcr_proc_pdu(p_ccb, p_msg);