X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fofp-print.c;h=4c89b3676e7246de9e7d504cd2b4babb1608cd04;hb=54a1cfb53616baeef103bd8e395768fc344b1cc6;hp=0f7278cbb89abb596ad9295675362f80f6bc7b6d;hpb=428b2eddc9c47d8306252f0fc5218839d2ff017c;p=sliver-openvswitch.git diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 0f7278cbb..4c89b3676 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 fractional 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');