From mboxrd@z Thu Jan 1 00:00:00 1970 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from imap.gmail.com [2a00:1450:400c:c0a::6d] by vm-ifcgrfdd with IMAP (fetchmail-6.4.39) for (single-drop); Fri, 19 Sep 2025 16:07:21 +0200 (CEST) Received: by 2002:a05:6f02:529:b0:fc:36d7:21b3 with SMTP id 41csp402187rch; Fri, 19 Sep 2025 07:07:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVChf9kJhc4ctjFtUJ4gW20fBJ2jqS1uLNZwn2YKisltsiPZotMforsZDIRmLYv9Gp8yV/Dz6d4@gapps.redhat.com X-Google-Smtp-Source: AGHT+IEKHybfElp8iLYYXJv6BFU4UGmWh4FtKIM5ZUj2JJ5cAcjmTGaIvFCMxvBtGF2YiSVz2EmW X-Received: by 2002:a05:6214:b6b:b0:730:a986:49b0 with SMTP id 6a1803df08f44-7991a92db64mr44209306d6.31.1758290838889; Fri, 19 Sep 2025 07:07:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1758290838; cv=pass; d=google.com; s=arc-20240605; b=OXYOe6VS7oT8rQWF1ULfVyAY78PvClXhkqhglKvY/ej2l7NL3N5UNvCYRMftz+da3M 2VNZW78uGNfdPKyhauUfUBTQKJk/MJv0ZQvglyP7mDymYqTFvG52sIlYM3+F2oTwVXjd G5CTBjCdf+VvriSVOTR7DsU+grjKbZm8/tsP1aW76tVvThhZbXDL0q+H5be33pfvPvfr 5RrH01luS4J18Ce/sNXJhmSSuKAJaSRrWnmWjPuJfWTbi6q3V5BVwkhavtnyHCI1QfmQ mOeknMr3SZy2qr0S1kYxgwB4D9RKlWqHKFmmAclRUU7iZVFvCK3OyrYxz1jlDmmWgvJ7 3iCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:list-unsubscribe:list-subscribe:list-post :list-owner:list-help:list-archive:list-archive:archived-at :archived-at:list-id:precedence:cc:message-id-hash:mime-version :message-id:date:subject:to:from:dkim-signature:delivered-to; bh=NIu2HWxhiihiW7dwAGBvxZF4PmtvFzuNHDhQWT9deSE=; fh=a0/9SsnFCQu5xSZk7UufXEB0QSlcktPKh2fnJeFmjQA=; b=k1kGUpRzMxAt9XKfS4HjJGfWt+L/nJixcLTIg9AFK+zQUpo3FHrGTumulGMhafBzHe 2IVpooKr0+C6QMLzQ2qlJouhMFlRpVT55KlFQHO8J3pw59QJ01dSLW5iup+2BW4k0cnm 2BVKWTFWBMtlXpvN/84f44eJwq4DHNHEp431X+WeJGFNEzhxgL9OhWhZF0biDCymApNM KAcc69WIWaV+5uW1QIww6Kr4smbZUe2ClYx0E8F4mrvEetkzVY+ptF8ApI0gfEznWspd 31fItxJuWe617DtYYlNMKnTn/iDfazUdUmBxlxOXNKLTV1IrYdzHe4/hGwDWFMUCGWjK aGIA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=neutral (body hash did not verify) header.i=@redhat.com header.s=mimecast20190719 header.b="Y/Oec9N9"; arc=pass (i=1 spf=pass spfdomain=passt.top); spf=pass (google.com: domain of passt-dev-bounces@passt.top designates 88.198.0.164 as permitted sender) smtp.mailfrom=passt-dev-bounces@passt.top Return-Path: Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com. [170.10.128.131]) by mx.google.com with ESMTPS id 6a1803df08f44-79ba6b5fa97si4430376d6.1031.2025.09.19.07.07.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Sep 2025 07:07:18 -0700 (PDT) Received-SPF: pass (google.com: domain of passt-dev-bounces@passt.top designates 88.198.0.164 as permitted sender) client-ip=88.198.0.164; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@redhat.com header.s=mimecast20190719 header.b="Y/Oec9N9"; arc=pass (i=1 spf=pass spfdomain=passt.top); spf=pass (google.com: domain of passt-dev-bounces@passt.top designates 88.198.0.164 as permitted sender) smtp.mailfrom=passt-dev-bounces@passt.top Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-Ma7cjwpvOYaXhDbXdUaH5Q-1; Fri, 19 Sep 2025 10:07:17 -0400 X-MC-Unique: Ma7cjwpvOYaXhDbXdUaH5Q-1 X-Mimecast-MFC-AGG-ID: Ma7cjwpvOYaXhDbXdUaH5Q_1758290836 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 670701955F6A for ; Fri, 19 Sep 2025 14:07:16 +0000 (UTC) Received: by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) id 6253B19541B0; Fri, 19 Sep 2025 14:07:16 +0000 (UTC) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.49]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5EBD41955F21 for ; Fri, 19 Sep 2025 14:07:16 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [170.10.128.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1DFDD1955E88 for ; Fri, 19 Sep 2025 14:07:16 +0000 (UTC) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=dkim.mimecast.com; s=201903; t=1758290835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=NIu2HWxhiihiW7dwAGBvxZF4PmtvFzuNHDhQWT9deSE=; b=hw5XvcLC2q1dmBs5fIuV+TKCHUFxr6opAqFcqhEQCzJxChT9axA4YBzwtp+z2fw4ClPPCy t/LiF5PWrEbMYM172u7hNP04hdsl9NKLFCM4K/U1T22iIdpBqZOqVsaaizvLR1rUcsGOyx Pps44R8XdFDMDaP5u/DW1kRVpNKZl0CVKSdH/IY0kXXYLpZCLH6y3aHFCWq3zK61h9wceB Esk2C8eONztSEupji2S5kSWRXKd+ldHPRzV5pPRo+NFrcNdeABkTZDmilulwcBJiRkw6Ct XtXeXDfx9zOjTMGoxKmx/xFlp9kbqrebRWMSpiT1zx398UeY+6Xr09vAiQSkEQ== ARC-Seal: i=1; s=201903; d=dkim.mimecast.com; t=1758290835; a=rsa-sha256; cv=none; b=lqq5VcEFWJ41LiLWmPUurneaqvNsoFXs3v50MQS/JmBOuwmVi4nTmWTYM7OJr3o6CTmZkU +xi75B68ZHekIcoZMHS/WSIj60WsdjMqcV/xEJkBF48m0stcGK3Wlc/W3L3VRLfFsWVN6r bKY+ZwuKwOjQHuzhAJYBFdpXgjGPjNuLeaKr1QXr+brlXsuyIfwrAPvhLjgd79OoUeafpa aI+t98Syznw+5XNSix0laqs7P1Sn5GnnKgGlySSCy62EeFq/TG8BiZRbdPcjeUrQrpu/k4 h4SoGtGG/o3T7heEiIP224meUzX2fM3j8v2P5ep8r20nxt4YIqVP0jk3hyJ+hQ== ARC-Authentication-Results: i=1; relay.mimecast.com; dkim=fail ("body hash did not verify") header.d=redhat.com header.s=mimecast20190719 header.b="Y/Oec9N9"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=redhat.com (policy=quarantine); spf=pass (relay.mimecast.com: domain of passt-dev-bounces@passt.top designates 88.198.0.164 as permitted sender) smtp.mailfrom=passt-dev-bounces@passt.top Authentication-Results: relay.mimecast.com; dkim=fail ("body hash did not verify") header.d=redhat.com header.s=mimecast20190719 header.b="Y/Oec9N9"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=redhat.com (policy=quarantine); spf=pass (relay.mimecast.com: domain of passt-dev-bounces@passt.top designates 88.198.0.164 as permitted sender) smtp.mailfrom=passt-dev-bounces@passt.top Received: from passt.top (passt.top [88.198.0.164]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-_exD2vvaOvmopm2DDIDoSg-1; Fri, 19 Sep 2025 10:07:11 -0400 X-MC-Unique: _exD2vvaOvmopm2DDIDoSg-1 X-Mimecast-MFC-AGG-ID: _exD2vvaOvmopm2DDIDoSg_1758290828 Received: from [88.198.0.164] (localhost.localdomain [127.0.0.1]) by passt.top (Postfix) with ESMTP id B8CF25A0271; Fri, 19 Sep 2025 14:54:06 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 1C4E55A0271 for ; Fri, 19 Sep 2025 14:54:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758286443; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cQCqcvcAz3B3sKfHxJduOXCTenOv+Q23VJNXU6DO3/M=; b=Y/Oec9N9RVIietuMUmo/Yk0vsgLBok2OsPlteVHi0aZe1vkQ2B8R+2JYVsNmLpxTi55U5A IVjRpYaTQ14n8/vzIiuMfjbtWqa3/fh9ZgNuR2MRagJVX4o2kOhE9KiytaydDZDzIMLmJE TqLdmsE9fc90h31ULUI4P2IzVkqYfKM= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-347-YnBsI3iFM6Ceg8ybP9kPpw-1; Fri, 19 Sep 2025 08:54:01 -0400 X-MC-Unique: YnBsI3iFM6Ceg8ybP9kPpw-1 X-Mimecast-MFC-AGG-ID: YnBsI3iFM6Ceg8ybP9kPpw_1758286440 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B4D0B180029E for ; Fri, 19 Sep 2025 12:54:00 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.45.224.236]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A2CE7180035E; Fri, 19 Sep 2025 12:53:59 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v2] Add --stats option to display event statistics Date: Fri, 19 Sep 2025 14:53:58 +0200 Message-ID: <20250919125358.177998-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-MFC-PROC-ID: BTfSkbR-qLp4yC9hnJRt-rqA5astkvLdZ0qEeAaHsLk_1758286440 X-Mimecast-Originator: redhat.com Message-ID-Hash: H6USOSXEKYGQI7PARWJAPJTWPOP5QYF2 X-Message-ID-Hash: H6USOSXEKYGQI7PARWJAPJTWPOP5QYF2 X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Laurent Vivier X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mimecast-Spam-Score: 3 X-Mimecast-MFC-PROC-ID: xQQvA9R019j9kVQcEoIOmzeS70CN6qfPIvy57MGeR2o_1758290828 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition;Similar Internal Domain=false;Similar Monitored External Domain=false;Custom External Domain=false;Mimecast External Domain=false;Newly Observed Domain=false;Internal User Name=false;Custom Display Name List=false;Reply-to Address Mismatch=false;Targeted Threat Dictionary=false;Mimecast Threat Dictionary=false;Custom Threat Dictionary=false X-Mimecast-Bulk-Signature: yes X-Mimecast-Spam-Signature: bulk content-type: text/plain; charset="US-ASCII"; x-default=true Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Message-ID: <20250919125358.eOpWcdDW9Y2-uXNcAPyiibEu7PJ4GMEdaIMT6wyRR-4@z> Introduce a new --stats DELAY option that displays event statistics tables showing counts by epoll event type. Statistics are printed to stderr with a minimum delay between updates, and only when events occur. Signed-off-by: Laurent Vivier --- conf.c | 8 ++++++++ passt.1 | 5 +++++ passt.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ passt.h | 2 ++ 4 files changed, 73 insertions(+) diff --git a/conf.c b/conf.c index 02e903b5cf70..66b9e63400ec 100644 --- a/conf.c +++ b/conf.c @@ -835,6 +835,8 @@ static void usage(const char *name, FILE *f, int status= ) =09=09"\n" =09=09" -d, --debug=09=09Be verbose\n" =09=09" --trace=09=09Be extra verbose, implies --debug\n" +=09=09" --stats DELAY =09Display events statistics\n" +=09=09" minimum DELAY seconds between updates\n" =09=09" -q, --quiet=09=09Don't print informational messages\n" =09=09" -f, --foreground=09Don't run in background\n" =09=09" default: run in background\n" @@ -1480,6 +1482,7 @@ void conf(struct ctx *c, int argc, char **argv) =09=09{"repair-path",=09required_argument,=09NULL,=09=0928 }, =09=09{"migrate-exit", no_argument,=09=09NULL,=09=0929 }, =09=09{"migrate-no-linger", no_argument,=09NULL,=09=0930 }, +=09=09{"stats", required_argument,=09=09NULL,=09=0931 }, =09=09{ 0 }, =09}; =09const char *optstring =3D "+dqfel:hs:F:I:p:P:m:a:n:M:g:i:o:D:S:H:461t:u= :T:U:"; @@ -1708,6 +1711,11 @@ void conf(struct ctx *c, int argc, char **argv) =09=09=09=09die("--migrate-no-linger is for vhost-user mode only"); =09=09=09c->migrate_no_linger =3D true; =20 +=09=09=09break; +=09=09case 31: +=09=09=09if (!c->foreground) +=09=09=09=09die("Can't display statistics if not running in foreground"); +=09=09=09c->stats =3D strtol(optarg, NULL, 0); =09=09=09break; =09=09case 'd': =09=09=09c->debug =3D 1; diff --git a/passt.1 b/passt.1 index af5726a7f1c5..0c17454c3e43 100644 --- a/passt.1 +++ b/passt.1 @@ -84,6 +84,11 @@ Be verbose, don't log to the system logger. .BR \-\-trace Be extra verbose, show single packets. Implies \fB--debug\fR. =20 +.TP +.BR \-\-stats " " \fIDELAY\fR +Display events statistics with a minimum \fIDELAY\fR seconds between updat= es. +If there is no event, statistics are not displayed. + .TP .BR \-q ", " \-\-quiet Don't print informational messages. diff --git a/passt.c b/passt.c index a4ec115d1784..31fbb75b1b12 100644 --- a/passt.c +++ b/passt.c @@ -83,6 +83,14 @@ char *epoll_type_str[] =3D { static_assert(ARRAY_SIZE(epoll_type_str) =3D=3D EPOLL_NUM_TYPES, =09 "epoll_type_str[] doesn't match enum epoll_type"); =20 +/** + * struct passt_stats - Statistics + * @events:=09Event counters for epoll type events + */ +struct passt_stats { +=09unsigned long events[EPOLL_NUM_TYPES]; +}; + /** * post_handler() - Run periodic and deferred tasks for L4 protocol handle= rs * @c:=09=09Execution context @@ -174,6 +182,53 @@ static void exit_handler(int signal) =09_exit(EXIT_SUCCESS); } =20 +/** + * print_stats() - Print event statistics table to stderr + * @c:=09=09Execution context + * @stats:=09Event counters + * @now:=09Current timestamp + */ +static void print_stats(const struct ctx *c, const struct passt_stats *sta= ts, +=09=09=09const struct timespec *now) +{ +=09static struct timespec before; +=09static int lines_printed; +=09long long elapsed_ns; +=09int i; + +=09if (!c->stats) +=09=09return; + +=09elapsed_ns =3D (now->tv_sec - before.tv_sec) * 1000000000LL + +=09=09 (now->tv_nsec - before.tv_nsec); + +=09if (elapsed_ns < c->stats * 1000000000LL) +=09=09return; + +=09before =3D *now; + +=09if (!(lines_printed % 20)) { +=09=09/* Table header */ +=09=09for (i =3D 1; i < EPOLL_NUM_TYPES; i++) { +=09=09=09int j; + +=09=09=09for (j =3D 0; j < i * (6 + 1); j++) { +=09=09=09=09if (j && !(j % (6 + 1))) +=09=09=09=09=09FPRINTF(stderr, "|"); +=09=09=09=09else +=09=09=09=09=09FPRINTF(stderr, " "); +=09=09=09} +=09=09=09FPRINTF(stderr, "%s\n", epoll_type_str[i]); +=09=09} +=09} + +=09FPRINTF(stderr, " "); +=09for (i =3D 1; i < EPOLL_NUM_TYPES; i++) +=09=09FPRINTF(stderr, " %6lu", stats->events[i]); +=09FPRINTF(stderr, "\n"); +=09lines_printed++; +} + /** * main() - Entry point and main loop * @argc:=09Argument count @@ -191,6 +246,7 @@ static void exit_handler(int signal) int main(int argc, char **argv) { =09struct epoll_event events[EPOLL_EVENTS]; +=09struct passt_stats stats =3D { 0 }; =09int nfds, i, devnull_fd =3D -1; =09struct ctx c =3D { 0 }; =09struct rlimit limit; @@ -362,6 +418,8 @@ loop: =09=09=09/* Can't happen */ =09=09=09ASSERT(0); =09=09} +=09=09stats.events[ref.type]++; +=09=09print_stats(&c, &stats, &now); =09} =20 =09post_handler(&c, &now); diff --git a/passt.h b/passt.h index 3ffc19fdae05..0075eb4b3b16 100644 --- a/passt.h +++ b/passt.h @@ -187,6 +187,7 @@ struct ip6_ctx { * @mode:=09=09Operation mode, qemu/UNIX domain socket or namespace/tap * @debug:=09=09Enable debug mode * @trace:=09=09Enable tracing (extra debug) mode + * @stats:=09=09Events statistics delay (0 means disabled) * @quiet:=09=09Don't print informational messages * @foreground:=09=09Run in foreground, don't log to stderr by default * @nofile:=09=09Maximum number of open files (ulimit -n) @@ -248,6 +249,7 @@ struct ctx { =09enum passt_modes mode; =09int debug; =09int trace; +=09int stats; =09int quiet; =09int foreground; =09int nofile; --=20 2.50.1