]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
events: allow relative timestamps
authorJohannes Berg <johannes.berg@intel.com>
Wed, 13 Oct 2010 15:52:15 +0000 (17:52 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 13 Oct 2010 15:52:15 +0000 (17:52 +0200)
event.c
iw.h

diff --git a/event.c b/event.c
index ac2dabc51c2359873e3a2166a843086b8c3d3051..6f3faa25e556f91916d9933808dcf1e390daf30b 100644 (file)
--- a/event.c
+++ b/event.c
@@ -141,10 +141,20 @@ static int print_event(struct nl_msg *msg, void *arg)
        int rem_nst;
        __u16 status;
 
-       if (args->time) {
-               struct timeval tv;
-               gettimeofday(&tv, NULL);
-               printf("%ld.%06u: ", (long) tv.tv_sec, (unsigned int) tv.tv_usec);
+       if (args->time || args->reltime) {
+               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;
+                               args->have_ts = true;
+                       } else
+                               usecs -= previous;
+               }
+               printf("%llu.%06llu: ", usecs/1000000, usecs % 1000000);
        }
 
        nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
@@ -477,12 +487,17 @@ static int print_events(struct nl80211_state *state,
                        args.frame = true;
                else if (strcmp(argv[0], "-t") == 0)
                        args.time = true;
+               else if (strcmp(argv[0], "-r") == 0)
+                       args.reltime = true;
                else
                        return 1;
                argc--;
                argv++;
        }
 
+       if (args.time && args.reltime)
+               return 1;
+
        if (argc)
                return 1;
 
@@ -492,7 +507,8 @@ static int print_events(struct nl80211_state *state,
 
        return __do_listen_events(state, 0, NULL, &args);
 }
-TOPLEVEL(event, "[-t] [-f]", 0, 0, CIB_NONE, print_events,
+TOPLEVEL(event, "[-t] [-r] [-f]", 0, 0, CIB_NONE, print_events,
        "Monitor events from the kernel.\n"
        "-t - print timestamp\n"
+       "-r - print relative timstamp\n"
        "-f - print full frame for auth/assoc etc.");
diff --git a/iw.h b/iw.h
index c21f093d4e93833e2b83e0fe898c81ba7ebb5c45..5eb9083b823d1ba5fbd267940421c4100bc0bbf7 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -105,7 +105,9 @@ int handle_cmd(struct nl80211_state *state, enum id_input idby,
               int argc, char **argv);
 
 struct print_event_args {
-       bool frame, time;
+       struct timeval ts; /* internal */
+       bool have_ts; /* must be set false */
+       bool frame, time, reltime;
 };
 
 __u32 listen_events(struct nl80211_state *state,