comparison src/ex_cmds2.c @ 177:84c21eb4fc40

updated for version 7.0054
author vimboss
date Mon, 28 Feb 2005 22:44:58 +0000
parents 8c60f65311fa
children d292c40ca788
comparison
equal deleted inserted replaced
176:df9a1e1ffecd 177:84c21eb4fc40
24 #include "version.h" 24 #include "version.h"
25 25
26 static void cmd_source __ARGS((char_u *fname, exarg_T *eap)); 26 static void cmd_source __ARGS((char_u *fname, exarg_T *eap));
27 27
28 #ifdef FEAT_EVAL 28 #ifdef FEAT_EVAL
29 /* Growarray to store the names of sourced scripts. 29 /* Growarray to store info about already sourced scripts.
30 * For Unix also store the dev/ino, so that we don't have to stat() each 30 * For Unix also store the dev/ino, so that we don't have to stat() each
31 * script when going through the list. */ 31 * script when going through the list. */
32 typedef struct scriptitem_S 32 typedef struct scriptitem_S
33 { 33 {
34 char_u *sn_name; 34 char_u *sn_name;
36 int sn_dev; 36 int sn_dev;
37 ino_t sn_ino; 37 ino_t sn_ino;
38 # endif 38 # endif
39 # ifdef FEAT_PROFILE 39 # ifdef FEAT_PROFILE
40 int sn_prof_on; /* TRUE when script is/was profiled */ 40 int sn_prof_on; /* TRUE when script is/was profiled */
41 int sn_pr_force; /* forceit: profile defined functions */ 41 int sn_pr_force; /* forceit: profile functions in this script */
42 proftime_T sn_pr_child; /* time set when going into first child */ 42 proftime_T sn_pr_child; /* time set when going into first child */
43 int sn_pr_nest; /* nesting for sn_pr_child */ 43 int sn_pr_nest; /* nesting for sn_pr_child */
44 /* profiling the script as a whole */ 44 /* profiling the script as a whole */
45 int sn_pr_count; /* nr of times sourced */ 45 int sn_pr_count; /* nr of times sourced */
46 proftime_T sn_pr_total; /* time spend in script + children */ 46 proftime_T sn_pr_total; /* time spend in script + children */
800 */ 800 */
801 void 801 void
802 profile_zero(tm) 802 profile_zero(tm)
803 proftime_T *tm; 803 proftime_T *tm;
804 { 804 {
805 # ifdef WIN3264
806 tm->QuadPart = 0;
807 # else
805 tm->tv_usec = 0; 808 tm->tv_usec = 0;
806 tm->tv_sec = 0; 809 tm->tv_sec = 0;
810 # endif
807 } 811 }
808 812
809 /* 813 /*
810 * Store the current time in "tm". 814 * Store the current time in "tm".
811 */ 815 */
812 void 816 void
813 profile_start(tm) 817 profile_start(tm)
814 proftime_T *tm; 818 proftime_T *tm;
815 { 819 {
820 # ifdef WIN3264
821 QueryPerformanceCounter(tm);
822 # else
816 gettimeofday(tm, NULL); 823 gettimeofday(tm, NULL);
824 # endif
817 } 825 }
818 826
819 /* 827 /*
820 * Compute the elapsed time from "tm" till now and store in "tm". 828 * Compute the elapsed time from "tm" till now and store in "tm".
821 */ 829 */
823 profile_end(tm) 831 profile_end(tm)
824 proftime_T *tm; 832 proftime_T *tm;
825 { 833 {
826 proftime_T now; 834 proftime_T now;
827 835
836 # ifdef WIN3264
837 QueryPerformanceCounter(&now);
838 tm->QuadPart = now.QuadPart - tm->QuadPart;
839 # else
828 gettimeofday(&now, NULL); 840 gettimeofday(&now, NULL);
829 tm->tv_usec = now.tv_usec - tm->tv_usec; 841 tm->tv_usec = now.tv_usec - tm->tv_usec;
830 tm->tv_sec = now.tv_sec - tm->tv_sec; 842 tm->tv_sec = now.tv_sec - tm->tv_sec;
831 if (tm->tv_usec < 0) 843 if (tm->tv_usec < 0)
832 { 844 {
833 tm->tv_usec += 1000000; 845 tm->tv_usec += 1000000;
834 --tm->tv_sec; 846 --tm->tv_sec;
835 } 847 }
848 # endif
836 } 849 }
837 850
838 /* 851 /*
839 * Subtract the time "tm2" from "tm". 852 * Subtract the time "tm2" from "tm".
840 */ 853 */
841 void 854 void
842 profile_sub(tm, tm2) 855 profile_sub(tm, tm2)
843 proftime_T *tm, *tm2; 856 proftime_T *tm, *tm2;
844 { 857 {
858 # ifdef WIN3264
859 tm->QuadPart -= tm2->QuadPart;
860 # else
845 tm->tv_usec -= tm2->tv_usec; 861 tm->tv_usec -= tm2->tv_usec;
846 tm->tv_sec -= tm2->tv_sec; 862 tm->tv_sec -= tm2->tv_sec;
847 if (tm->tv_usec < 0) 863 if (tm->tv_usec < 0)
848 { 864 {
849 tm->tv_usec += 1000000; 865 tm->tv_usec += 1000000;
850 --tm->tv_sec; 866 --tm->tv_sec;
851 } 867 }
868 # endif
852 } 869 }
853 870
854 /* 871 /*
855 * Add the time "tm2" to "tm". 872 * Add the time "tm2" to "tm".
856 */ 873 */
857 void 874 void
858 profile_add(tm, tm2) 875 profile_add(tm, tm2)
859 proftime_T *tm, *tm2; 876 proftime_T *tm, *tm2;
860 { 877 {
878 # ifdef WIN3264
879 tm->QuadPart += tm2->QuadPart;
880 # else
861 tm->tv_usec += tm2->tv_usec; 881 tm->tv_usec += tm2->tv_usec;
862 tm->tv_sec += tm2->tv_sec; 882 tm->tv_sec += tm2->tv_sec;
863 if (tm->tv_usec >= 1000000) 883 if (tm->tv_usec >= 1000000)
864 { 884 {
865 tm->tv_usec -= 1000000; 885 tm->tv_usec -= 1000000;
866 ++tm->tv_sec; 886 ++tm->tv_sec;
867 } 887 }
888 # endif
868 } 889 }
869 890
870 /* 891 /*
871 * Get the current waittime. 892 * Get the current waittime.
872 */ 893 */
895 */ 916 */
896 int 917 int
897 profile_equal(tm1, tm2) 918 profile_equal(tm1, tm2)
898 proftime_T *tm1, *tm2; 919 proftime_T *tm1, *tm2;
899 { 920 {
921 # ifdef WIN3264
922 return (tm1->QuadPart == tm2->QuadPart);
923 # else
900 return (tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec); 924 return (tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec);
925 # endif
926 }
927
928 /*
929 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2"
930 */
931 int
932 profile_cmp(tm1, tm2)
933 proftime_T *tm1, *tm2;
934 {
935 # ifdef WIN3264
936 return (int)(tm2->QuadPart - tm1->QuadPart);
937 # else
938 if (tm1->tv_sec == tm2->tv_sec)
939 return tm2->tv_usec - tm1->tv_usec;
940 return tm2->tv_sec - tm1->tv_sec;
941 # endif
901 } 942 }
902 943
903 /* 944 /*
904 * Return a string that represents a time. 945 * Return a string that represents a time.
905 * Uses a static buffer! 946 * Uses a static buffer!
908 profile_msg(tm) 949 profile_msg(tm)
909 proftime_T *tm; 950 proftime_T *tm;
910 { 951 {
911 static char buf[50]; 952 static char buf[50];
912 953
954 # ifdef WIN3264
955 LARGE_INTEGER fr;
956
957 QueryPerformanceFrequency(&fr);
958 sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart);
959 # else
913 sprintf(buf, "%3ld.%06ld", (long)tm->tv_sec, (long)tm->tv_usec); 960 sprintf(buf, "%3ld.%06ld", (long)tm->tv_sec, (long)tm->tv_usec);
961 #endif
914 return buf; 962 return buf;
915 } 963 }
916 964
917 static char_u *profile_fname = NULL; 965 static char_u *profile_fname = NULL;
918 966
960 fd = fopen((char *)profile_fname, "w"); 1008 fd = fopen((char *)profile_fname, "w");
961 if (fd == NULL) 1009 if (fd == NULL)
962 EMSG2(_(e_notopen), profile_fname); 1010 EMSG2(_(e_notopen), profile_fname);
963 else 1011 else
964 { 1012 {
1013 script_dump_profile(fd);
965 func_dump_profile(fd); 1014 func_dump_profile(fd);
966 script_dump_profile(fd);
967 fclose(fd); 1015 fclose(fd);
968 } 1016 }
969 } 1017 }
970 } 1018 }
971 1019