Occasionally I run a command like this: watch -n.1 ovs-ofctl dump-flows br0 to see how flows change over time. Until now, it has been more difficult than necessary to spot real changes, because flows "jump around" as the number of decimals printed for duration changes from moment to moment. That is, you might see cookie=0x0, duration=4.566s, table=0, n_packets=0, ... one moment, and then cookie=0x0, duration=4.8s, table=0, n_packets=0, ... the next moment. Shortening 4.8 to 4.800 shifts everything following it two places to the left, creating a visual jump.
This commit avoids that problem by always printing at least three decimals if we print any. There can still be an occasional jump if a duration is exactly on a second boundary, but that only happens 1/1000 of the time. Signed-off-by: Ben Pfaff <b...@nicira.com> --- lib/ofp-print.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 0f7278c..286af6f 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -860,10 +860,26 @@ static void ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec) { ds_put_format(string, "%u", sec); + + /* If there are no fractional seconds, don't print any decimals. + * + * If the fractional seconds can be expressed exactly as milliseconds, + * print 3 decimals. Open vSwitch provides millisecond precision for most + * time measurements, so printing 3 decimals every time makes it easier to + * spot real changes in flow dumps that refresh themselves quickly. + * + * If the factional seconds are more precise than milliseconds, print the + * number of decimals needed to express them exactly. + */ if (nsec > 0) { - ds_put_format(string, ".%09u", nsec); - while (string->string[string->length - 1] == '0') { - string->length--; + unsigned int msec = nsec / 1000000; + if (msec * 1000000 == nsec) { + ds_put_format(string, ".%03u", msec); + } else { + ds_put_format(string, ".%09u", nsec); + while (string->string[string->length - 1] == '0') { + string->length--; + } } } ds_put_char(string, 's'); -- 1.7.10.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev