From patchwork Tue Aug 1 23:31: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: 13337396 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 C4FF2EB64DD for ; Tue, 1 Aug 2023 23:31:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230343AbjHAXbq (ORCPT ); Tue, 1 Aug 2023 19:31:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbjHAXbo (ORCPT ); Tue, 1 Aug 2023 19:31:44 -0400 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8109D2690 for ; Tue, 1 Aug 2023 16:31:39 -0700 (PDT) Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-77acb04309dso311534539f.2 for ; Tue, 01 Aug 2023 16:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932698; x=1691537498; 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=TbRnrDjO2z4W5xCHGvv4Zw70gPLYuAD9RIZn7FwE8QN4axW1gqnTRPKkuULfbW0Pv1 ZlgD607tTyg7gb5oytQ8nyIg3Og73PVJQwaTy4m/ZmrfU/AKU3MP/4Af+TF8VBrkfH2P 8MeEAAkLoIEvLk8W6mN2d6B/ZOY+CGSc/gRjA309MAzNQWnKlHi6RbIO5EX/KPM4tr/B TDe/YaEb/Oz613xwHaG5Tbd3H+z2NeN0PVz+RcNnOtBDAn6yS7P5S2Fhe8mRTTUWEX5k IWDknkfZYTUWoV/2dERtByodx5ig3PFP5MAtzK4kVMHUQ9uDOIIYwncCQ/q1ViF3TzJo /4OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932698; x=1691537498; 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=bQ27uAWtBhybE/pUyzRJuY5hCwUcRCv925giuWGHQ+7K38/jY7cA4wpo2LdyROSdye n9OvwB2pkKkhjuVe60RHOuQB1D651sJOeEvE90xE5cSaLOifwRPonuY0NQ0rBqyEO4MC eKAg066CYF0TEUcNfUtv18AtGK7VSNUb9WFwK3RmK4eAe9BP2TXhw0lsfddYcWxoJkw5 v21iflVSN4uf/T71pgGKXioouV9OmcuRJMbod5PdLLufusmoPSF/l8AqYMZsy+aautik GqWajgBNrx0L8fgsUtv+pSOl17dUZGb+RuUQzev9aXJmp/4LV6jqPpV0CPdl583KG2sl bdrQ== X-Gm-Message-State: ABy/qLYLlEDCm+ZjMFw4PQ+YACofUiYUlAoy6ga7lEpcym7S8OYAoSq2 R4hOAm+a9rZ9ggrHP1i8gWvz15Qpm+w= X-Google-Smtp-Source: APBJJlHrWZrSRX79rxgJYT2go/GHulyr0RNEZNzNe2eW3lspByAeqaj72YPDGre3sc9QAJ8bPw1Kuw== X-Received: by 2002:a6b:7116:0:b0:787:34d:f1ea with SMTP id q22-20020a6b7116000000b00787034df1eamr14637686iog.8.1690932697838; Tue, 01 Aug 2023 16:31: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 d20-20020a5d9bd4000000b00790af7745b1sm1286269ion.20.2023.08.01.16.31.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:31:37 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v3 1/5] monitor: Add TX frame number and speed estimation Date: Tue, 1 Aug 2023 16:31:31 -0700 Message-ID: <20230801233135.537864-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:31: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: 13337397 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 9A8A2EB64DD for ; Tue, 1 Aug 2023 23:31:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbjHAXbw (ORCPT ); Tue, 1 Aug 2023 19:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbjHAXbr (ORCPT ); Tue, 1 Aug 2023 19:31:47 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4D56268C for ; Tue, 1 Aug 2023 16:31:40 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-790ab117bd5so98276239f.0 for ; Tue, 01 Aug 2023 16:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932699; x=1691537499; 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=PKMvEr+weBIjOiZaDQ0u5XiuMoTcE9fcjfSgPOBk8t/4bniW5N8/Glk0vf3B4MVUOx 27olflpkJCn/a68Gl8U34aiwJdgUsgtKDKPX81GIzqzib0n/80oeJci+1H4rheaSMVcd gRET73hsJZZ5r42IVoVxuhNuz+uCB7olCCJ1AhFd+anvw6OHW80DJ9L/KAtXWclJTPAi +XdjECt7eCn+ba4PKZlllQdc6VM/OnAior44Vo8F3LG0zisq8uIM7aBm3B6/JnFNrFZg x43EBuOqP69IFuk6zSeg1p+DDjeznZ2gVkjrLKoQ90rap8HbNnTE8eukq0DL0JdKh2ng 3gmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932699; x=1691537499; 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=ci2Easptcc9tlODUqqMgl07jRsHdKLk3U0UGuYQ4L6OezzkfnRHs866Knuq2oChPQc 6dDzUty8UXS1yXWTvwfEq7dN1/KEixdtNmM17P28ikK6K0EV9s01/QNymc/mESukhbf+ blWb9XSYPKyjrWmgjr8hCKwhh9h9s5fBZxk0TLt8FYbVWNlcoytcxlIKQ/Ntv8XU3vHi PxpV6Ef2SGyp0PIHC5MIuOsgHpvtEg/2ss+OrVykHD+Irx5m/COBgzrfWYGrL0W8uM8W ZJgFqaZgCqn4LqZi4mQQcI8uORdL/Qr6Fx5kkCQF5nDbnDafWWMIFu7pvcSiFuuAZgwK b2zw== X-Gm-Message-State: ABy/qLZtqjvD9Eo7q51jvWKqxkX2Fh3sycdZq/fK0L53i9GCKCCEip5r pG/vaKd11nVLYIdgFkHEjwW86Eqc6Co= X-Google-Smtp-Source: APBJJlG1SrkSFdKKSW1/GOvYcbTpnBRxY/iSSl24PEysXvri2yKB7+tyYPKv8+1BJb2NwwrDU82Pbw== X-Received: by 2002:a6b:fd06:0:b0:790:b033:6ffc with SMTP id c6-20020a6bfd06000000b00790b0336ffcmr5438361ioi.20.1690932699483; Tue, 01 Aug 2023 16:31: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 d20-20020a5d9bd4000000b00790af7745b1sm1286269ion.20.2023.08.01.16.31.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:31:38 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v3 2/5] monitor/analyze: Use conn_pkt_tx on acl_pkt Date: Tue, 1 Aug 2023 16:31:32 -0700 Message-ID: <20230801233135.537864-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801233135.537864-1-luiz.dentz@gmail.com> References: <20230801233135.537864-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:31: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: 13337398 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 8BB79C0015E for ; Tue, 1 Aug 2023 23:32:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230480AbjHAXcB (ORCPT ); Tue, 1 Aug 2023 19:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbjHAXbv (ORCPT ); Tue, 1 Aug 2023 19:31:51 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1A6B269E for ; Tue, 1 Aug 2023 16:31:42 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-77ac14ff51bso250543539f.3 for ; Tue, 01 Aug 2023 16:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932701; x=1691537501; 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=gHWbG5QpPM3ecx/0zdjMLFW4bAygZ1dsi40a9sVQPTvpqSXcEEabvMr1gL9+BAU7/t qqi8Em3dEt/1H/1daWbcT78/nHhPrhdaTZWE6jQf7assjGjKv2q5EmrTLoweu2UcFKRB kdG2Fmiu3GqNnNHoofAu1NhkWjxYZWHXDPZAshCj6ZfO5ZVRXAHyjUYMSieSXZsrNgMS mqTQTgmE9n/oYvyQa1mOQK15lD/OzKXFYURMcwia9KOn4szQF+udGV2ujYgde5lRGNra t0QzVlVXa54dqMZdY3SZ821kWawDndK/pzQ/YUYzWebmdTBMTAhIN5w4J9107QO+SDtV w20Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932701; x=1691537501; 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=KHCz24R0ttcRlalrqr8tbjsyrM4c3GcEEhXJlSdsAVtsynf5q+bawfCMmlN4ql75lR a4vT70x6hS7UG5Fuc0mgohAV3YyQV8kStKeGHSl/4az3w2PNymSO+aSFcTc7AZ6s+rz3 Jtdj0l+dNzb7OYk9ImwRH7EUx5qEin6aJ1UTfpP7sh1hVwlhrRDXzOk3X93blqdoSOiG +Bxxi0zH2CE82r0UR1klbH7ul3qKXF9Iv+hUiZGgyWW5Nw93plBju+D43DTqTRSmP2KJ 0HGj/fC+fBwL6t3Boij/honRnLRRRQdbBEpjTzsEgsn+sOuDBso7vryRspcSOtz0+6WJ 2gAw== X-Gm-Message-State: ABy/qLYkjMyseSKQf98zl3M30DH5RsIKNG5MYwfF0TZbhhxNvq6vBFVy 5InXYodZj1dy/8MRlryUDP7pt+7oqlg= X-Google-Smtp-Source: APBJJlGf4cAEH/LO72qRxNcALFvvYTMP5LlMG6NKLe65V4N8tJCNjMsFBRUcv80UUzWvoN3wjlUgAg== X-Received: by 2002:a5e:dc06:0:b0:787:8cf:7426 with SMTP id b6-20020a5edc06000000b0078708cf7426mr12722732iok.6.1690932701169; Tue, 01 Aug 2023 16:31: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 d20-20020a5d9bd4000000b00790af7745b1sm1286269ion.20.2023.08.01.16.31.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:31:40 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v3 3/5] monitor: Print channel latency information with -a/--analyze Date: Tue, 1 Aug 2023 16:31:33 -0700 Message-ID: <20230801233135.537864-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801233135.537864-1-luiz.dentz@gmail.com> References: <20230801233135.537864-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:31: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: 13337399 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 67238C41513 for ; Tue, 1 Aug 2023 23:32:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231341AbjHAXcC (ORCPT ); Tue, 1 Aug 2023 19:32:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230488AbjHAXbv (ORCPT ); Tue, 1 Aug 2023 19:31:51 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DF87268E for ; Tue, 1 Aug 2023 16:31:44 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-790ca0ed6d3so31921239f.3 for ; Tue, 01 Aug 2023 16:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932703; x=1691537503; 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=Ivie46mRW9uSTezbQ8QV5LZ2qxLXoONT1Ypjj606L4Yz9VpEvA9C48iCcQiZQgJeNg Lh601km2DrO4993f7Ymtx7Gutlme4Brjbjb42pjHIwHY3fc07cdqfK3XOdFzHtCxYWq9 S01nab6kEv1LaTggO2wWl5lPQTe2sppHBG7Aqhfc7UE9SKz49jNHOcuQ0BOWzZyIyzTj FDzyop87QDIMVfuDaSDDS7u1T6cpQDxyvVkZkpeq3LnbVwqZlnME0IO+l8BrEyHtta10 pe7w4g+7NlVsfahktn4eyJ63U2Km5Ad8Lry074roFuQ7MIB8cIL0blrgxlLTfGvBIMmU XYfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932703; x=1691537503; 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=Kw7aEs3YY0GvysVkQAnVttEUP6pdNGCN6ZkcRNk4oKf8cRO3z/owKMCWo/GaUeFanj lWbAzVFR+mE1MxpLBVm6ITPYyNs9zH8jCXkt2QRpsYE2sNX9LEzqzaXuozHKFFrPKM99 8VtpGCjYzCThZteOBifxTQ3xXQlcu/+Z5a38S7SoNnsUM7R5ktlqxNbjCSO2WetB6qJh eOqFwcxO9ft777KnPZ8y1UQx7afV73zwb1wXztb0i5+JPbyk7GJW564cFMUjafhMJZ4r Y5h5n6kpBK3Vur8Q96YJYdPzBGfsjq76xme39dMPnrEVliuq6IoXUeLQ8j/mVRMqYCx1 BHcA== X-Gm-Message-State: ABy/qLZmKFT6yUXrOJ/4y+WhRfjRO2qoo5e1bm3W4SuAgvO8xCVFxJ7N X1eRSckKRMKSb+WmgN0rJAmE+IwFKVs= X-Google-Smtp-Source: APBJJlEouG445VIof3f0/uLhCbZyqfgHc0kqNBxLlKyaN6Amv3ZDa6c52gFkzDWRgxC1GPwYAgx5yw== X-Received: by 2002:a6b:4a14:0:b0:783:4e11:76d7 with SMTP id w20-20020a6b4a14000000b007834e1176d7mr11245553iob.21.1690932703004; Tue, 01 Aug 2023 16:31: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 d20-20020a5d9bd4000000b00790af7745b1sm1286269ion.20.2023.08.01.16.31.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:31:41 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v3 4/5] monitor: Add connection tracking for SCO/ISO with -a/--analyze Date: Tue, 1 Aug 2023 16:31:34 -0700 Message-ID: <20230801233135.537864-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801233135.537864-1-luiz.dentz@gmail.com> References: <20230801233135.537864-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:31: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: 13337400 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 B8121EB64DD for ; Tue, 1 Aug 2023 23:32:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbjHAXcD (ORCPT ); Tue, 1 Aug 2023 19:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbjHAXbx (ORCPT ); Tue, 1 Aug 2023 19:31:53 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12FD32690 for ; Tue, 1 Aug 2023 16:31:46 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7909808a504so162915639f.1 for ; Tue, 01 Aug 2023 16:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932705; x=1691537505; 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=uhNC38rHJARy+Xjp7ygLG8chIPQNmXHx9lmwZL4Bu0s=; b=UupK7Ns0o/fJJMAaRF8f1C4AW4nc2U5kf+qVlm990D2uRl+gauX4dffGp7/rqHwhlY aqoFEqoNPmO9Fhc6rX6nOHkYYEOS1cmdFlxBh8EMkOTLIbYfHAAlhF00MOLTObZAvyfV 9aPYOnzghd/Ubjh3Hkz0spbDiiNnZjuiG27g+vMdiWsF+9OOYZuxmYsraBLPW9kW4v9F Vw0ZuWgVFmlr7h0xZoKbZHzn6Ny2dD6zCIiRL2lItuamlEqc6WXdLyuJPO7MjMD3veac TZ+N0eEWwtL6FarggD5LEwm4OR/lebkR/oGRypwS5PB9zDZ42r1SXCM5to+yBUzfSmli /s4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932705; x=1691537505; 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=uhNC38rHJARy+Xjp7ygLG8chIPQNmXHx9lmwZL4Bu0s=; b=NfXw6NcHU8zoPCDfKhQvCUpGgHhQhAVJFpb1lnqF28qc5l3CXzMI/+VQlrINjX/DHg tZI/cPzZU2B0c/A7jtOgHnszhjJhzctDSWCzq3d7/TVqVhnhpGT5ia4SI+hLAU3Jgk8a TschVPUAXcJ0xIWIH4BjAiMvGOiSNdmhQ39trERJx106YtWxaK8U1l6R9BZ7y7RkPF/X oYoFSgt+0iz2VhlstHXHEQvtJQa0WMBAKIkEQOp/ijNSjzyAP0LSysFZ4d8PXQdNK5rd Yjx8a4L1z7WFTG4WSFzQfreY66A+BZxQS38bJbOH3/785cQMHkc5I+NyKE21NqFVvRij 57yw== X-Gm-Message-State: ABy/qLasO/iz3wmTUKKaj+gFQdwZ4Is7p4sfcIpKzQSXJKUtFmv/HFkG +h1EtsTBNfQb0NgFnfisE63rGwrcpak= X-Google-Smtp-Source: APBJJlGVzAhnpWgIG87wgMDbUlhiljHkM9fjwHuhLXKm0bkrKtXb7+nIZxobEoyqcEsxU/08Padv0w== X-Received: by 2002:a5d:9e14:0:b0:790:a073:f122 with SMTP id h20-20020a5d9e14000000b00790a073f122mr9681659ioh.2.1690932704736; Tue, 01 Aug 2023 16:31:44 -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 d20-20020a5d9bd4000000b00790af7745b1sm1286269ion.20.2023.08.01.16.31.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:31:43 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v3 5/5] monitor/analyze: Inline data to gnuplot Date: Tue, 1 Aug 2023 16:31:35 -0700 Message-ID: <20230801233135.537864-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801233135.537864-1-luiz.dentz@gmail.com> References: <20230801233135.537864-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 | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index d0ad70d5dc74..9f882a6c8b71 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -112,35 +112,28 @@ 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, "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 +159,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); }