X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fhelper%2Ftime_support.c;h=9615817fc591cc04964fdded03a425ab4dea2e61;hp=620c9c488e675dfdf2f46a0d30539197f00475c6;hb=5ed126c4f90948fbf53d186dc4ef49018fb5ecfc;hpb=82d2633b5f550115e9e7c7d0520babb6680aa38f diff --git a/src/helper/time_support.c b/src/helper/time_support.c index 620c9c488e..9615817fc5 100644 --- a/src/helper/time_support.c +++ b/src/helper/time_support.c @@ -22,7 +22,9 @@ #endif #include "time_support.h" +#include "log.h" +#include #include #include @@ -82,3 +84,26 @@ int timeval_add_time(struct timeval *result, int sec, int usec) return 0; } +int duration_start_measure(duration_t *duration) +{ + gettimeofday(&duration->start, NULL); + + return ERROR_OK; +} + +int duration_stop_measure(duration_t *duration, char **text) +{ + struct timeval end; + + gettimeofday(&end, NULL); + + timeval_subtract(&duration->duration, &end, &duration->start); + + if (text) + { + *text = malloc(16); + snprintf(*text, 16, "%lis %lius", duration->duration.tv_sec, duration->duration.tv_usec); + } + + return ERROR_OK; +}