Mercurial > vim
annotate src/profiler.c @ 32669:448aef880252
normalize line endings
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 26 Jun 2023 09:54:34 +0200 |
parents | d863a33cb220 |
children | 695b50472e85 |
rev | line source |
---|---|
32669
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
2 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
4 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
8 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
9 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
10 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
11 * profiler.c: vim script profiler |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
12 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
13 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
14 #include "vim.h" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
15 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
16 #if defined(FEAT_EVAL) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
17 # if defined(FEAT_PROFILE) || defined(FEAT_RELTIME) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
18 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
19 * Store the current time in "tm". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
20 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
21 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
22 profile_start(proftime_T *tm) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
23 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
24 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
25 QueryPerformanceCounter(tm); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
26 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
27 PROF_GET_TIME(tm); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
28 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
29 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
30 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
31 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
32 * Compute the elapsed time from "tm" till now and store in "tm". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
33 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
34 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
35 profile_end(proftime_T *tm) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
36 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
37 proftime_T now; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
38 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
39 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
40 QueryPerformanceCounter(&now); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
41 tm->QuadPart = now.QuadPart - tm->QuadPart; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
42 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
43 PROF_GET_TIME(&now); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
44 tm->tv_fsec = now.tv_fsec - tm->tv_fsec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
45 tm->tv_sec = now.tv_sec - tm->tv_sec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
46 if (tm->tv_fsec < 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
47 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
48 tm->tv_fsec += TV_FSEC_SEC; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
49 --tm->tv_sec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
50 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
51 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
52 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
53 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
54 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
55 * Subtract the time "tm2" from "tm". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
56 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
57 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
58 profile_sub(proftime_T *tm, proftime_T *tm2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
59 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
60 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
61 tm->QuadPart -= tm2->QuadPart; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
62 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
63 tm->tv_fsec -= tm2->tv_fsec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
64 tm->tv_sec -= tm2->tv_sec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
65 if (tm->tv_fsec < 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
66 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
67 tm->tv_fsec += TV_FSEC_SEC; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
68 --tm->tv_sec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
69 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
70 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
71 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
72 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
73 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
74 * Return a string that represents the time in "tm". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
75 * Uses a static buffer! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
76 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
77 char * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
78 profile_msg(proftime_T *tm) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
79 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
80 static char buf[50]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
81 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
82 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
83 LARGE_INTEGER fr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
84 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
85 QueryPerformanceFrequency(&fr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
86 sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
87 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
88 sprintf(buf, PROF_TIME_FORMAT, (long)tm->tv_sec, (long)tm->tv_fsec); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
89 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
90 return buf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
91 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
92 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
93 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
94 * Return a float that represents the time in "tm". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
95 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
96 float_T |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
97 profile_float(proftime_T *tm) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
98 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
99 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
100 LARGE_INTEGER fr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
101 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
102 QueryPerformanceFrequency(&fr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
103 return (float_T)tm->QuadPart / (float_T)fr.QuadPart; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
104 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
105 return (float_T)tm->tv_sec + (float_T)tm->tv_fsec / (float_T)TV_FSEC_SEC; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
106 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
107 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
108 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
109 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
110 * Put the time "msec" past now in "tm". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
111 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
112 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
113 profile_setlimit(long msec, proftime_T *tm) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
114 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
115 if (msec <= 0) // no limit |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
116 profile_zero(tm); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
117 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
118 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
119 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
120 LARGE_INTEGER fr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
121 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
122 QueryPerformanceCounter(tm); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
123 QueryPerformanceFrequency(&fr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
124 tm->QuadPart += (LONGLONG)((double)msec / 1000.0 * (double)fr.QuadPart); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
125 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
126 varnumber_T fsec; // this should be 64 bit if possible |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
127 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
128 PROF_GET_TIME(tm); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
129 fsec = (varnumber_T)tm->tv_fsec |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
130 + (varnumber_T)msec * (varnumber_T)(TV_FSEC_SEC / 1000); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
131 tm->tv_fsec = fsec % (long)TV_FSEC_SEC; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
132 tm->tv_sec += fsec / (long)TV_FSEC_SEC; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
133 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
134 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
135 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
136 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
137 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
138 * Return TRUE if the current time is past "tm". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
139 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
140 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
141 profile_passed_limit(proftime_T *tm) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
142 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
143 proftime_T now; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
144 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
145 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
146 if (tm->QuadPart == 0) // timer was not set |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
147 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
148 QueryPerformanceCounter(&now); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
149 return (now.QuadPart > tm->QuadPart); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
150 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
151 if (tm->tv_sec == 0) // timer was not set |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
152 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
153 PROF_GET_TIME(&now); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
154 return (now.tv_sec > tm->tv_sec |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
155 || (now.tv_sec == tm->tv_sec && now.tv_fsec > tm->tv_fsec)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
156 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
157 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
158 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
159 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
160 * Set the time in "tm" to zero. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
161 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
162 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
163 profile_zero(proftime_T *tm) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
164 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
165 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
166 tm->QuadPart = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
167 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
168 tm->tv_fsec = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
169 tm->tv_sec = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
170 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
171 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
172 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
173 # endif // FEAT_PROFILE || FEAT_RELTIME |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
174 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
175 #if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_PROFILE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
176 # if defined(HAVE_MATH_H) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
177 # include <math.h> |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
178 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
179 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
180 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
181 * Divide the time "tm" by "count" and store in "tm2". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
182 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
183 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
184 profile_divide(proftime_T *tm, int count, proftime_T *tm2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
185 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
186 if (count == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
187 profile_zero(tm2); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
188 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
189 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
190 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
191 tm2->QuadPart = tm->QuadPart / count; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
192 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
193 double fsec = (tm->tv_sec * (float_T)TV_FSEC_SEC + tm->tv_fsec) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
194 / count; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
195 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
196 tm2->tv_sec = floor(fsec / (float_T)TV_FSEC_SEC); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
197 tm2->tv_fsec = vim_round(fsec - (tm2->tv_sec * (float_T)TV_FSEC_SEC)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
198 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
199 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
200 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
201 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
202 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
203 # if defined(FEAT_PROFILE) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
204 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
205 * Functions for profiling. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
206 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
207 static proftime_T prof_wait_time; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
208 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
209 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
210 * Add the time "tm2" to "tm". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
211 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
212 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
213 profile_add(proftime_T *tm, proftime_T *tm2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
214 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
215 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
216 tm->QuadPart += tm2->QuadPart; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
217 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
218 tm->tv_fsec += tm2->tv_fsec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
219 tm->tv_sec += tm2->tv_sec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
220 if (tm->tv_fsec >= TV_FSEC_SEC) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
221 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
222 tm->tv_fsec -= TV_FSEC_SEC; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
223 ++tm->tv_sec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
224 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
225 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
226 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
227 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
228 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
229 * Add the "self" time from the total time and the children's time. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
230 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
231 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
232 profile_self(proftime_T *self, proftime_T *total, proftime_T *children) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
233 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
234 // Check that the result won't be negative. Can happen with recursive |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
235 // calls. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
236 #ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
237 if (total->QuadPart <= children->QuadPart) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
238 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
239 #else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
240 if (total->tv_sec < children->tv_sec |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
241 || (total->tv_sec == children->tv_sec |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
242 && total->tv_fsec <= children->tv_fsec)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
243 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
244 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
245 profile_add(self, total); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
246 profile_sub(self, children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
247 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
248 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
249 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
250 * Get the current waittime. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
251 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
252 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
253 profile_get_wait(proftime_T *tm) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
254 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
255 *tm = prof_wait_time; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
256 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
257 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
258 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
259 * Subtract the passed waittime since "tm" from "tma". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
260 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
261 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
262 profile_sub_wait(proftime_T *tm, proftime_T *tma) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
263 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
264 proftime_T tm3 = prof_wait_time; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
265 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
266 profile_sub(&tm3, tm); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
267 profile_sub(tma, &tm3); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
268 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
269 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
270 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
271 * Return TRUE if "tm1" and "tm2" are equal. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
272 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
273 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
274 profile_equal(proftime_T *tm1, proftime_T *tm2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
275 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
276 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
277 return (tm1->QuadPart == tm2->QuadPart); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
278 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
279 return (tm1->tv_fsec == tm2->tv_fsec && tm1->tv_sec == tm2->tv_sec); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
280 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
281 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
282 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
283 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
284 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
285 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
286 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
287 profile_cmp(const proftime_T *tm1, const proftime_T *tm2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
288 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
289 # ifdef MSWIN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
290 return (int)(tm2->QuadPart - tm1->QuadPart); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
291 # else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
292 if (tm1->tv_sec == tm2->tv_sec) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
293 return tm2->tv_fsec - tm1->tv_fsec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
294 return tm2->tv_sec - tm1->tv_sec; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
295 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
296 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
297 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
298 static char_u *profile_fname = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
299 static proftime_T pause_time; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
300 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
301 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
302 * Reset all profiling information. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
303 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
304 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
305 profile_reset(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
306 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
307 int id; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
308 int todo; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
309 hashtab_T *functbl; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
310 hashitem_T *hi; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
311 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
312 // Reset sourced files. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
313 for (id = 1; id <= script_items.ga_len; id++) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
314 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
315 scriptitem_T *si = SCRIPT_ITEM(id); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
316 if (si->sn_prof_on) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
317 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
318 si->sn_prof_on = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
319 si->sn_pr_force = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
320 profile_zero(&si->sn_pr_child); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
321 si->sn_pr_nest = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
322 si->sn_pr_count = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
323 profile_zero(&si->sn_pr_total); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
324 profile_zero(&si->sn_pr_self); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
325 profile_zero(&si->sn_pr_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
326 profile_zero(&si->sn_pr_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
327 ga_clear(&si->sn_prl_ga); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
328 profile_zero(&si->sn_prl_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
329 profile_zero(&si->sn_prl_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
330 profile_zero(&si->sn_prl_wait); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
331 si->sn_prl_idx = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
332 si->sn_prl_execed = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
333 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
334 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
335 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
336 // Reset functions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
337 functbl = func_tbl_get(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
338 todo = (int)functbl->ht_used; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
339 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
340 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
341 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
342 ufunc_T *fp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
343 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
344 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
345 if (HASHITEM_EMPTY(hi)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
346 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
347 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
348 todo--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
349 fp = HI2UF(hi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
350 if (fp->uf_prof_initialized) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
351 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
352 fp->uf_profiling = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
353 fp->uf_prof_initialized = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
354 fp->uf_tm_count = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
355 profile_zero(&fp->uf_tm_total); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
356 profile_zero(&fp->uf_tm_self); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
357 profile_zero(&fp->uf_tm_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
358 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
359 for (i = 0; i < fp->uf_lines.ga_len; i++) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
360 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
361 fp->uf_tml_count[i] = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
362 profile_zero(&fp->uf_tml_total[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
363 profile_zero(&fp->uf_tml_self[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
364 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
365 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
366 profile_zero(&fp->uf_tml_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
367 profile_zero(&fp->uf_tml_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
368 profile_zero(&fp->uf_tml_wait); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
369 fp->uf_tml_idx = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
370 fp->uf_tml_execed = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
371 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
372 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
373 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
374 VIM_CLEAR(profile_fname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
375 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
376 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
377 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
378 * ":profile cmd args" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
379 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
380 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
381 ex_profile(exarg_T *eap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
382 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
383 char_u *e; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
384 int len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
385 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
386 e = skiptowhite(eap->arg); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
387 len = (int)(e - eap->arg); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
388 e = skipwhite(e); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
389 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
390 if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
391 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
392 VIM_CLEAR(profile_fname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
393 profile_fname = expand_env_save_opt(e, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
394 do_profiling = PROF_YES; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
395 profile_zero(&prof_wait_time); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
396 set_vim_var_nr(VV_PROFILING, 1L); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
397 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
398 else if (do_profiling == PROF_NONE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
399 emsg(_(e_first_use_profile_start_fname)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
400 else if (STRCMP(eap->arg, "stop") == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
401 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
402 profile_dump(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
403 do_profiling = PROF_NONE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
404 set_vim_var_nr(VV_PROFILING, 0L); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
405 profile_reset(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
406 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
407 else if (STRCMP(eap->arg, "pause") == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
408 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
409 if (do_profiling == PROF_YES) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
410 profile_start(&pause_time); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
411 do_profiling = PROF_PAUSED; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
412 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
413 else if (STRCMP(eap->arg, "continue") == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
414 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
415 if (do_profiling == PROF_PAUSED) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
416 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
417 profile_end(&pause_time); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
418 profile_add(&prof_wait_time, &pause_time); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
419 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
420 do_profiling = PROF_YES; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
421 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
422 else if (STRCMP(eap->arg, "dump") == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
423 profile_dump(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
424 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
425 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
426 // The rest is similar to ":breakadd". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
427 ex_breakadd(eap); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
428 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
429 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
430 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
431 // Command line expansion for :profile. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
432 static enum |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
433 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
434 PEXP_SUBCMD, // expand :profile sub-commands |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
435 PEXP_FUNC // expand :profile func {funcname} |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
436 } pexpand_what; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
437 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
438 static char *pexpand_cmds[] = { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
439 "start", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
440 "stop", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
441 "pause", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
442 "continue", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
443 "func", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
444 "file", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
445 "dump", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
446 NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
447 }; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
448 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
449 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
450 * Function given to ExpandGeneric() to obtain the profile command |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
451 * specific expansion. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
452 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
453 char_u * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
454 get_profile_name(expand_T *xp UNUSED, int idx) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
455 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
456 switch (pexpand_what) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
457 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
458 case PEXP_SUBCMD: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
459 return (char_u *)pexpand_cmds[idx]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
460 default: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
461 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
462 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
463 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
464 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
465 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
466 * Handle command line completion for :profile command. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
467 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
468 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
469 set_context_in_profile_cmd(expand_T *xp, char_u *arg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
470 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
471 char_u *end_subcmd; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
472 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
473 // Default: expand subcommands. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
474 xp->xp_context = EXPAND_PROFILE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
475 pexpand_what = PEXP_SUBCMD; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
476 xp->xp_pattern = arg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
477 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
478 end_subcmd = skiptowhite(arg); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
479 if (*end_subcmd == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
480 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
481 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
482 if ((end_subcmd - arg == 5 && STRNCMP(arg, "start", 5) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
483 || (end_subcmd - arg == 4 && STRNCMP(arg, "file", 4) == 0)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
484 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
485 xp->xp_context = EXPAND_FILES; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
486 xp->xp_pattern = skipwhite(end_subcmd); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
487 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
488 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
489 else if (end_subcmd - arg == 4 && STRNCMP(arg, "func", 4) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
490 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
491 xp->xp_context = EXPAND_USER_FUNC; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
492 xp->xp_pattern = skipwhite(end_subcmd); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
493 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
494 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
495 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
496 xp->xp_context = EXPAND_NOTHING; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
497 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
498 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
499 static proftime_T inchar_time; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
500 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
501 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
502 * Called when starting to wait for the user to type a character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
503 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
504 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
505 prof_inchar_enter(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
506 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
507 profile_start(&inchar_time); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
508 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
509 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
510 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
511 * Called when finished waiting for the user to type a character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
512 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
513 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
514 prof_inchar_exit(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
515 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
516 profile_end(&inchar_time); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
517 profile_add(&prof_wait_time, &inchar_time); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
518 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
519 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
520 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
521 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
522 * Return TRUE when a function defined in the current script should be |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
523 * profiled. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
524 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
525 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
526 prof_def_func(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
527 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
528 if (current_sctx.sc_sid > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
529 return SCRIPT_ITEM(current_sctx.sc_sid)->sn_pr_force; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
530 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
531 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
532 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
533 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
534 * Print the count and times for one function or function line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
535 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
536 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
537 prof_func_line( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
538 FILE *fd, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
539 int count, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
540 proftime_T *total, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
541 proftime_T *self, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
542 int prefer_self) // when equal print only self time |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
543 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
544 if (count > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
545 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
546 fprintf(fd, "%5d ", count); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
547 if (prefer_self && profile_equal(total, self)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
548 fprintf(fd, PROF_TIME_BLANK); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
549 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
550 fprintf(fd, "%s ", profile_msg(total)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
551 if (!prefer_self && profile_equal(total, self)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
552 fprintf(fd, PROF_TIME_BLANK); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
553 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
554 fprintf(fd, "%s ", profile_msg(self)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
555 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
556 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
557 fprintf(fd, " %s%s", PROF_TIME_BLANK, PROF_TIME_BLANK); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
558 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
559 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
560 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
561 prof_sort_list( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
562 FILE *fd, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
563 ufunc_T **sorttab, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
564 int st_len, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
565 char *title, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
566 int prefer_self) // when equal print only self time |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
567 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
568 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
569 ufunc_T *fp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
570 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
571 fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
572 fprintf(fd, "%s function\n", PROF_TOTALS_HEADER); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
573 for (i = 0; i < 20 && i < st_len; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
574 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
575 fp = sorttab[i]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
576 prof_func_line(fd, fp->uf_tm_count, &fp->uf_tm_total, &fp->uf_tm_self, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
577 prefer_self); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
578 if (fp->uf_name[0] == K_SPECIAL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
579 fprintf(fd, " <SNR>%s()\n", fp->uf_name + 3); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
580 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
581 fprintf(fd, " %s()\n", fp->uf_name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
582 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
583 fprintf(fd, "\n"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
584 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
585 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
586 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
587 * Compare function for total time sorting. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
588 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
589 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
590 prof_total_cmp(const void *s1, const void *s2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
591 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
592 ufunc_T *p1, *p2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
593 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
594 p1 = *(ufunc_T **)s1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
595 p2 = *(ufunc_T **)s2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
596 return profile_cmp(&p1->uf_tm_total, &p2->uf_tm_total); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
597 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
598 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
599 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
600 * Compare function for self time sorting. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
601 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
602 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
603 prof_self_cmp(const void *s1, const void *s2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
604 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
605 ufunc_T *p1, *p2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
606 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
607 p1 = *(ufunc_T **)s1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
608 p2 = *(ufunc_T **)s2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
609 return profile_cmp(&p1->uf_tm_self, &p2->uf_tm_self); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
610 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
611 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
612 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
613 * Start profiling function "fp". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
614 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
615 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
616 func_do_profile(ufunc_T *fp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
617 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
618 int len = fp->uf_lines.ga_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
619 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
620 if (!fp->uf_prof_initialized) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
621 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
622 if (len == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
623 len = 1; // avoid getting error for allocating zero bytes |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
624 fp->uf_tm_count = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
625 profile_zero(&fp->uf_tm_self); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
626 profile_zero(&fp->uf_tm_total); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
627 if (fp->uf_tml_count == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
628 fp->uf_tml_count = ALLOC_CLEAR_MULT(int, len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
629 if (fp->uf_tml_total == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
630 fp->uf_tml_total = ALLOC_CLEAR_MULT(proftime_T, len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
631 if (fp->uf_tml_self == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
632 fp->uf_tml_self = ALLOC_CLEAR_MULT(proftime_T, len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
633 fp->uf_tml_idx = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
634 if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
635 || fp->uf_tml_self == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
636 return; // out of memory |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
637 fp->uf_prof_initialized = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
638 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
639 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
640 fp->uf_profiling = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
641 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
642 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
643 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
644 * Save time when starting to invoke another script or function. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
645 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
646 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
647 script_prof_save( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
648 proftime_T *tm) // place to store wait time |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
649 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
650 scriptitem_T *si; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
651 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
652 if (SCRIPT_ID_VALID(current_sctx.sc_sid)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
653 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
654 si = SCRIPT_ITEM(current_sctx.sc_sid); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
655 if (si->sn_prof_on && si->sn_pr_nest++ == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
656 profile_start(&si->sn_pr_child); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
657 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
658 profile_get_wait(tm); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
659 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
660 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
661 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
662 * When calling a function: may initialize for profiling. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
663 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
664 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
665 profile_may_start_func(profinfo_T *info, ufunc_T *fp, ufunc_T *caller) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
666 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
667 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
668 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
669 info->pi_started_profiling = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
670 func_do_profile(fp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
671 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
672 if (fp->uf_profiling || (caller != NULL && caller->uf_profiling)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
673 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
674 ++fp->uf_tm_count; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
675 profile_start(&info->pi_call_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
676 profile_zero(&fp->uf_tm_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
677 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
678 script_prof_save(&info->pi_wait_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
679 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
680 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
681 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
682 * After calling a function: may handle profiling. profile_may_start_func() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
683 * must have been called previously. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
684 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
685 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
686 profile_may_end_func(profinfo_T *info, ufunc_T *fp, ufunc_T *caller) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
687 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
688 profile_end(&info->pi_call_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
689 profile_sub_wait(&info->pi_wait_start, &info->pi_call_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
690 profile_add(&fp->uf_tm_total, &info->pi_call_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
691 profile_self(&fp->uf_tm_self, &info->pi_call_start, &fp->uf_tm_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
692 if (caller != NULL && caller->uf_profiling) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
693 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
694 profile_add(&caller->uf_tm_children, &info->pi_call_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
695 profile_add(&caller->uf_tml_children, &info->pi_call_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
696 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
697 if (info->pi_started_profiling) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
698 // make a ":profdel func" stop profiling the function |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
699 fp->uf_profiling = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
700 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
701 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
702 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
703 * Prepare profiling for entering a child or something else that is not |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
704 * counted for the script/function itself. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
705 * Should always be called in pair with prof_child_exit(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
706 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
707 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
708 prof_child_enter( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
709 proftime_T *tm) // place to store waittime |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
710 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
711 funccall_T *fc = get_current_funccal(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
712 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
713 if (fc != NULL && fc->fc_func->uf_profiling) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
714 profile_start(&fc->fc_prof_child); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
715 script_prof_save(tm); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
716 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
717 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
718 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
719 * Take care of time spent in a child. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
720 * Should always be called after prof_child_enter(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
721 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
722 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
723 prof_child_exit( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
724 proftime_T *tm) // where waittime was stored |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
725 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
726 funccall_T *fc = get_current_funccal(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
727 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
728 if (fc != NULL && fc->fc_func->uf_profiling) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
729 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
730 profile_end(&fc->fc_prof_child); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
731 profile_sub_wait(tm, &fc->fc_prof_child); // don't count waiting time |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
732 profile_add(&fc->fc_func->uf_tm_children, &fc->fc_prof_child); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
733 profile_add(&fc->fc_func->uf_tml_children, &fc->fc_prof_child); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
734 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
735 script_prof_restore(tm); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
736 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
737 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
738 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
739 * Called when starting to read a function line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
740 * "sourcing_lnum" must be correct! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
741 * When skipping lines it may not actually be executed, but we won't find out |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
742 * until later and we need to store the time now. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
743 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
744 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
745 func_line_start(void *cookie, long lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
746 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
747 funccall_T *fcp = (funccall_T *)cookie; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
748 ufunc_T *fp = fcp->fc_func; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
749 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
750 if (fp->uf_profiling && lnum >= 1 && lnum <= fp->uf_lines.ga_len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
751 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
752 fp->uf_tml_idx = lnum - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
753 // Skip continuation lines. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
754 while (fp->uf_tml_idx > 0 && FUNCLINE(fp, fp->uf_tml_idx) == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
755 --fp->uf_tml_idx; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
756 fp->uf_tml_execed = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
757 profile_start(&fp->uf_tml_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
758 profile_zero(&fp->uf_tml_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
759 profile_get_wait(&fp->uf_tml_wait); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
760 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
761 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
762 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
763 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
764 * Called when actually executing a function line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
765 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
766 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
767 func_line_exec(void *cookie) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
768 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
769 funccall_T *fcp = (funccall_T *)cookie; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
770 ufunc_T *fp = fcp->fc_func; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
771 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
772 if (fp->uf_profiling && fp->uf_tml_idx >= 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
773 fp->uf_tml_execed = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
774 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
775 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
776 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
777 * Called when done with a function line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
778 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
779 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
780 func_line_end(void *cookie) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
781 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
782 funccall_T *fcp = (funccall_T *)cookie; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
783 ufunc_T *fp = fcp->fc_func; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
784 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
785 if (fp->uf_profiling && fp->uf_tml_idx >= 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
786 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
787 if (fp->uf_tml_execed) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
788 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
789 ++fp->uf_tml_count[fp->uf_tml_idx]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
790 profile_end(&fp->uf_tml_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
791 profile_sub_wait(&fp->uf_tml_wait, &fp->uf_tml_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
792 profile_add(&fp->uf_tml_total[fp->uf_tml_idx], &fp->uf_tml_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
793 profile_self(&fp->uf_tml_self[fp->uf_tml_idx], &fp->uf_tml_start, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
794 &fp->uf_tml_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
795 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
796 fp->uf_tml_idx = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
797 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
798 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
799 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
800 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
801 * Dump the profiling results for all functions in file "fd". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
802 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
803 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
804 func_dump_profile(FILE *fd) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
805 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
806 hashtab_T *functbl; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
807 hashitem_T *hi; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
808 int todo; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
809 ufunc_T *fp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
810 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
811 ufunc_T **sorttab; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
812 int st_len = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
813 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
814 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
815 functbl = func_tbl_get(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
816 todo = (int)functbl->ht_used; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
817 if (todo == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
818 return; // nothing to dump |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
819 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
820 sorttab = ALLOC_MULT(ufunc_T *, todo); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
821 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
822 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
823 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
824 if (!HASHITEM_EMPTY(hi)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
825 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
826 --todo; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
827 fp = HI2UF(hi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
828 if (fp->uf_prof_initialized) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
829 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
830 if (sorttab != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
831 sorttab[st_len++] = fp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
832 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
833 if (fp->uf_name[0] == K_SPECIAL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
834 fprintf(fd, "FUNCTION <SNR>%s()\n", fp->uf_name + 3); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
835 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
836 fprintf(fd, "FUNCTION %s()\n", fp->uf_name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
837 if (fp->uf_script_ctx.sc_sid > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
838 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
839 p = home_replace_save(NULL, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
840 get_scriptname(fp->uf_script_ctx.sc_sid)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
841 if (p != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
842 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
843 fprintf(fd, " Defined: %s:%ld\n", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
844 p, (long)fp->uf_script_ctx.sc_lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
845 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
846 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
847 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
848 if (fp->uf_tm_count == 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
849 fprintf(fd, "Called 1 time\n"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
850 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
851 fprintf(fd, "Called %d times\n", fp->uf_tm_count); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
852 fprintf(fd, "Total time: %s\n", profile_msg(&fp->uf_tm_total)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
853 fprintf(fd, " Self time: %s\n", profile_msg(&fp->uf_tm_self)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
854 fprintf(fd, "\n"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
855 fprintf(fd, "%s\n", PROF_TOTALS_HEADER); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
856 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
857 for (i = 0; i < fp->uf_lines.ga_len; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
858 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
859 if (FUNCLINE(fp, i) == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
860 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
861 prof_func_line(fd, fp->uf_tml_count[i], |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
862 &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
863 fprintf(fd, "%s\n", FUNCLINE(fp, i)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
864 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
865 fprintf(fd, "\n"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
866 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
867 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
868 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
869 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
870 if (sorttab != NULL && st_len > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
871 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
872 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
873 prof_total_cmp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
874 prof_sort_list(fd, sorttab, st_len, "TOTAL", FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
875 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
876 prof_self_cmp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
877 prof_sort_list(fd, sorttab, st_len, "SELF", TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
878 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
879 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
880 vim_free(sorttab); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
881 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
882 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
883 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
884 * Start profiling script "fp". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
885 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
886 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
887 script_do_profile(scriptitem_T *si) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
888 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
889 si->sn_pr_count = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
890 profile_zero(&si->sn_pr_total); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
891 profile_zero(&si->sn_pr_self); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
892 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
893 ga_init2(&si->sn_prl_ga, sizeof(sn_prl_T), 100); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
894 si->sn_prl_idx = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
895 si->sn_prof_on = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
896 si->sn_pr_nest = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
897 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
898 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
899 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
900 * Count time spent in children after invoking another script or function. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
901 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
902 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
903 script_prof_restore(proftime_T *tm) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
904 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
905 scriptitem_T *si; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
906 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
907 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
908 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
909 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
910 si = SCRIPT_ITEM(current_sctx.sc_sid); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
911 if (si->sn_prof_on && --si->sn_pr_nest == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
912 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
913 profile_end(&si->sn_pr_child); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
914 profile_sub_wait(tm, &si->sn_pr_child); // don't count wait time |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
915 profile_add(&si->sn_pr_children, &si->sn_pr_child); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
916 profile_add(&si->sn_prl_children, &si->sn_pr_child); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
917 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
918 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
919 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
920 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
921 * Dump the profiling results for all scripts in file "fd". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
922 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
923 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
924 script_dump_profile(FILE *fd) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
925 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
926 int id; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
927 scriptitem_T *si; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
928 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
929 FILE *sfd; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
930 sn_prl_T *pp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
931 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
932 for (id = 1; id <= script_items.ga_len; ++id) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
933 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
934 si = SCRIPT_ITEM(id); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
935 if (si->sn_prof_on) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
936 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
937 fprintf(fd, "SCRIPT %s\n", si->sn_name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
938 if (si->sn_pr_count == 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
939 fprintf(fd, "Sourced 1 time\n"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
940 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
941 fprintf(fd, "Sourced %d times\n", si->sn_pr_count); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
942 fprintf(fd, "Total time: %s\n", profile_msg(&si->sn_pr_total)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
943 fprintf(fd, " Self time: %s\n", profile_msg(&si->sn_pr_self)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
944 fprintf(fd, "\n"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
945 fprintf(fd, "%s\n", PROF_TOTALS_HEADER); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
946 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
947 sfd = mch_fopen((char *)si->sn_name, "r"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
948 if (sfd == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
949 fprintf(fd, "Cannot open file!\n"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
950 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
951 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
952 // Keep going till the end of file, so that trailing |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
953 // continuation lines are listed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
954 for (i = 0; ; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
955 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
956 if (vim_fgets(IObuff, IOSIZE, sfd)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
957 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
958 // When a line has been truncated, append NL, taking care |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
959 // of multi-byte characters . |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
960 if (IObuff[IOSIZE - 2] != NUL && IObuff[IOSIZE - 2] != NL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
961 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
962 int n = IOSIZE - 2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
963 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
964 if (enc_utf8) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
965 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
966 // Move to the first byte of this char. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
967 // utf_head_off() doesn't work, because it checks |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
968 // for a truncated character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
969 while (n > 0 && (IObuff[n] & 0xc0) == 0x80) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
970 --n; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
971 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
972 else if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
973 n -= mb_head_off(IObuff, IObuff + n); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
974 IObuff[n] = NL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
975 IObuff[n + 1] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
976 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
977 if (i < si->sn_prl_ga.ga_len |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
978 && (pp = &PRL_ITEM(si, i))->snp_count > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
979 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
980 fprintf(fd, "%5d ", pp->snp_count); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
981 if (profile_equal(&pp->sn_prl_total, &pp->sn_prl_self)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
982 fprintf(fd, " "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
983 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
984 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
985 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_self)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
986 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
987 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
988 fprintf(fd, " "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
989 fprintf(fd, "%s", IObuff); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
990 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
991 fclose(sfd); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
992 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
993 fprintf(fd, "\n"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
994 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
995 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
996 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
997 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
998 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
999 * Dump the profiling info. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1000 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1001 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1002 profile_dump(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1003 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1004 FILE *fd; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1005 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1006 if (profile_fname == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1007 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1008 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1009 fd = mch_fopen((char *)profile_fname, "w"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1010 if (fd == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1011 semsg(_(e_cant_open_file_str), profile_fname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1012 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1013 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1014 script_dump_profile(fd); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1015 func_dump_profile(fd); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1016 fclose(fd); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1017 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1018 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1019 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1020 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1021 * Called when starting to read a script line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1022 * "sourcing_lnum" must be correct! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1023 * When skipping lines it may not actually be executed, but we won't find out |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1024 * until later and we need to store the time now. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1025 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1026 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1027 script_line_start(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1028 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1029 scriptitem_T *si; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1030 sn_prl_T *pp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1031 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1032 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1033 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1034 si = SCRIPT_ITEM(current_sctx.sc_sid); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1035 if (si->sn_prof_on && SOURCING_LNUM >= 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1036 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1037 // Grow the array before starting the timer, so that the time spent |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1038 // here isn't counted. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1039 (void)ga_grow(&si->sn_prl_ga, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1040 (int)(SOURCING_LNUM - si->sn_prl_ga.ga_len)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1041 si->sn_prl_idx = SOURCING_LNUM - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1042 while (si->sn_prl_ga.ga_len <= si->sn_prl_idx |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1043 && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1044 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1045 // Zero counters for a line that was not used before. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1046 pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1047 pp->snp_count = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1048 profile_zero(&pp->sn_prl_total); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1049 profile_zero(&pp->sn_prl_self); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1050 ++si->sn_prl_ga.ga_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1051 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1052 si->sn_prl_execed = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1053 profile_start(&si->sn_prl_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1054 profile_zero(&si->sn_prl_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1055 profile_get_wait(&si->sn_prl_wait); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1056 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1057 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1058 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1059 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1060 * Called when actually executing a function line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1061 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1062 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1063 script_line_exec(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1064 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1065 scriptitem_T *si; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1066 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1067 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1068 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1069 si = SCRIPT_ITEM(current_sctx.sc_sid); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1070 if (si->sn_prof_on && si->sn_prl_idx >= 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1071 si->sn_prl_execed = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1072 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1073 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1074 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1075 * Called when done with a script line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1076 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1077 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1078 script_line_end(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1079 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1080 scriptitem_T *si; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1081 sn_prl_T *pp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1082 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1083 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1084 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1085 si = SCRIPT_ITEM(current_sctx.sc_sid); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1086 if (si->sn_prof_on && si->sn_prl_idx >= 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1087 && si->sn_prl_idx < si->sn_prl_ga.ga_len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1088 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1089 if (si->sn_prl_execed) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1090 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1091 pp = &PRL_ITEM(si, si->sn_prl_idx); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1092 ++pp->snp_count; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1093 profile_end(&si->sn_prl_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1094 profile_sub_wait(&si->sn_prl_wait, &si->sn_prl_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1095 profile_add(&pp->sn_prl_total, &si->sn_prl_start); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1096 profile_self(&pp->sn_prl_self, &si->sn_prl_start, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1097 &si->sn_prl_children); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1098 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1099 si->sn_prl_idx = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1100 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1101 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1102 # endif // FEAT_PROFILE |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1103 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32471
diff
changeset
|
1104 #endif |