Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2769242pxb; Sat, 6 Feb 2021 07:11:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJytSgvIhXw5vRDxHXJ+oHIX4OsLyaiUTGaVV4UFspGKpXjAQNtAucoEGtWkizJJW63TyEde X-Received: by 2002:a17:906:30cd:: with SMTP id b13mr9212235ejb.336.1612624260102; Sat, 06 Feb 2021 07:11:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612624260; cv=none; d=google.com; s=arc-20160816; b=OB5Nto54fA5gNuYzeOSXLr1n/YdWNNitznypVjwtLIa0JyFSrbG/w/P4o4HnX/IBI3 zN2VpnHYLqxSpXJsV2wQVjlaDvnId9NNR/VeqVBOPhLq9efrbA7Pu7SzpIPjBdUL4MzL YPY0TRCjbD/B3FJaptEJB1X4JDsMjc/VfnRq7UUvsK99s8862n4mStnClFAKoh1KX3Tv IZlOuqg18ZQbsYC0A+x6kM3tEB7igrBJq3qLmnZ/5QvBLQBGoWF968rv6G66d8GRyUNC wTOIwe8AjCK2xp7jEu+JXRlo5VnjehNSO2k6BXM6aZnCCDILwl7P98SXoHty3O0OvJOk Ly2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=PQExpiWyYta4VVihzb+CKltkjCyE+Nn7N3aG4A9+MCU=; b=Km9nSsFHXH0/wH0cZuS2pPs3sq1CXmvSG4C2Zw+4oP/ZxXB84N/LazQwHfkh/KjuUV +kydpYBjlgz7b1PGgWNP9eWwQVgLI4MKpNTGEskv9wPv3fKcptzXK0bXUDLsgy0qe+xe kesHu4ZPQfRuy5DVPeQMAoY3vrZ8bhVQ0J995lvYGQt0fQTUlM0crYpjc5w5ix0M8uqE ErO67ajqcPlDvFXrETkaeGO9+oqP1inbDV3NjvOdBObVWN3xx4XmtYhECHd14bmTo7f3 bFSZl3reYe8YZAa4CvT2oQV92hD9ED7jfnfVcReQS+zRcYg0rJUALU7MQNy8zCwbLf79 1Gow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fi28si6733361ejb.379.2021.02.06.07.10.29; Sat, 06 Feb 2021 07:11:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229763AbhBFPGA (ORCPT + 99 others); Sat, 6 Feb 2021 10:06:00 -0500 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]:40845 "EHLO smail.rz.tu-ilmenau.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbhBFPFd (ORCPT ); Sat, 6 Feb 2021 10:05:33 -0500 Received: from isengard.fritz.box (unknown [87.147.51.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 3D20E58005E; Sat, 6 Feb 2021 16:04:40 +0100 (CET) From: Markus Theil To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Markus Theil Subject: [PATCH] iw: add option to print human readable event time Date: Sat, 6 Feb 2021 16:04:32 +0100 Message-Id: <20210206150432.10456-1-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Signed-off-by: Markus Theil --- event.c | 30 ++++++++++++++++++++++++------ iw.h | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/event.c b/event.c index 61395f8..8bdbbe9 100644 --- a/event.c +++ b/event.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "iw.h" static int no_seq_check(struct nl_msg *msg, void *arg) @@ -905,12 +906,13 @@ static int print_event(struct nl_msg *msg, void *arg) int rem_nst; __u16 status; - if (args->time || args->reltime) { + if (args->time || args->reltime || args->ctime) { unsigned long long usecs, previous; previous = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec; gettimeofday(&args->ts, NULL); usecs = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec; + if (args->reltime) { if (!args->have_ts) { usecs = 0; @@ -918,7 +920,16 @@ static int print_event(struct nl_msg *msg, void *arg) } else usecs -= previous; } - printf("%llu.%06llu: ", usecs/1000000, usecs % 1000000); + + if (args->ctime) { + struct tm *tm = localtime(&args->ts.tv_sec); + char buf[255]; + + memset(buf, 0, 255); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); + printf("[%s.%06lu]: ", buf, args->ts.tv_usec); + } else + printf("%llu.%06llu: ", usecs/1000000, usecs % 1000000); } nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), @@ -1407,6 +1418,7 @@ static int print_events(struct nl80211_state *state, enum id_input id) { struct print_event_args args; + int num_time_formats = 0; int ret; memset(&args, 0, sizeof(args)); @@ -1417,17 +1429,22 @@ static int print_events(struct nl80211_state *state, while (argc > 0) { if (strcmp(argv[0], "-f") == 0) args.frame = true; - else if (strcmp(argv[0], "-t") == 0) + else if (strcmp(argv[0], "-t") == 0) { + num_time_formats++; args.time = true; - else if (strcmp(argv[0], "-r") == 0) + } else if (strcmp(argv[0], "-T") == 0) { + num_time_formats++; + args.ctime = true; + } else if (strcmp(argv[0], "-r") == 0) { + num_time_formats++; args.reltime = true; - else + } else return 1; argc--; argv++; } - if (args.time && args.reltime) + if (num_time_formats > 1) return 1; if (argc) @@ -1442,5 +1459,6 @@ static int print_events(struct nl80211_state *state, TOPLEVEL(event, "[-t|-r] [-f]", 0, 0, CIB_NONE, print_events, "Monitor events from the kernel.\n" "-t - print timestamp\n" + "-T - print absolute, human-readable timestamp\n" "-r - print relative timestamp\n" "-f - print full frame for auth/assoc etc."); diff --git a/iw.h b/iw.h index 807adec..7f7f4fc 100644 --- a/iw.h +++ b/iw.h @@ -181,7 +181,7 @@ int handle_cmd(struct nl80211_state *state, enum id_input idby, struct print_event_args { struct timeval ts; /* internal */ bool have_ts; /* must be set false */ - bool frame, time, reltime; + bool frame, time, reltime, ctime; }; __u32 listen_events(struct nl80211_state *state, -- 2.30.0