Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

events: allow relative timestamps

  • Loading branch information...
commit 981b21adb6f032a0c9e1f3b982514abe3a54cef2 1 parent 5548dfd
@jmberg jmberg authored
Showing with 24 additions and 6 deletions.
  1. +21 −5 event.c
  2. +3 −1 iw.h
View
26 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.");
View
4 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,

0 comments on commit 981b21a

Please sign in to comment.
Something went wrong with that request. Please try again.