From patchwork Tue Aug 1 23:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13337347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72B7AEB64DD for ; Tue, 1 Aug 2023 23:21:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229906AbjHAXVm (ORCPT ); Tue, 1 Aug 2023 19:21:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbjHAXVk (ORCPT ); Tue, 1 Aug 2023 19:21:40 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 868472103 for ; Tue, 1 Aug 2023 16:21:38 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-686b643df5dso4426267b3a.1 for ; Tue, 01 Aug 2023 16:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932097; x=1691536897; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=qJ6YRW/+NBQYYZauJ1pKe2cpcAAs1iTDa7rLKeHdW6k=; b=jNRpF089QA/ZiNCEAegP22R2mnGtGPW+XsA7R6kY/h7AAQW8DgVEjAZClH19IAV4rr CWlcr2WmGuagCzCknw20T2xLww6BOjUag16mwmgdynS+ESrG+RDhHVry22CxwWlxeP12 auNvH+jGkbU8XSKMHWvYwH8sxAgptpbe7Oem9sSeGUHNZ6AYdTu63dtfa1XWbvkfhn7O FYKUkgnxVyM0LciHyv1Xv7mXbVj5XGea1KoCN2XCoLrpf1rAK6ikQjXSyu3hmhG6137O mJS9IVh/y/iuMKbYtyUV4vDbW3r77WBeLb99ZA1+3WVbuYLofGIwWFzO6ZfXd1J33Jsd hzZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932097; x=1691536897; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qJ6YRW/+NBQYYZauJ1pKe2cpcAAs1iTDa7rLKeHdW6k=; b=CDy6tLEZeV1yB6nn1mIFvgeKQMZz+VvJC1I6ouTD096U3Cms4iXFZO8b+oFdzWKWh3 T9Nh6Hj36NKmQ4sDDIUiuEFnL7zwsQ1/SuymxLEsUSYL1YfS5tDEWbFJ+aGxtUcra6OO SnulQMXZuoWpaqowXEZ2o3ogh2u/f2yDicyjbJViQ3f1+OOwmZOafheZlHBG33Sg4/DP +Ja7E8I1iNnE3urfO4yY8GL0bse8RjGKZ1xNKB6u2KIViiTbpn3wKObXPJ+XdRJuWE8x MP/hZ/c8jFy0QkP0pn7r4mULQtU5qcT7gno3OevCxJ2c0wXTlRmw8CpGtxTEtQhIfGS9 ujaw== X-Gm-Message-State: ABy/qLbQWHaasyNRvzmBYhznf+N1YFDDEihYz19EbM/KEug6glRmkfgf ins+Pdncd2/G9DIvMJINhdJYdKvvi20= X-Google-Smtp-Source: APBJJlHRhsdxKMv4KMTLfS46yPrparet9ffSedGAYAJMH0c+TnZaQxOoPtC36ZFW/Zr7lc5WGjTFRg== X-Received: by 2002:a05:6a00:1785:b0:679:bc89:e45 with SMTP id s5-20020a056a00178500b00679bc890e45mr16554303pfg.6.1690932097193; Tue, 01 Aug 2023 16:21:37 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id fk25-20020a056a003a9900b00682a8e600f0sm9856157pfb.35.2023.08.01.16.21.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:21:36 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 1/5] monitor: Add TX frame number and speed estimation Date: Tue, 1 Aug 2023 16:21:31 -0700 Message-ID: <20230801232135.535733-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds the frame information while decoding: > HCI Event: Number of Completed Packets (0x13) plen 5 Num handles: 1 Handle: 256 Address: XX:XX:XX:XX:XX:XX Count: 1 #188: len 850 (755 Kb/s) Latency: 9 msec (3-21 msec ~6 msec) Channel: 68 [PSM 25 mode Basic (0x00)] {chan 4} Channel Latency: 9 msec (7-21 msec ~9 msec) Or the speed estimation while analyzing: Found BR-ACL connection with handle 256 Address: XX:XX:XX:XX:XX:XX 60 RX packets 22548 TX packets 22547 TX completed packets 3-73 msec (~11 msec) TX Latency 6-850 octets (~847 octets) TX packet size ~568 Kb/s TX transfer speed --- monitor/analyze.c | 2 ++ monitor/packet.c | 37 ++++++++++++++++++++++++------------- monitor/packet.h | 7 +++++++ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index b4a7cf726ac9..db026190701d 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -226,6 +226,8 @@ static void conn_destroy(void *data) TV_MSEC(conn->tx_l.med)); print_field("%u-%u octets (~%u octets) TX packet size", conn->tx_pkt_min, conn->tx_pkt_max, conn->tx_pkt_med); + print_field("~%lld Kb/s TX transfer speed", + conn->tx_bytes * 8 / TV_MSEC(conn->tx_l.total)); plot_draw(conn->plot); diff --git a/monitor/packet.c b/monitor/packet.c index fb469cdeafed..84af03a0011f 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -10397,6 +10397,8 @@ static void role_change_evt(struct timeval *tv, uint16_t index, void packet_latency_add(struct packet_latency *latency, struct timeval *delta) { + timeradd(&latency->total, delta, &latency->total); + if ((!timerisset(&latency->min) || timercmp(delta, &latency->min, <)) && delta->tv_sec >= 0 && delta->tv_usec >= 0) latency->min = *delta; @@ -10427,28 +10429,30 @@ void packet_latency_add(struct packet_latency *latency, struct timeval *delta) static void packet_dequeue_tx(struct timeval *tv, uint16_t handle) { struct packet_conn_data *conn; - struct timeval *tx; + struct packet_frame *frame; struct timeval delta; conn = packet_get_conn_data(handle); if (!conn) return; - tx = queue_pop_head(conn->tx_q); - if (!tx) + frame = queue_pop_head(conn->tx_q); + if (!frame) return; - timersub(tv, tx, &delta); + timersub(tv, &frame->tv, &delta); packet_latency_add(&conn->tx_l, &delta); + print_field("#%zu: len %zu (%lld Kb/s)", frame->num, frame->len, + frame->len * 8 / TV_MSEC(delta)); print_field("Latency: %lld msec (%lld-%lld msec ~%lld msec)", TV_MSEC(delta), TV_MSEC(conn->tx_l.min), TV_MSEC(conn->tx_l.max), TV_MSEC(conn->tx_l.med)); l2cap_dequeue_frame(&delta, conn); - free(tx); + free(frame); } static void num_completed_packets_evt(struct timeval *tv, uint16_t index, @@ -12442,10 +12446,11 @@ void packet_hci_event(struct timeval *tv, struct ucred *cred, uint16_t index, event_data->func(tv, index, data, hdr->plen); } -static void packet_queue_tx(struct timeval *tv, uint16_t handle) +static void packet_enqueue_tx(struct timeval *tv, uint16_t handle, + size_t num, uint16_t len) { struct packet_conn_data *conn; - struct timeval *tx; + struct packet_frame *frame; conn = packet_get_conn_data(handle); if (!conn) @@ -12454,9 +12459,12 @@ static void packet_queue_tx(struct timeval *tv, uint16_t handle) if (!conn->tx_q) conn->tx_q = queue_new(); - tx = new0(struct timeval, 1); - memcpy(tx, tv, sizeof(*tv)); - queue_push_tail(conn->tx_q, tx); + frame = new0(struct packet_frame, 1); + if (tv) + memcpy(&frame->tv, tv, sizeof(*tv)); + frame->num = num; + frame->len = len; + queue_push_tail(conn->tx_q, frame); } void packet_hci_acldata(struct timeval *tv, struct ucred *cred, uint16_t index, @@ -12497,7 +12505,8 @@ void packet_hci_acldata(struct timeval *tv, struct ucred *cred, uint16_t index, handle_str, extra_str); if (!in) - packet_queue_tx(tv, acl_handle(handle)); + packet_enqueue_tx(tv, acl_handle(handle), + index_list[index].frame, dlen); if (size != dlen) { print_text(COLOR_ERROR, "invalid packet size (%d != %d)", @@ -12549,7 +12558,8 @@ void packet_hci_scodata(struct timeval *tv, struct ucred *cred, uint16_t index, handle_str, extra_str); if (!in) - packet_queue_tx(tv, acl_handle(handle)); + packet_enqueue_tx(tv, acl_handle(handle), + index_list[index].frame, hdr->dlen); if (size != hdr->dlen) { print_text(COLOR_ERROR, "invalid packet size (%d != %d)", @@ -12599,7 +12609,8 @@ void packet_hci_isodata(struct timeval *tv, struct ucred *cred, uint16_t index, handle_str, extra_str); if (!in) - packet_queue_tx(tv, acl_handle(handle)); + packet_enqueue_tx(tv, acl_handle(handle), + index_list[index].frame, hdr->dlen); if (size != hdr->dlen) { print_text(COLOR_ERROR, "invalid packet size (%d != %d)", diff --git a/monitor/packet.h b/monitor/packet.h index 12cb68d508f8..750ce405e4bc 100644 --- a/monitor/packet.h +++ b/monitor/packet.h @@ -26,11 +26,18 @@ #define TV_MSEC(_tv) (long long)((_tv).tv_sec * 1000 + (_tv).tv_usec / 1000) struct packet_latency { + struct timeval total; struct timeval min; struct timeval max; struct timeval med; }; +struct packet_frame { + struct timeval tv; + size_t num; + size_t len; +}; + struct packet_conn_data { uint16_t index; uint8_t src[6]; From patchwork Tue Aug 1 23:21:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13337348 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 037DCC00528 for ; Tue, 1 Aug 2023 23:21:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231330AbjHAXVp (ORCPT ); Tue, 1 Aug 2023 19:21:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231334AbjHAXVn (ORCPT ); Tue, 1 Aug 2023 19:21:43 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE5C426A6 for ; Tue, 1 Aug 2023 16:21:40 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-686b9920362so4478485b3a.1 for ; Tue, 01 Aug 2023 16:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932099; x=1691536899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=lSvZQzyPYO9K+Yy/xJPLeAc8DQcrhOgj51xCbnGnWEw=; b=F7RhJ/foWlrk12xrL7DmCYobY2RtS7ALxIMmrpoVJVaTzNFf0g5j0svFeu3O5veTC6 gw2N252v3xgMnvNNrZ9q7doAYIrQA3zbO+CsXZX+0VPZC3KaJ/3o7x/c16ehhog/2DzE 6pkyN9UXmqRs/UJQO2Fc9HDMZlV8YGa8zDYxkQ/qCVcCWg/2a3iscLTnSLIxUN/bbE8R m+IFiPlczXS4qTVWU0yr72VS8id5+a/Fh7xJR0me/hQYMBxoE9s4Z4MioQHiQahkq9lm 2a06n3jKNE8+ibxnNndCydMc6ojnoAxnJnf0WUpL1noAIFQihL+O8fL8cMmKPXL8jGTn dnvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932099; x=1691536899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lSvZQzyPYO9K+Yy/xJPLeAc8DQcrhOgj51xCbnGnWEw=; b=NLngzsvs1ZvHy/fL7htmLeblLWqBR6nbz9u77lH0suOivw6BgwqySf1ZopGSdPixuD RW7DlrWae2bkEDxOo5P6wZj8pCdEs27INZy2YBZZstL46GjF0JOBS7Tu7ORZCdFV9Arj +oGANcA1bLsN4M3kVt6hAHVtfi4yjWsGQirdsqngYDNDz7CXwxnepQjL2ulUbVZ/BByB r90kUkW08VjCIk8Rn2ZvLnIIh41D7iG/dZr1AQAQD7Ss4qe74NeIOliaLEm+yJMTGK/u hoDvKESqENMkFClgNHd24/sPEimO3tmIYuQErtJMvxzXiGrn+VwehnXJnYGjDxrA5OaG ncTw== X-Gm-Message-State: ABy/qLYNmS+IJjSieD//l8M5IAFx/GKlKqF2sNmRrMHcpoS6qRSBGSor Uj4z0F8SqgxZR7bXeDhAIYB83Rtd/+o= X-Google-Smtp-Source: APBJJlEy4vlAUbzh4YUOSmuhX9XPCcbWjgIAajJm2iFdflg8lRFhivUPzdI+n3VIDJfbjNRfCsB/fQ== X-Received: by 2002:a05:6a00:1687:b0:668:83b7:fd02 with SMTP id k7-20020a056a00168700b0066883b7fd02mr17240699pfc.31.1690932099016; Tue, 01 Aug 2023 16:21:39 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id fk25-20020a056a003a9900b00682a8e600f0sm9856157pfb.35.2023.08.01.16.21.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:21:37 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 2/5] monitor/analyze: Use conn_pkt_tx on acl_pkt Date: Tue, 1 Aug 2023 16:21:32 -0700 Message-ID: <20230801232135.535733-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801232135.535733-1-luiz.dentz@gmail.com> References: <20230801232135.535733-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes use of conn_pkt_tx also on acl_pkt like other connections. --- monitor/analyze.c | 49 ++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index db026190701d..a016e26e31ac 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -600,6 +600,24 @@ static void event_pkt(struct timeval *tv, uint16_t index, } } +static void conn_pkt_tx(struct hci_conn *conn, struct timeval *tv, + uint16_t size) +{ + struct timeval *last_tx; + + conn->tx_num++; + + last_tx = new0(struct timeval, 1); + memcpy(last_tx, tv, sizeof(*tv)); + queue_push_tail(conn->tx_queue, last_tx); + conn->tx_bytes += size; + + if (!conn->tx_pkt_min || size < conn->tx_pkt_min) + conn->tx_pkt_min = size; + if (!conn->tx_pkt_max || size > conn->tx_pkt_max) + conn->tx_pkt_max = size; +} + static void acl_pkt(struct timeval *tv, uint16_t index, bool out, const void *data, uint16_t size) { @@ -637,39 +655,12 @@ static void acl_pkt(struct timeval *tv, uint16_t index, bool out, } if (out) { - struct timeval *last_tx; - - conn->tx_num++; - last_tx = new0(struct timeval, 1); - memcpy(last_tx, tv, sizeof(*tv)); - queue_push_tail(conn->tx_queue, last_tx); - conn->tx_bytes += size; - - if (!conn->tx_pkt_min || size < conn->tx_pkt_min) - conn->tx_pkt_min = size; - if (!conn->tx_pkt_max || size > conn->tx_pkt_max) - conn->tx_pkt_max = size; + conn_pkt_tx(conn, tv, size); } else { conn->rx_num++; } } -static void conn_pkt_tx(struct hci_conn *conn, struct timeval *tv, - uint16_t size) -{ - struct timeval *last_tx; - - last_tx = new0(struct timeval, 1); - memcpy(last_tx, tv, sizeof(*tv)); - queue_push_tail(conn->tx_queue, last_tx); - conn->tx_bytes += size; - - if (!conn->tx_pkt_min || size < conn->tx_pkt_min) - conn->tx_pkt_min = size; - if (!conn->tx_pkt_max || size > conn->tx_pkt_max) - conn->tx_pkt_max = size; -} - static void sco_pkt(struct timeval *tv, uint16_t index, bool out, const void *data, uint16_t size) { @@ -690,7 +681,6 @@ static void sco_pkt(struct timeval *tv, uint16_t index, bool out, return; if (out) { - conn->tx_num++; conn_pkt_tx(conn, tv, size - sizeof(*hdr)); } else { conn->rx_num++; @@ -778,7 +768,6 @@ static void iso_pkt(struct timeval *tv, uint16_t index, bool out, return; if (out) { - conn->tx_num++; conn_pkt_tx(conn, tv, size - sizeof(*hdr)); } else { conn->rx_num++; From patchwork Tue Aug 1 23:21:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13337349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD111EB64DD for ; Tue, 1 Aug 2023 23:21:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230249AbjHAXVr (ORCPT ); Tue, 1 Aug 2023 19:21:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbjHAXVp (ORCPT ); Tue, 1 Aug 2023 19:21:45 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32AE3269A for ; Tue, 1 Aug 2023 16:21:43 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-686f94328a4so233659b3a.0 for ; Tue, 01 Aug 2023 16:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932101; x=1691536901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=qGdN2bLVyroX7eOEJoTxXxLAwDoSogPhY6dWkJKYs4U=; b=aanq8ahmlrIRNr+UMYnkqq990pIcZLhrPRiqRneKLUjyczsZEwvsHJu/ONKYd/ZGqa k5pIvHa2NL1Yzl/KjnPqFTeLpr9Q4b1U73h1dS41FdFemYvTUQl6PN7gUkD/lomAnPVu nlcvONQDNaPtFnA/59HUZcw/scj85mKoQG5+7zLlpLwA01g/33wYg1598pZTiE8/Xjyk wkQf7T3zThxu0Fc29pvqTwTalLxOgLsM4K0+TSF+iBXPEzuOHQugv5+9EvfTIe1twD9C NQlRKDLHz8ekz2tEIqS4OYQgSheSKcxyYqIAcZJ/mzMvdRazcQ+F8iSwStDLc3kvVsZS eV5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932101; x=1691536901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qGdN2bLVyroX7eOEJoTxXxLAwDoSogPhY6dWkJKYs4U=; b=FbcvXqPIOzG8CPSCMNgn+f12Eb72R8BfTatdgIkg9qihcVzQYb4veNSfVHp8/u58wm Oi6PLH25JM7n8qv6s2V4LQN+NRX52mPF9T/HdJQkSgEBC24cXka9migyjaWFTQXUxDBS NWuXsOzUCiq25z2KWlma5DpQ3qUVs2j4mH3Nm1Ovwc+hEBCbmJJzRCy84prZ9Pq9Anz9 BAEJVyRi7cs7YWdv81FsRqow2Sbu2flSHbv/G/dcHfRYlcL0tRyxhpi4piddStr2lGXp 03Uh1MYPb0Sl5mAsDqr8ShYYSFSD7rKd4K6P3OMsyaYeNlg3Y/o/X0yPvNxDza9AP17F lRrw== X-Gm-Message-State: ABy/qLauvn7glwkKwo8VaHrzD6uZxNhTuvyB0x2uxIH6AhX/DqmXbnRb 1ui3suAnA8v9EN78WBAR42yitEkD6EM= X-Google-Smtp-Source: APBJJlHdeJ3FcBTKdwWhlwhrrbUBMsvQIAyzY3UNAnV89Kt8QLMQHKupmKVCZMj3XLuYTNs7zfl9wA== X-Received: by 2002:a05:6a00:847:b0:67a:52a7:b278 with SMTP id q7-20020a056a00084700b0067a52a7b278mr18575166pfk.9.1690932101358; Tue, 01 Aug 2023 16:21:41 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id fk25-20020a056a003a9900b00682a8e600f0sm9856157pfb.35.2023.08.01.16.21.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:21:39 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 3/5] monitor: Print channel latency information with -a/--analyze Date: Tue, 1 Aug 2023 16:21:33 -0700 Message-ID: <20230801232135.535733-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801232135.535733-1-luiz.dentz@gmail.com> References: <20230801232135.535733-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This prints channel latency information and use gnuplot when using -a/--analyze to plot a graph of channels: Found TX L2CAP channel with CID 68 PSM 25 22490 packets 7-50 msec (~11 msec) TX Latency 850-850 octets TX packet size ~569 Kb/s TX transfer speed 10000 +-+----------------------------------------------------------------+ +| ++ | +| || + Packets +-----+ | +| + || | | 1000 +-| | || |+ ++ | +| | || || || + | +| | || || ||+ +| | +| | || || ||| || ++ ++ | 100 +-| | || || ||| || || || + | +| | || || ||| || || || ++| + + | +| | || || ||| || || || ||| | | | +| | || || ||| || || || ||| |+ +| + | | | || || ||| || || || ||| || || |+ + | 10 +-| | || || ||| || || || ||| || || || |+ | +| | || || ||| || || || ||| || || || || + | +| +| || || ||| || || || ||| || || || ||+ ++ |+ ++ + | | || || || ||| || || || ||| || || || ||| || || || | | 1 +-| || || || ||| || || || ||| || || || ||| || || || | + + | ++----------------------------------------------------------------+ + + + + + + + + + + 5 10 15 20 25 30 35 40 45 50 Latency (ms) --- monitor/analyze.c | 169 +++++++++++++++++++++++++++++----------------- 1 file changed, 107 insertions(+), 62 deletions(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index a016e26e31ac..89b0382825dc 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -78,6 +78,11 @@ struct hci_conn { struct queue *chan_list; }; +struct hci_conn_tx { + struct timeval tv; + struct l2cap_chan *chan; +}; + struct plot { long long x_msec; size_t y_count; @@ -88,61 +93,15 @@ struct l2cap_chan { uint16_t psm; bool out; unsigned long num; + size_t tx_bytes; + struct packet_latency tx_l; + struct queue *plot; + uint16_t tx_pkt_min; + uint16_t tx_pkt_max; }; static struct queue *dev_list; -static void chan_destroy(void *data) -{ - struct l2cap_chan *chan = data; - - printf(" Found %s L2CAP channel with CID %u\n", - chan->out ? "TX" : "RX", chan->cid); - if (chan->psm) - printf(" PSM %u\n", chan->psm); - printf(" %lu packets\n", chan->num); - - free(chan); -} - -static struct l2cap_chan *chan_alloc(struct hci_conn *conn, uint16_t cid, - bool out) -{ - struct l2cap_chan *chan; - - chan = new0(struct l2cap_chan, 1); - - chan->cid = cid; - chan->out = out; - - return chan; -} - -static bool chan_match_cid(const void *a, const void *b) -{ - const struct l2cap_chan *chan = a; - uint32_t val = PTR_TO_UINT(b); - uint16_t cid = val & 0xffff; - bool out = val & 0x10000; - - return chan->cid == cid && chan->out == out; -} - -static struct l2cap_chan *chan_lookup(struct hci_conn *conn, uint16_t cid, - bool out) -{ - struct l2cap_chan *chan; - uint32_t val = cid | (out ? 0x10000 : 0); - - chan = queue_find(conn->chan_list, chan_match_cid, UINT_TO_PTR(val)); - if (!chan) { - chan = chan_alloc(conn, cid, out); - queue_push_tail(conn->chan_list, chan); - } - - return chan; -} - static void tmp_write(void *data, void *user_data) { struct plot *plot = data; @@ -184,6 +143,74 @@ done: unlink(filename); } +static void chan_destroy(void *data) +{ + struct l2cap_chan *chan = data; + + printf(" Found %s L2CAP channel with CID %u\n", + chan->out ? "TX" : "RX", chan->cid); + if (chan->psm) + print_field("PSM %u", chan->psm); + + print_field("%lu packets", chan->num); + + if (!queue_isempty(chan->plot)) { + print_field("%lld-%lld msec (~%lld msec) TX Latency", + TV_MSEC(chan->tx_l.min), TV_MSEC(chan->tx_l.max), + TV_MSEC(chan->tx_l.med)); + print_field("%u-%u octets TX packet size", + chan->tx_pkt_min, chan->tx_pkt_max); + } + + if (TV_MSEC(chan->tx_l.total)) + print_field("~%lld Kb/s TX transfer speed", + chan->tx_bytes * 8 / TV_MSEC(chan->tx_l.total)); + + if (chan->num > 1) + plot_draw(chan->plot); + + free(chan); +} + +static struct l2cap_chan *chan_alloc(struct hci_conn *conn, uint16_t cid, + bool out) +{ + struct l2cap_chan *chan; + + chan = new0(struct l2cap_chan, 1); + + chan->cid = cid; + chan->out = out; + chan->plot = queue_new(); + + return chan; +} + +static bool chan_match_cid(const void *a, const void *b) +{ + const struct l2cap_chan *chan = a; + uint32_t val = PTR_TO_UINT(b); + uint16_t cid = val & 0xffff; + bool out = val & 0x10000; + + return chan->cid == cid && chan->out == out; +} + +static struct l2cap_chan *chan_lookup(struct hci_conn *conn, uint16_t cid, + bool out) +{ + struct l2cap_chan *chan; + uint32_t val = cid | (out ? 0x10000 : 0); + + chan = queue_find(conn->chan_list, chan_match_cid, UINT_TO_PTR(val)); + if (!chan) { + chan = chan_alloc(conn, cid, out); + queue_push_tail(conn->chan_list, chan); + } + + return chan; +} + static void conn_destroy(void *data) { struct hci_conn *conn = data; @@ -506,9 +533,11 @@ static void plot_add(struct queue *queue, struct timeval *latency, { struct plot *plot; - plot = queue_find(queue, match_plot_latency, latency); + /* Use LRU ordering */ + plot = queue_remove_if(queue, match_plot_latency, latency); if (plot) { plot->y_count += count; + queue_push_head(queue, plot); return; } @@ -533,7 +562,7 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv, uint16_t count = get_le16(data + 2); struct hci_conn *conn; struct timeval res; - struct timeval *last_tx; + struct hci_conn_tx *last_tx; int j; data += 4; @@ -548,11 +577,17 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv, for (j = 0; j < count; j++) { last_tx = queue_pop_head(conn->tx_queue); if (last_tx) { - timersub(tv, last_tx, &res); + struct l2cap_chan *chan = last_tx->chan; + + timersub(tv, &last_tx->tv, &res); packet_latency_add(&conn->tx_l, &res); + plot_add(conn->plot, &res, 1); - plot_add(conn->plot, &res, count); + if (chan) { + packet_latency_add(&chan->tx_l, &res); + plot_add(chan->plot, &res, 1); + } free(last_tx); } @@ -601,14 +636,15 @@ static void event_pkt(struct timeval *tv, uint16_t index, } static void conn_pkt_tx(struct hci_conn *conn, struct timeval *tv, - uint16_t size) + uint16_t size, struct l2cap_chan *chan) { - struct timeval *last_tx; + struct hci_conn_tx *last_tx; conn->tx_num++; - last_tx = new0(struct timeval, 1); + last_tx = new0(struct hci_conn_tx, 1); memcpy(last_tx, tv, sizeof(*tv)); + last_tx->chan = chan; queue_push_tail(conn->tx_queue, last_tx); conn->tx_bytes += size; @@ -616,6 +652,15 @@ static void conn_pkt_tx(struct hci_conn *conn, struct timeval *tv, conn->tx_pkt_min = size; if (!conn->tx_pkt_max || size > conn->tx_pkt_max) conn->tx_pkt_max = size; + + if (chan) { + chan->tx_bytes += size; + + if (!chan->tx_pkt_min || size < chan->tx_pkt_min) + chan->tx_pkt_min = size; + if (!chan->tx_pkt_max || size > chan->tx_pkt_max) + chan->tx_pkt_max = size; + } } static void acl_pkt(struct timeval *tv, uint16_t index, bool out, @@ -624,7 +669,7 @@ static void acl_pkt(struct timeval *tv, uint16_t index, bool out, const struct bt_hci_acl_hdr *hdr = data; struct hci_dev *dev; struct hci_conn *conn; - struct l2cap_chan *chan; + struct l2cap_chan *chan = NULL; uint16_t cid; data += sizeof(*hdr); @@ -655,7 +700,7 @@ static void acl_pkt(struct timeval *tv, uint16_t index, bool out, } if (out) { - conn_pkt_tx(conn, tv, size); + conn_pkt_tx(conn, tv, size, chan); } else { conn->rx_num++; } @@ -681,7 +726,7 @@ static void sco_pkt(struct timeval *tv, uint16_t index, bool out, return; if (out) { - conn_pkt_tx(conn, tv, size - sizeof(*hdr)); + conn_pkt_tx(conn, tv, size - sizeof(*hdr), NULL); } else { conn->rx_num++; } @@ -768,7 +813,7 @@ static void iso_pkt(struct timeval *tv, uint16_t index, bool out, return; if (out) { - conn_pkt_tx(conn, tv, size - sizeof(*hdr)); + conn_pkt_tx(conn, tv, size - sizeof(*hdr), NULL); } else { conn->rx_num++; } From patchwork Tue Aug 1 23:21:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13337350 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BE34EB64DD for ; Tue, 1 Aug 2023 23:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230316AbjHAXVu (ORCPT ); Tue, 1 Aug 2023 19:21:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231341AbjHAXVu (ORCPT ); Tue, 1 Aug 2023 19:21:50 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 177AD26A2 for ; Tue, 1 Aug 2023 16:21:45 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-686f94328a4so233674b3a.0 for ; Tue, 01 Aug 2023 16:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932104; x=1691536904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=FVMcQ/mN4qzoaXflcSf8aSfstIOnnWhVxxJ+tu9PHtI=; b=ftngeHu+iENw+5okDXJAHNyJETlYVRvIIWBUPJTRdy6XkL4ANhMgcQzcoAQQEpbXTc r40Ms95cG6OBYG1LZ7BPKMFruGgeW3Sb0Q5Q9VktNq3NxMUKp2D4Gzpaz0/GqOBkSMGD Cjgh5Zg0Gl7eHU1/Nj5wHBvBOIIQaqe1j3AHyGfvfW+v4b/9CdeIYNqOzL8B5fYRalZm MJU1yQoy4v2Gkqq8cDLIXNwNjmJrWJ0rwzbdnkP6xLYXQeWOxMQc6HWDJaMNLTr5xfE1 NOLUN9y5fTCv/x+kv/N0aM6tXDzzs2d4fFYdwrUQv8fkeS7yjDLMV+aXNRW/tUo0hrVR xQkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932104; x=1691536904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FVMcQ/mN4qzoaXflcSf8aSfstIOnnWhVxxJ+tu9PHtI=; b=DdZKwzNgYQfn2R2rlzbfd9NEM0C+PSS3Z8edOUe/JHQLZfhnz6x2pxQEX6ykfbUqVb zz0oNAMmj1D+avSHWJtiFs56TMlacOl8j5HEbzcBBcAQ36Px4k11TuPR4honSUiMm/T8 SxUIZpRxDNd3FYFaLCqXjhDzajc4PhBFn+iQwKiGQFRwMaDQFIKd1YAnGtuOXh4F+pky fzqaZ06IM4fW7oCt1RcZa+EqNvduOHWCnro9xYi4yc9+f/ODV6IjwsRFNGGeYpfZMeQ0 IcmSJQ/WiO6w5CGhw/UOp55fGpHT37T//dqH0FVvnKr5scIc+zg1ndMXsAwGGWMg65LF WR9A== X-Gm-Message-State: ABy/qLay1559A3GIAoSdAV821Cq7sGcRV0osDH7DwGlrh+58eiypdg8L 5/8AmYdpiqmlw+CPRUidIfD9LeabtK0= X-Google-Smtp-Source: APBJJlEv8yFprpC46AEYFyPw4iQtfJLQGMWtwqQ868ApzOqiFUpNuq2NC8TehiH1kULNDc6bpEhnZg== X-Received: by 2002:a05:6a20:6a1f:b0:137:c971:6a0c with SMTP id p31-20020a056a206a1f00b00137c9716a0cmr14380947pzk.31.1690932103619; Tue, 01 Aug 2023 16:21:43 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id fk25-20020a056a003a9900b00682a8e600f0sm9856157pfb.35.2023.08.01.16.21.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:21:41 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 4/5] monitor: Add connection tracking for SCO/ISO with -a/--analyze Date: Tue, 1 Aug 2023 16:21:34 -0700 Message-ID: <20230801232135.535733-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801232135.535733-1-luiz.dentz@gmail.com> References: <20230801232135.535733-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds proper connection tracking to SCO/ISO connection by handling the events that establishes them. --- monitor/analyze.c | 108 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index 89b0382825dc..d0ad70d5dc74 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -253,7 +253,9 @@ static void conn_destroy(void *data) TV_MSEC(conn->tx_l.med)); print_field("%u-%u octets (~%u octets) TX packet size", conn->tx_pkt_min, conn->tx_pkt_max, conn->tx_pkt_med); - print_field("~%lld Kb/s TX transfer speed", + + if (TV_MSEC(conn->tx_l.total)) + print_field("~%lld Kb/s TX transfer speed", conn->tx_bytes * 8 / TV_MSEC(conn->tx_l.total)); plot_draw(conn->plot); @@ -595,9 +597,110 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv, } } +static void evt_sync_conn_complete(struct hci_dev *dev, struct timeval *tv, + const void *data, uint16_t size) +{ + const struct bt_hci_evt_sync_conn_complete *evt = data; + struct hci_conn *conn; + + if (evt->status) + return; + + conn = conn_lookup_type(dev, le16_to_cpu(evt->handle), evt->link_type); + if (!conn) + return; + + memcpy(conn->bdaddr, evt->bdaddr, 6); + conn->setup_seen = true; +} + +static void evt_le_cis_established(struct hci_dev *dev, struct timeval *tv, + struct iovec *iov) +{ + const struct bt_hci_evt_le_cis_established *evt; + struct hci_conn *conn; + + evt = util_iov_pull_mem(iov, sizeof(*evt)); + if (!evt || evt->status) + return; + + conn = conn_lookup_type(dev, le16_to_cpu(evt->conn_handle), + CONN_LE_ISO); + if (!conn) + return; + + conn->setup_seen = true; +} + +static void evt_le_big_complete(struct hci_dev *dev, struct timeval *tv, + struct iovec *iov) +{ + const struct bt_hci_evt_le_big_complete *evt; + int i; + + evt = util_iov_pull_mem(iov, sizeof(*evt)); + if (!evt || evt->status) + return; + + for (i = 0; i < evt->num_bis; i++) { + struct hci_conn *conn; + uint16_t handle; + + if (!util_iov_pull_le16(iov, &handle)) + return; + + conn = conn_lookup_type(dev, handle, CONN_LE_ISO); + if (conn) + conn->setup_seen = true; + } +} + +static void evt_le_big_sync_established(struct hci_dev *dev, struct timeval *tv, + struct iovec *iov) +{ + const struct bt_hci_evt_le_big_sync_estabilished *evt; + int i; + + evt = util_iov_pull_mem(iov, sizeof(*evt)); + if (!evt || evt->status) + return; + + for (i = 0; i < evt->num_bis; i++) { + struct hci_conn *conn; + uint16_t handle; + + if (!util_iov_pull_le16(iov, &handle)) + return; + + conn = conn_lookup_type(dev, handle, CONN_LE_ISO); + if (conn) + conn->setup_seen = true; + } +} + static void evt_le_meta_event(struct hci_dev *dev, struct timeval *tv, const void *data, uint16_t size) { + struct iovec iov = { + .iov_base = (void *)data, + .iov_len = size, + }; + uint8_t subevt; + + if (!util_iov_pull_u8(&iov, &subevt)) + return; + + switch (subevt) { + case BT_HCI_EVT_LE_CIS_ESTABLISHED: + evt_le_cis_established(dev, tv, &iov); + break; + case BT_HCI_EVT_LE_BIG_COMPLETE: + evt_le_big_complete(dev, tv, &iov); + break; + case BT_HCI_EVT_LE_BIG_SYNC_ESTABILISHED: + evt_le_big_sync_established(dev, tv, &iov); + break; + } } static void event_pkt(struct timeval *tv, uint16_t index, @@ -629,6 +732,9 @@ static void event_pkt(struct timeval *tv, uint16_t index, case BT_HCI_EVT_NUM_COMPLETED_PACKETS: evt_num_completed_packets(dev, tv, data, size); break; + case BT_HCI_EVT_SYNC_CONN_COMPLETE: + evt_sync_conn_complete(dev, tv, data, size); + break; case BT_HCI_EVT_LE_META_EVENT: evt_le_meta_event(dev, tv, data, size); break; From patchwork Tue Aug 1 23:21:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13337351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D841CEB64DD for ; Tue, 1 Aug 2023 23:21:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230141AbjHAXVy (ORCPT ); Tue, 1 Aug 2023 19:21:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230523AbjHAXVx (ORCPT ); Tue, 1 Aug 2023 19:21:53 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9968F26A6 for ; Tue, 1 Aug 2023 16:21:46 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68706d67ed9so3897309b3a.2 for ; Tue, 01 Aug 2023 16:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932105; x=1691536905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=hhHzgYxpkySIP9sxo8gNiJ+G7DvpijjrVJOTxAgVnsM=; b=VhhRxqVSQs9zHULXPFJF4fvyucLWWYINw901Pl/fj8GPCvTJA/AXySVxY1uNUJW5TX ntJ/3mwoPJuaYL2Zz4m9PxP+nrYuRzJZamVwbVbnrQo5WJ7Ljyj4xnf/oli9mM+yuPHo x7mNaY9uweTPUslKaBIPgVJEri84weljEsOluzHs5qta9ZmFnKqtYw6JA6V3/yhrhxIq aKXUF+Wk25Ig6QZx6/u7sqWyMyyk1x8QbPTWa53ma7vCLvBgPrMkOuBFrrYrkEhDBhPN SySI9WkFKKGLBsH8dttkAkSQiyFQF5imbyg+GIAXbbeI/qInBHF3gJZas4HGhaTpXzGp xZiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932105; x=1691536905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hhHzgYxpkySIP9sxo8gNiJ+G7DvpijjrVJOTxAgVnsM=; b=Ko4PJatfy7YrOACn15zYT3HiLva90x37ANIopE6B623YqKeXHxqJ2aBTydIAl3SV/G FouWK0cYjmwlhQx60LijvCk7cp6RLJaksmq2x9f1DNrpDH3caWXj/sAtT74IVzM3kapr Mfd4jCI3SqCvPxxnlejGsSuPaiCjh3JPCMMqXc7in8J+iIPhWeiic4RevenSh+KxQKlv /KyIqKo4l6ZPswTcTWheacnb2fdp9Ej1iSVhVON8GZ0STTgRprgxRvpLDa0Q04y5synR RRsDQ+YVGtRtdViPPDFXS4yiH/HmEG0J4NFRWK69YwuuwNWlBfXwdDJTWmduztsCt9KJ /l0A== X-Gm-Message-State: ABy/qLYsc/BLu5K/bZx/bmg2IprmItqpMeFoJ4oZsVUFv/nZDxF4lyhF fAuSGHA4zMuSl3cHqvJerYylHqJO/IU= X-Google-Smtp-Source: APBJJlGWQBG4MWWhpaw9iU0Kr66QJzOm477GWJXocvLTjDuauaqO3DQw2xgHS3gko1WHMNSw76zxEw== X-Received: by 2002:a05:6a20:a108:b0:13e:23bc:f4cc with SMTP id q8-20020a056a20a10800b0013e23bcf4ccmr6011708pzk.37.1690932105404; Tue, 01 Aug 2023 16:21:45 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id fk25-20020a056a003a9900b00682a8e600f0sm9856157pfb.35.2023.08.01.16.21.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:21:44 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 5/5] monitor/analyze: Inline data to gnuplot Date: Tue, 1 Aug 2023 16:21:35 -0700 Message-ID: <20230801232135.535733-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801232135.535733-1-luiz.dentz@gmail.com> References: <20230801232135.535733-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz Instead of creating a separate file just to write the x:y axis inline the data via gnuplot $data variable then use it to plot. --- monitor/analyze.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index d0ad70d5dc74..687595cb249a 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -112,35 +112,29 @@ static void tmp_write(void *data, void *user_data) static void plot_draw(struct queue *queue) { - const char *filename = "analyze.tmp"; - FILE *gplot = popen("gnuplot", "w"); - FILE *tmp; + FILE *gplot; + if (queue_length(queue) < 2) + return; + + gplot = popen("gnuplot", "w"); if (!gplot) return; - if (queue_isempty(queue)) - goto done; - - tmp = fopen(filename, "w"); - if (!tmp) - goto done; - - queue_foreach(queue, tmp_write, tmp); + fprintf(gplot, "$data << EOD\n"); + queue_foreach(queue, tmp_write, gplot); + fprintf(gplot, "EOD\n"); fprintf(gplot, "set terminal dumb enhanced ansi\n"); fprintf(gplot, "set xlabel 'Latency (ms)'\n"); fprintf(gplot, "set tics out nomirror\n"); fprintf(gplot, "set log y\n"); fprintf(gplot, "set yrange [0.5:*]\n"); - fprintf(gplot, "plot './%s' using 1:2 t 'Packets' w impulses\n", - filename); + fprintf(gplot, "set log y\n"); + fprintf(gplot, "plot $data using 1:2 t 'Packets' w impulses\n"); fflush(gplot); - fclose(tmp); -done: pclose(gplot); - unlink(filename); } static void chan_destroy(void *data) @@ -166,8 +160,7 @@ static void chan_destroy(void *data) print_field("~%lld Kb/s TX transfer speed", chan->tx_bytes * 8 / TV_MSEC(chan->tx_l.total)); - if (chan->num > 1) - plot_draw(chan->plot); + plot_draw(chan->plot); free(chan); }