Print date when time is asked
I've been tracing function latency for a few days to see the distribution around the rare anomaly and it's getting inconvenient to see the exact time:
Tracing 1 functions for "get_page_from_freelist"... Hit Ctrl-C to end.
17:32:13
usecs : count distribution
0 -> 1 : 138719 |****************************************|
2 -> 3 : 4766 |* |
4 -> 7 : 623 | |
8 -> 15 : 538 | |
16 -> 31 : 115 | |
32 -> 63 : 5 | |
64 -> 127 : 1 | |
Including date into the time string would make it more useful. There are many places to fix:
$ fgrep '%H:%M:%S' -r tools
tools/argdist.py: print("[%s]" % strftime("%H:%M:%S"))
tools/bashreadline.py: print("%-9s %-6d %s" % (strftime("%H:%M:%S"), event.pid, event.str))
tools/biolatency.py: print("%-8s\n" % strftime("%H:%M:%S"), end="")
tools/biotop.py: print("%-8s loadavg: %s" % (strftime("%H:%M:%S"), stats.read()))
tools/btrfsdist.py: print(strftime("%H:%M:%S:"))
tools/btrfsslower.py: print("%-8s %-14.14s %-6s %1s %-7s %-8d %7.2f %s" % (strftime("%H:%M:%S"),
tools/cachestat.py: print("%-8s " % strftime("%H:%M:%S"), end="")
tools/cachetop.py: strftime("%H:%M:%S"), buff, cached, FIELDS[sort_field],
tools/cpudist.py: print("%-8s\n" % strftime("%H:%M:%S"), end="")
tools/dcstat.py: print("%-8s: " % strftime("%H:%M:%S"), end="")
tools/ext4dist.py: print(strftime("%H:%M:%S:"))
tools/ext4slower.py: print("%-8s %-14.14s %-6s %1s %-7s %-8d %7.2f %s" % (strftime("%H:%M:%S"),
tools/filelife.py: print("%-8s %-6d %-16s %-7.2f %s" % (strftime("%H:%M:%S"), event.pid,
tools/filetop.py: print("%-8s loadavg: %s" % (strftime("%H:%M:%S"), stats.read()))
tools/funccount.py: print("%-8s\n" % strftime("%H:%M:%S"), end="")
tools/funclatency.py: print("%-8s\n" % strftime("%H:%M:%S"), end="")
tools/gethostlatency.py: print("%-9s %-6d %-16s %10.2f %s" % (strftime("%H:%M:%S"), event.pid,
tools/hardirqs.py: print("%-8s\n" % strftime("%H:%M:%S"), end="")
tools/killsnoop.py: print("%-9s %-6d %-16s %-4d %-6d %d" % (strftime("%H:%M:%S"),
tools/mdflush.py: print("%-8s %-6d %-16s %s" % (strftime("%H:%M:%S"), event.pid, event.comm,
tools/memleak.py: (datetime.now().strftime("%H:%M:%S"), top_stacks))
tools/old/bashreadline.py: print("%-9s %-6d %s" % (strftime("%H:%M:%S"), pid, msg))
tools/old/filelife.py: print("%-8s %-6d %-16s %-7.2f %s" % (strftime("%H:%M:%S"), pid, task,
tools/old/gethostlatency.py: print("%-9s %-6d %-12.12s %6.2f %s" % (strftime("%H:%M:%S"), pid, task,
tools/old/memleak.py: (datetime.now().strftime("%H:%M:%S"), top_stacks))
tools/old/stackcount.py: print("%-8s\n" % strftime("%H:%M:%S"), end="")
tools/oomkill.py: ", %d pages, loadavg: %s") % (strftime("%H:%M:%S"), event.fpid,
tools/pidpersec.py: print("%s: PIDs/sec: %d" % (strftime("%H:%M:%S"),
tools/runqlat.py: print("%-8s\n" % strftime("%H:%M:%S"), end="")
tools/softirqs.py: print("%-8s\n" % strftime("%H:%M:%S"), end="")
tools/stackcount.py: print("%-8s\n" % strftime("%H:%M:%S"), end="")
tools/tcpretrans.py: strftime("%H:%M:%S"), event.pid, event.ip,
tools/tcpretrans.py: strftime("%H:%M:%S"), event.pid, event.ip,
tools/trace.py: time = strftime("%H:%M:%S") if Probe.use_localtime else \
tools/vfsstat.py: print("%-8s: " % strftime("%H:%M:%S"), end="")
tools/xfsdist.py: print(strftime("%H:%M:%S:"))
tools/xfsslower.py: print("%-8s %-14.14s %-6s %1s %-7s %-8d %7.2f %s" % (strftime("%H:%M:%S"),
tools/zfsdist.py: print(strftime("%H:%M:%S:"))
tools/zfsslower.py: print("%-8s %-14.14s %-6s %1s %-7s %-8d %7.2f %s" % (strftime("%H:%M:%S"),
I'd really rather you didn't.
- There are cases where the time is used in a column, and we very much want to stay within 80 chars as much as possible.
- The time in this simple format was inspired by sar. No one has "fixed" sar.
- These tools are designed for ad hoc usage, just like vmstat/iostat/tcpdump/top. By running this over a day, you're turning it into a monitoring tool, and now you want to change the output to suit your use case. That's not the common use case.
- I'd like as much as possible for the default output to be uncluttered to let the end user focus on the important information.
I've done this in the past -- provided full time & day strings -- by use of a command line option. My preference would be:
- A low frequency per event tool where second resolution is sufficient, and few columns: HH:MM:SS included by default
- A high frequency per event tool where sub-second resolution is desired, and few columns: seconds.fraction included by default
- An interval summary tool with few columns: HH:MM:SS included by default
- A per event or interval summary tool with many columns, pushing the 80 char limit: HH:MM:SS or seconds.fraction included only with -T.
- A histogram summary tool: No time by default, HH:MM:SS included with -T.
Maybe, maybe, there's some tool that we'd obviously want to run for >24 hours, and another option could be addded, "--full-timestamp", which printed with the date. But that would be the exception.
Something I'd like to see fixed is the time removed from some of the histogram output tools by default, and only included with an option, like -T.
Adding to this, for tools that need high resolution time I would prefer HH:MM:SS.MMM, and to obtain the timestamp directly from BPF instead of taking the time when Python received the event. Several times now I have wanted to match events to other tools (e.g. ngrep) with sub-second resolution. This requires a format that is both synchronized to wall time and has sub-second granularity.
+1
On 19 Aug 2016 20:00, "Mark Drayton" [email protected] wrote:
Adding to this, for tools that need high resolution time I would prefer HH:MM:SS.MMM, and to obtain the timestamp directly from BPF instead of taking the time when Python received the event. Several times now I have wanted to match events to other tools (e.g. ngrep) with sub-second resolution. This requires a format that is both synchronized to wall time and has sub-second granularity.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/iovisor/bcc/issues/666#issuecomment-241105880, or mute the thread https://github.com/notifications/unsubscribe-auth/ADPbVFBDGiNm39ex-SKth7hENDxWoG9Iks5qhf06gaJpZM4Jndn2 .
And at times, especially for biosnoop, I'll take the output of seconds.fraction format and load it in a spreadsheet or another tool (eg, subsecond offset heatmap, or some ad hoc awk). That won't work well with HH:MM:SS.MMM -- I'd usually need to post-process to turn it back into seconds.fraction.
This is also why the original iosnoop had:
# iosnoop -h
[...]
-t # print completion time, us
-v # print completion time, string
[...]
-t was for use with other tools, and -v was the full time & date format. (And default had nothing.)
HH:MM:SS.MMM is more likely to push us beyond 80 chars.
I suppose, if we had to, we could have three options:
- -T: timestamps as HH:MM:SS (include .MMM only if that resolution is commonly desired: if the tool prints high frequency sub-second events, like biosnoop, and not like oomkill).
- --full-timestamp: time & date
- --raw-timestamp: seconds.fraction
Maybe the latter two can have single character versions, but that might be overkill.
Yes, anytime we have a fraction we should be pulling it from kernel BPF, not Python.
I'd print time only in secs.usecs format similar to ftrace and dmesg. Note that bpf_ktime_get_ns() returns the time using the same source as clock_gettime(CLOCK_MONOTONIC, &ts); in user space, so they can be directly compared. No idea how python gets its time.
I'd use bpf_ktime_get_ns() when compared to before for getting delta . I want know when happened(e.g signal), the HH:MM:SS.MMM perfect. I'd like BPF kernel can convert bpf_ktime_get_ns() to HH:MM:SS.MMM, or support HH:MM:SS.MMM. Python can do read /proc/update, it's ugly.
These tools are designed for ad hoc usage, just like vmstat/iostat/tcpdump/top. By running this over a day, you're turning it into a monitoring tool, and now you want to change the output to suit your use case. That's not the common use case.
I covered my needs with https://github.com/cloudflare/ebpf_exporter.