public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-nex] tools: bpftool: change time format for program 'loaded at:' information
@ 2018-05-01 20:18 Quentin Monnet
  2018-05-01 21:25 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Quentin Monnet @ 2018-05-01 20:18 UTC (permalink / raw)
  To: ast, borkmann; +Cc: netdev, oss-drivers, quentin.monnet

To make eBPF program load time easier to parse from "bpftool prog"
output for machines, change the time format used by the program. The
format now differs for plain and JSON version:

- Plain version uses a string formatted according to ISO 8601.
- JSON uses the number of seconds since the Epoch, wich is less friendly
  for humans but even easier to process.

Example output:

    # ./bpftool prog
    41298: xdp  tag a04f5eef06a7f555 dev foo
            loaded_at 2018-04-18T17:19:47+0100  uid 0
            xlated 16B  not jited  memlock 4096B

    # ./bpftool prog -p
    [{
            "id": 41298,
            "type": "xdp",
            "tag": "a04f5eef06a7f555",
            "gpl_compatible": false,
            "dev": {
                "ifindex": 14,
                "ns_dev": 3,
                "ns_inode": 4026531993,
                "ifname": "foo"
            },
            "loaded_at": 1524068387,
            "uid": 0,
            "bytes_xlated": 16,
            "jited": false,
            "bytes_memlock": 4096
        }
    ]

Previously, "Apr 18/17:19" would be used at both places.

Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 tools/bpf/bpftool/prog.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index e71a0a11afde..9bdfdf2d3fbe 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -96,7 +96,10 @@ static void print_boot_time(__u64 nsecs, char *buf, unsigned int size)
 		return;
 	}
 
-	strftime(buf, size, "%b %d/%H:%M", &load_tm);
+	if (json_output)
+		strftime(buf, size, "%s", &load_tm);
+	else
+		strftime(buf, size, "%FT%T%z", &load_tm);
 }
 
 static int prog_fd_by_tag(unsigned char *tag)
@@ -245,7 +248,8 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
 		print_boot_time(info->load_time, buf, sizeof(buf));
 
 		/* Piggy back on load_time, since 0 uid is a valid one */
-		jsonw_string_field(json_wtr, "loaded_at", buf);
+		jsonw_name(json_wtr, "loaded_at");
+		jsonw_printf(json_wtr, "%s", buf);
 		jsonw_uint_field(json_wtr, "uid", info->created_by_uid);
 	}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-nex] tools: bpftool: change time format for program 'loaded at:' information
  2018-05-01 20:18 [PATCH bpf-nex] tools: bpftool: change time format for program 'loaded at:' information Quentin Monnet
@ 2018-05-01 21:25 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2018-05-01 21:25 UTC (permalink / raw)
  To: Quentin Monnet; +Cc: ast, borkmann, netdev, oss-drivers

On Tue, May 01, 2018 at 09:18:38PM +0100, Quentin Monnet wrote:
> To make eBPF program load time easier to parse from "bpftool prog"
> output for machines, change the time format used by the program. The
> format now differs for plain and JSON version:
> 
> - Plain version uses a string formatted according to ISO 8601.
> - JSON uses the number of seconds since the Epoch, wich is less friendly
>   for humans but even easier to process.
> 
> Example output:
> 
>     # ./bpftool prog
>     41298: xdp  tag a04f5eef06a7f555 dev foo
>             loaded_at 2018-04-18T17:19:47+0100  uid 0
>             xlated 16B  not jited  memlock 4096B
> 
>     # ./bpftool prog -p
>     [{
>             "id": 41298,
>             "type": "xdp",
>             "tag": "a04f5eef06a7f555",
>             "gpl_compatible": false,
>             "dev": {
>                 "ifindex": 14,
>                 "ns_dev": 3,
>                 "ns_inode": 4026531993,
>                 "ifname": "foo"
>             },
>             "loaded_at": 1524068387,
>             "uid": 0,
>             "bytes_xlated": 16,
>             "jited": false,
>             "bytes_memlock": 4096
>         }
>     ]
> 
> Previously, "Apr 18/17:19" would be used at both places.
> 
> Suggested-by: Alexei Starovoitov <ast@kernel.org>
> Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
> Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>

Applied, Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-01 21:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-01 20:18 [PATCH bpf-nex] tools: bpftool: change time format for program 'loaded at:' information Quentin Monnet
2018-05-01 21:25 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox