Mercurial > vim
diff src/main.c @ 19396:a961efb326e5 v8.2.0256
patch 8.2.0256: time and timer related code is spread out
Commit: https://github.com/vim/vim/commit/0a8fed6231c84e4e1b3a7dd6c0d95d3f98207fe0
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Feb 14 13:22:17 2020 +0100
patch 8.2.0256: time and timer related code is spread out
Problem: Time and timer related code is spread out.
Solution: Move time and timer related code to a new file. (Yegappan
Lakshmanan, closes #5604)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 14 Feb 2020 13:30:05 +0100 |
parents | 5f2cb68f7cb8 |
children | 031184ace7c5 |
line wrap: on
line diff
--- a/src/main.c +++ b/src/main.c @@ -3669,110 +3669,6 @@ check_swap_exists_action(void) #endif // NO_VIM_MAIN -#if defined(STARTUPTIME) || defined(PROTO) -static struct timeval prev_timeval; - -# ifdef MSWIN -/* - * Windows doesn't have gettimeofday(), although it does have struct timeval. - */ - static int -gettimeofday(struct timeval *tv, char *dummy UNUSED) -{ - long t = clock(); - tv->tv_sec = t / CLOCKS_PER_SEC; - tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC; - return 0; -} -# endif - -/* - * Save the previous time before doing something that could nest. - * set "*tv_rel" to the time elapsed so far. - */ - void -time_push(void *tv_rel, void *tv_start) -{ - *((struct timeval *)tv_rel) = prev_timeval; - gettimeofday(&prev_timeval, NULL); - ((struct timeval *)tv_rel)->tv_usec = prev_timeval.tv_usec - - ((struct timeval *)tv_rel)->tv_usec; - ((struct timeval *)tv_rel)->tv_sec = prev_timeval.tv_sec - - ((struct timeval *)tv_rel)->tv_sec; - if (((struct timeval *)tv_rel)->tv_usec < 0) - { - ((struct timeval *)tv_rel)->tv_usec += 1000000; - --((struct timeval *)tv_rel)->tv_sec; - } - *(struct timeval *)tv_start = prev_timeval; -} - -/* - * Compute the previous time after doing something that could nest. - * Subtract "*tp" from prev_timeval; - * Note: The arguments are (void *) to avoid trouble with systems that don't - * have struct timeval. - */ - void -time_pop( - void *tp) // actually (struct timeval *) -{ - prev_timeval.tv_usec -= ((struct timeval *)tp)->tv_usec; - prev_timeval.tv_sec -= ((struct timeval *)tp)->tv_sec; - if (prev_timeval.tv_usec < 0) - { - prev_timeval.tv_usec += 1000000; - --prev_timeval.tv_sec; - } -} - - static void -time_diff(struct timeval *then, struct timeval *now) -{ - long usec; - long msec; - - usec = now->tv_usec - then->tv_usec; - msec = (now->tv_sec - then->tv_sec) * 1000L + usec / 1000L, - usec = usec % 1000L; - fprintf(time_fd, "%03ld.%03ld", msec, usec >= 0 ? usec : usec + 1000L); -} - - void -time_msg( - char *mesg, - void *tv_start) // only for do_source: start time; actually - // (struct timeval *) -{ - static struct timeval start; - struct timeval now; - - if (time_fd != NULL) - { - if (strstr(mesg, "STARTING") != NULL) - { - gettimeofday(&start, NULL); - prev_timeval = start; - fprintf(time_fd, "\n\ntimes in msec\n"); - fprintf(time_fd, " clock self+sourced self: sourced script\n"); - fprintf(time_fd, " clock elapsed: other lines\n\n"); - } - gettimeofday(&now, NULL); - time_diff(&start, &now); - if (((struct timeval *)tv_start) != NULL) - { - fprintf(time_fd, " "); - time_diff(((struct timeval *)tv_start), &now); - } - fprintf(time_fd, " "); - time_diff(&prev_timeval, &now); - prev_timeval = now; - fprintf(time_fd, ": %s\n", mesg); - } -} - -#endif - #if !defined(NO_VIM_MAIN) && defined(FEAT_EVAL) static void set_progpath(char_u *argv0)