Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
19395:eb5ef6f5f58b | 19396:a961efb326e5 |
---|---|
3666 getout(1); | 3666 getout(1); |
3667 handle_swap_exists(NULL); | 3667 handle_swap_exists(NULL); |
3668 } | 3668 } |
3669 | 3669 |
3670 #endif // NO_VIM_MAIN | 3670 #endif // NO_VIM_MAIN |
3671 | |
3672 #if defined(STARTUPTIME) || defined(PROTO) | |
3673 static struct timeval prev_timeval; | |
3674 | |
3675 # ifdef MSWIN | |
3676 /* | |
3677 * Windows doesn't have gettimeofday(), although it does have struct timeval. | |
3678 */ | |
3679 static int | |
3680 gettimeofday(struct timeval *tv, char *dummy UNUSED) | |
3681 { | |
3682 long t = clock(); | |
3683 tv->tv_sec = t / CLOCKS_PER_SEC; | |
3684 tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC; | |
3685 return 0; | |
3686 } | |
3687 # endif | |
3688 | |
3689 /* | |
3690 * Save the previous time before doing something that could nest. | |
3691 * set "*tv_rel" to the time elapsed so far. | |
3692 */ | |
3693 void | |
3694 time_push(void *tv_rel, void *tv_start) | |
3695 { | |
3696 *((struct timeval *)tv_rel) = prev_timeval; | |
3697 gettimeofday(&prev_timeval, NULL); | |
3698 ((struct timeval *)tv_rel)->tv_usec = prev_timeval.tv_usec | |
3699 - ((struct timeval *)tv_rel)->tv_usec; | |
3700 ((struct timeval *)tv_rel)->tv_sec = prev_timeval.tv_sec | |
3701 - ((struct timeval *)tv_rel)->tv_sec; | |
3702 if (((struct timeval *)tv_rel)->tv_usec < 0) | |
3703 { | |
3704 ((struct timeval *)tv_rel)->tv_usec += 1000000; | |
3705 --((struct timeval *)tv_rel)->tv_sec; | |
3706 } | |
3707 *(struct timeval *)tv_start = prev_timeval; | |
3708 } | |
3709 | |
3710 /* | |
3711 * Compute the previous time after doing something that could nest. | |
3712 * Subtract "*tp" from prev_timeval; | |
3713 * Note: The arguments are (void *) to avoid trouble with systems that don't | |
3714 * have struct timeval. | |
3715 */ | |
3716 void | |
3717 time_pop( | |
3718 void *tp) // actually (struct timeval *) | |
3719 { | |
3720 prev_timeval.tv_usec -= ((struct timeval *)tp)->tv_usec; | |
3721 prev_timeval.tv_sec -= ((struct timeval *)tp)->tv_sec; | |
3722 if (prev_timeval.tv_usec < 0) | |
3723 { | |
3724 prev_timeval.tv_usec += 1000000; | |
3725 --prev_timeval.tv_sec; | |
3726 } | |
3727 } | |
3728 | |
3729 static void | |
3730 time_diff(struct timeval *then, struct timeval *now) | |
3731 { | |
3732 long usec; | |
3733 long msec; | |
3734 | |
3735 usec = now->tv_usec - then->tv_usec; | |
3736 msec = (now->tv_sec - then->tv_sec) * 1000L + usec / 1000L, | |
3737 usec = usec % 1000L; | |
3738 fprintf(time_fd, "%03ld.%03ld", msec, usec >= 0 ? usec : usec + 1000L); | |
3739 } | |
3740 | |
3741 void | |
3742 time_msg( | |
3743 char *mesg, | |
3744 void *tv_start) // only for do_source: start time; actually | |
3745 // (struct timeval *) | |
3746 { | |
3747 static struct timeval start; | |
3748 struct timeval now; | |
3749 | |
3750 if (time_fd != NULL) | |
3751 { | |
3752 if (strstr(mesg, "STARTING") != NULL) | |
3753 { | |
3754 gettimeofday(&start, NULL); | |
3755 prev_timeval = start; | |
3756 fprintf(time_fd, "\n\ntimes in msec\n"); | |
3757 fprintf(time_fd, " clock self+sourced self: sourced script\n"); | |
3758 fprintf(time_fd, " clock elapsed: other lines\n\n"); | |
3759 } | |
3760 gettimeofday(&now, NULL); | |
3761 time_diff(&start, &now); | |
3762 if (((struct timeval *)tv_start) != NULL) | |
3763 { | |
3764 fprintf(time_fd, " "); | |
3765 time_diff(((struct timeval *)tv_start), &now); | |
3766 } | |
3767 fprintf(time_fd, " "); | |
3768 time_diff(&prev_timeval, &now); | |
3769 prev_timeval = now; | |
3770 fprintf(time_fd, ": %s\n", mesg); | |
3771 } | |
3772 } | |
3773 | |
3774 #endif | |
3775 | 3671 |
3776 #if !defined(NO_VIM_MAIN) && defined(FEAT_EVAL) | 3672 #if !defined(NO_VIM_MAIN) && defined(FEAT_EVAL) |
3777 static void | 3673 static void |
3778 set_progpath(char_u *argv0) | 3674 set_progpath(char_u *argv0) |
3779 { | 3675 { |