nshlib/nsh_ddcmd: calculate time difference with microsecond precision

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
pengyiqiang 2022-07-15 16:23:39 +08:00 committed by Xiang Xiao
parent 83505e217b
commit 71ea8b052d

View File

@ -353,14 +353,15 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
elapsed = (((uint64_t)ts1.tv_sec * NSEC_PER_SEC) + ts1.tv_nsec);
elapsed -= (((uint64_t)ts0.tv_sec * NSEC_PER_SEC) + ts0.tv_nsec);
elapsed /= NSEC_PER_MSEC; /* msec */
elapsed /= NSEC_PER_USEC; /* usec */
total = ((uint64_t)dd.sector * (uint64_t)dd.sectsize);
nsh_output(vtbl, "%llu bytes copied, %u msec, ",
nsh_output(vtbl, "%llu bytes copied, %u usec, ",
total, (unsigned int)elapsed);
nsh_output(vtbl, "%u KB/s\n" ,
(unsigned int)((double)total / (double)elapsed));
(unsigned int)(((double)total / 1024)
/ ((double)elapsed / USEC_PER_SEC)));
#endif
errout_with_outf: