From 2689f58f2a0afa296a29ab301a4c1665b914caab Mon Sep 17 00:00:00 2001 From: Zachary T Welch Date: Sat, 7 Nov 2009 23:20:33 -0800 Subject: Overhaul time support API This patch changes the duration_* API in several ways. First, it updates the API to use better names. Second, string formatting has been removed from the API (with its associated malloc). Finally, a new function added to convert the time into seconds, which can be used (or formatted) by the caller. This eliminates hidden calls to malloc that require associated calls to free(). This patch also removes the useless extern keyword from prototypes, and it eliminates the duration_t typedef (use 'struct duration'). These API also allows proper error checking, as it is possible for gettimeofday to fail in certain circumstances. The consumers have all been chased to use this new API as well, as there were relatively few cases doing this type of measurement. In most cases, the code performs additional checks for errors, but the calling code looks much cleaner in every case. --- src/flash/nand.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/flash/nand.c') diff --git a/src/flash/nand.c b/src/flash/nand.c index 81a04f7a..8f67624d 100644 --- a/src/flash/nand.c +++ b/src/flash/nand.c @@ -1330,8 +1330,6 @@ static int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cm fileio_t fileio; - duration_t duration; - char *duration_text; if (argc < 3) { @@ -1372,7 +1370,8 @@ static int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cm } } - duration_start_measure(&duration); + struct duration bench; + duration_start(&bench); if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK) { @@ -1478,11 +1477,13 @@ static int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cm free(page); oob = NULL; page = NULL; - duration_stop_measure(&duration, &duration_text); - command_print(cmd_ctx, "wrote file %s to NAND flash %s up to offset 0x%8.8" PRIx32 " in %s", - args[1], args[0], offset, duration_text); - free(duration_text); - duration_text = NULL; + if (duration_measure(&bench) == ERROR_OK) + { + command_print(cmd_ctx, "wrote file %s to NAND flash %s " + "up to offset 0x%8.8" PRIx32 " in %fs (%0.3f kb/s)", + args[1], args[0], offset, duration_elapsed(&bench), + duration_kbps(&bench, fileio.size)); + } return ERROR_OK; } @@ -1506,8 +1507,6 @@ static int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd } fileio_t fileio; - duration_t duration; - char *duration_text; uint8_t *page = NULL; uint32_t page_size = 0; @@ -1560,7 +1559,8 @@ static int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd return ERROR_OK; } - duration_start_measure(&duration); + struct duration bench; + duration_start(&bench); while (size > 0) { @@ -1596,10 +1596,12 @@ static int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd oob = NULL; fileio_close(&fileio); - duration_stop_measure(&duration, &duration_text); - command_print(cmd_ctx, "dumped %lld byte in %s", fileio.size, duration_text); - free(duration_text); - duration_text = NULL; + if (duration_measure(&bench) == ERROR_OK) + { + command_print(cmd_ctx, "dumped %lld byte in %fs (%0.3f kb/s)", + fileio.size, duration_elapsed(&bench), + duration_kbps(&bench, fileio.size)); + } return ERROR_OK; } -- cgit v1.2.3