blob: e101067ce8ab438008a575e0c2e791374deef2d2 [file] [log] [blame]
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * profiler.c: vim script profiler
12 */
13
14#include "vim.h"
15
16#if defined(FEAT_EVAL) || defined(PROTO)
17# if defined(FEAT_PROFILE) || defined(FEAT_RELTIME) || defined(PROTO)
18/*
19 * Store the current time in "tm".
20 */
21 void
22profile_start(proftime_T *tm)
23{
24# ifdef MSWIN
25 QueryPerformanceCounter(tm);
26# else
Ernie Rael076de792023-03-16 21:43:15 +000027 PROF_GET_TIME(tm);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +020028# endif
29}
30
31/*
32 * Compute the elapsed time from "tm" till now and store in "tm".
33 */
34 void
35profile_end(proftime_T *tm)
36{
37 proftime_T now;
38
39# ifdef MSWIN
40 QueryPerformanceCounter(&now);
41 tm->QuadPart = now.QuadPart - tm->QuadPart;
42# else
Ernie Rael076de792023-03-16 21:43:15 +000043 PROF_GET_TIME(&now);
44 tm->tv_fsec = now.tv_fsec - tm->tv_fsec;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +020045 tm->tv_sec = now.tv_sec - tm->tv_sec;
Ernie Rael076de792023-03-16 21:43:15 +000046 if (tm->tv_fsec < 0)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +020047 {
Ernie Rael076de792023-03-16 21:43:15 +000048 tm->tv_fsec += TV_FSEC_SEC;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +020049 --tm->tv_sec;
50 }
51# endif
52}
53
54/*
55 * Subtract the time "tm2" from "tm".
56 */
57 void
58profile_sub(proftime_T *tm, proftime_T *tm2)
59{
60# ifdef MSWIN
61 tm->QuadPart -= tm2->QuadPart;
62# else
Ernie Rael076de792023-03-16 21:43:15 +000063 tm->tv_fsec -= tm2->tv_fsec;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +020064 tm->tv_sec -= tm2->tv_sec;
Ernie Rael076de792023-03-16 21:43:15 +000065 if (tm->tv_fsec < 0)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +020066 {
Ernie Rael076de792023-03-16 21:43:15 +000067 tm->tv_fsec += TV_FSEC_SEC;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +020068 --tm->tv_sec;
69 }
70# endif
71}
72
73/*
74 * Return a string that represents the time in "tm".
75 * Uses a static buffer!
76 */
77 char *
78profile_msg(proftime_T *tm)
79{
80 static char buf[50];
81
82# ifdef MSWIN
83 LARGE_INTEGER fr;
84
85 QueryPerformanceFrequency(&fr);
86 sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart);
87# else
Ernie Rael076de792023-03-16 21:43:15 +000088 sprintf(buf, PROF_TIME_FORMAT, (long)tm->tv_sec, (long)tm->tv_fsec);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +020089# endif
90 return buf;
91}
92
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +020093/*
94 * Return a float that represents the time in "tm".
95 */
96 float_T
97profile_float(proftime_T *tm)
98{
Bram Moolenaar73e28dc2022-09-17 21:08:33 +010099# ifdef MSWIN
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200100 LARGE_INTEGER fr;
101
102 QueryPerformanceFrequency(&fr);
103 return (float_T)tm->QuadPart / (float_T)fr.QuadPart;
Bram Moolenaar73e28dc2022-09-17 21:08:33 +0100104# else
Ernie Rael076de792023-03-16 21:43:15 +0000105 return (float_T)tm->tv_sec + (float_T)tm->tv_fsec / (float_T)TV_FSEC_SEC;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200106# endif
Bram Moolenaar73e28dc2022-09-17 21:08:33 +0100107}
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200108
109/*
110 * Put the time "msec" past now in "tm".
111 */
112 void
113profile_setlimit(long msec, proftime_T *tm)
114{
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200115 if (msec <= 0) // no limit
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200116 profile_zero(tm);
117 else
118 {
119# ifdef MSWIN
120 LARGE_INTEGER fr;
121
122 QueryPerformanceCounter(tm);
123 QueryPerformanceFrequency(&fr);
124 tm->QuadPart += (LONGLONG)((double)msec / 1000.0 * (double)fr.QuadPart);
125# else
Isao Satod13c2542023-05-19 13:20:34 +0100126 varnumber_T fsec; // this should be 64 bit if possible
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200127
Ernie Rael076de792023-03-16 21:43:15 +0000128 PROF_GET_TIME(tm);
Isao Satod13c2542023-05-19 13:20:34 +0100129 fsec = (varnumber_T)tm->tv_fsec
130 + (varnumber_T)msec * (varnumber_T)(TV_FSEC_SEC / 1000);
Ernie Rael076de792023-03-16 21:43:15 +0000131 tm->tv_fsec = fsec % (long)TV_FSEC_SEC;
132 tm->tv_sec += fsec / (long)TV_FSEC_SEC;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200133# endif
134 }
135}
136
137/*
138 * Return TRUE if the current time is past "tm".
139 */
140 int
141profile_passed_limit(proftime_T *tm)
142{
143 proftime_T now;
144
145# ifdef MSWIN
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200146 if (tm->QuadPart == 0) // timer was not set
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200147 return FALSE;
148 QueryPerformanceCounter(&now);
149 return (now.QuadPart > tm->QuadPart);
150# else
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200151 if (tm->tv_sec == 0) // timer was not set
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200152 return FALSE;
Ernie Rael076de792023-03-16 21:43:15 +0000153 PROF_GET_TIME(&now);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200154 return (now.tv_sec > tm->tv_sec
Ernie Rael076de792023-03-16 21:43:15 +0000155 || (now.tv_sec == tm->tv_sec && now.tv_fsec > tm->tv_fsec));
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200156# endif
157}
158
159/*
160 * Set the time in "tm" to zero.
161 */
162 void
163profile_zero(proftime_T *tm)
164{
165# ifdef MSWIN
166 tm->QuadPart = 0;
167# else
Ernie Rael076de792023-03-16 21:43:15 +0000168 tm->tv_fsec = 0;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200169 tm->tv_sec = 0;
170# endif
171}
172
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200173# endif // FEAT_PROFILE || FEAT_RELTIME
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200174
Bram Moolenaar73e28dc2022-09-17 21:08:33 +0100175#if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_PROFILE)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200176# if defined(HAVE_MATH_H)
177# include <math.h>
178# endif
179
180/*
181 * Divide the time "tm" by "count" and store in "tm2".
182 */
183 void
184profile_divide(proftime_T *tm, int count, proftime_T *tm2)
185{
186 if (count == 0)
187 profile_zero(tm2);
188 else
189 {
190# ifdef MSWIN
191 tm2->QuadPart = tm->QuadPart / count;
192# else
Ernie Rael076de792023-03-16 21:43:15 +0000193 double fsec = (tm->tv_sec * (float_T)TV_FSEC_SEC + tm->tv_fsec)
194 / count;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200195
Ernie Rael076de792023-03-16 21:43:15 +0000196 tm2->tv_sec = floor(fsec / (float_T)TV_FSEC_SEC);
197 tm2->tv_fsec = vim_round(fsec - (tm2->tv_sec * (float_T)TV_FSEC_SEC));
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200198# endif
199 }
200}
201#endif
202
203# if defined(FEAT_PROFILE) || defined(PROTO)
204/*
205 * Functions for profiling.
206 */
207static proftime_T prof_wait_time;
208
209/*
210 * Add the time "tm2" to "tm".
211 */
212 void
213profile_add(proftime_T *tm, proftime_T *tm2)
214{
215# ifdef MSWIN
216 tm->QuadPart += tm2->QuadPart;
217# else
Ernie Rael076de792023-03-16 21:43:15 +0000218 tm->tv_fsec += tm2->tv_fsec;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200219 tm->tv_sec += tm2->tv_sec;
Ernie Rael076de792023-03-16 21:43:15 +0000220 if (tm->tv_fsec >= TV_FSEC_SEC)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200221 {
Ernie Rael076de792023-03-16 21:43:15 +0000222 tm->tv_fsec -= TV_FSEC_SEC;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200223 ++tm->tv_sec;
224 }
225# endif
226}
227
228/*
229 * Add the "self" time from the total time and the children's time.
230 */
231 void
232profile_self(proftime_T *self, proftime_T *total, proftime_T *children)
233{
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200234 // Check that the result won't be negative. Can happen with recursive
235 // calls.
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200236#ifdef MSWIN
237 if (total->QuadPart <= children->QuadPart)
238 return;
239#else
240 if (total->tv_sec < children->tv_sec
241 || (total->tv_sec == children->tv_sec
Ernie Rael076de792023-03-16 21:43:15 +0000242 && total->tv_fsec <= children->tv_fsec))
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200243 return;
244#endif
245 profile_add(self, total);
246 profile_sub(self, children);
247}
248
249/*
250 * Get the current waittime.
251 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +0200252 static void
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200253profile_get_wait(proftime_T *tm)
254{
255 *tm = prof_wait_time;
256}
257
258/*
259 * Subtract the passed waittime since "tm" from "tma".
260 */
261 void
262profile_sub_wait(proftime_T *tm, proftime_T *tma)
263{
264 proftime_T tm3 = prof_wait_time;
265
266 profile_sub(&tm3, tm);
267 profile_sub(tma, &tm3);
268}
269
270/*
271 * Return TRUE if "tm1" and "tm2" are equal.
272 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +0200273 static int
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200274profile_equal(proftime_T *tm1, proftime_T *tm2)
275{
276# ifdef MSWIN
277 return (tm1->QuadPart == tm2->QuadPart);
278# else
Ernie Rael076de792023-03-16 21:43:15 +0000279 return (tm1->tv_fsec == tm2->tv_fsec && tm1->tv_sec == tm2->tv_sec);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200280# endif
281}
282
283/*
284 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2"
285 */
286 int
287profile_cmp(const proftime_T *tm1, const proftime_T *tm2)
288{
289# ifdef MSWIN
290 return (int)(tm2->QuadPart - tm1->QuadPart);
291# else
292 if (tm1->tv_sec == tm2->tv_sec)
Ernie Rael076de792023-03-16 21:43:15 +0000293 return tm2->tv_fsec - tm1->tv_fsec;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200294 return tm2->tv_sec - tm1->tv_sec;
295# endif
296}
297
298static char_u *profile_fname = NULL;
299static proftime_T pause_time;
300
301/*
Yegappan Lakshmanan18ee0f62022-04-08 13:23:19 +0100302 * Reset all profiling information.
303 */
304 static void
305profile_reset(void)
306{
307 int id;
308 int todo;
309 hashtab_T *functbl;
310 hashitem_T *hi;
311
312 // Reset sourced files.
313 for (id = 1; id <= script_items.ga_len; id++)
314 {
315 scriptitem_T *si = SCRIPT_ITEM(id);
316 if (si->sn_prof_on)
317 {
318 si->sn_prof_on = FALSE;
319 si->sn_pr_force = FALSE;
320 profile_zero(&si->sn_pr_child);
321 si->sn_pr_nest = 0;
322 si->sn_pr_count = 0;
323 profile_zero(&si->sn_pr_total);
324 profile_zero(&si->sn_pr_self);
325 profile_zero(&si->sn_pr_start);
326 profile_zero(&si->sn_pr_children);
327 ga_clear(&si->sn_prl_ga);
328 profile_zero(&si->sn_prl_start);
329 profile_zero(&si->sn_prl_children);
330 profile_zero(&si->sn_prl_wait);
331 si->sn_prl_idx = -1;
332 si->sn_prl_execed = 0;
333 }
334 }
335
336 // Reset functions.
337 functbl = func_tbl_get();
338 todo = (int)functbl->ht_used;
339
Yegappan Lakshmanan14113fd2023-03-07 17:13:51 +0000340 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo)
Yegappan Lakshmanan18ee0f62022-04-08 13:23:19 +0100341 {
342 ufunc_T *fp;
343 int i;
344
345 if (HASHITEM_EMPTY(hi))
346 continue;
347
348 todo--;
349 fp = HI2UF(hi);
350 if (fp->uf_prof_initialized)
351 {
352 fp->uf_profiling = 0;
353 fp->uf_prof_initialized = FALSE;
354 fp->uf_tm_count = 0;
355 profile_zero(&fp->uf_tm_total);
356 profile_zero(&fp->uf_tm_self);
357 profile_zero(&fp->uf_tm_children);
358
359 for (i = 0; i < fp->uf_lines.ga_len; i++)
360 {
361 fp->uf_tml_count[i] = 0;
362 profile_zero(&fp->uf_tml_total[i]);
363 profile_zero(&fp->uf_tml_self[i]);
364 }
365
366 profile_zero(&fp->uf_tml_start);
367 profile_zero(&fp->uf_tml_children);
368 profile_zero(&fp->uf_tml_wait);
369 fp->uf_tml_idx = -1;
370 fp->uf_tml_execed = 0;
371 }
372 }
373
374 VIM_CLEAR(profile_fname);
375}
376
377/*
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200378 * ":profile cmd args"
379 */
380 void
381ex_profile(exarg_T *eap)
382{
383 char_u *e;
384 int len;
385
386 e = skiptowhite(eap->arg);
387 len = (int)(e - eap->arg);
388 e = skipwhite(e);
389
390 if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL)
391 {
Yegappan Lakshmanan18ee0f62022-04-08 13:23:19 +0100392 VIM_CLEAR(profile_fname);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200393 profile_fname = expand_env_save_opt(e, TRUE);
394 do_profiling = PROF_YES;
395 profile_zero(&prof_wait_time);
396 set_vim_var_nr(VV_PROFILING, 1L);
397 }
398 else if (do_profiling == PROF_NONE)
Bram Moolenaar677658a2022-01-05 16:09:06 +0000399 emsg(_(e_first_use_profile_start_fname));
Yegappan Lakshmanan18ee0f62022-04-08 13:23:19 +0100400 else if (STRCMP(eap->arg, "stop") == 0)
401 {
402 profile_dump();
403 do_profiling = PROF_NONE;
404 set_vim_var_nr(VV_PROFILING, 0L);
405 profile_reset();
406 }
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200407 else if (STRCMP(eap->arg, "pause") == 0)
408 {
409 if (do_profiling == PROF_YES)
410 profile_start(&pause_time);
411 do_profiling = PROF_PAUSED;
412 }
413 else if (STRCMP(eap->arg, "continue") == 0)
414 {
415 if (do_profiling == PROF_PAUSED)
416 {
417 profile_end(&pause_time);
418 profile_add(&prof_wait_time, &pause_time);
419 }
420 do_profiling = PROF_YES;
421 }
Yegappan Lakshmanan18ee0f62022-04-08 13:23:19 +0100422 else if (STRCMP(eap->arg, "dump") == 0)
423 profile_dump();
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200424 else
425 {
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200426 // The rest is similar to ":breakadd".
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200427 ex_breakadd(eap);
428 }
429}
430
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200431// Command line expansion for :profile.
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200432static enum
433{
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200434 PEXP_SUBCMD, // expand :profile sub-commands
435 PEXP_FUNC // expand :profile func {funcname}
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200436} pexpand_what;
437
438static char *pexpand_cmds[] = {
439 "start",
Yegappan Lakshmanan18ee0f62022-04-08 13:23:19 +0100440 "stop",
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200441 "pause",
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200442 "continue",
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200443 "func",
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200444 "file",
Yegappan Lakshmanan18ee0f62022-04-08 13:23:19 +0100445 "dump",
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200446 NULL
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200447};
448
449/*
450 * Function given to ExpandGeneric() to obtain the profile command
451 * specific expansion.
452 */
453 char_u *
454get_profile_name(expand_T *xp UNUSED, int idx)
455{
456 switch (pexpand_what)
457 {
458 case PEXP_SUBCMD:
459 return (char_u *)pexpand_cmds[idx];
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200460 default:
461 return NULL;
462 }
463}
464
465/*
466 * Handle command line completion for :profile command.
467 */
468 void
469set_context_in_profile_cmd(expand_T *xp, char_u *arg)
470{
471 char_u *end_subcmd;
472
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200473 // Default: expand subcommands.
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200474 xp->xp_context = EXPAND_PROFILE;
475 pexpand_what = PEXP_SUBCMD;
476 xp->xp_pattern = arg;
477
478 end_subcmd = skiptowhite(arg);
479 if (*end_subcmd == NUL)
480 return;
481
Yegappan Lakshmanan1fdf84e2022-03-15 10:53:09 +0000482 if ((end_subcmd - arg == 5 && STRNCMP(arg, "start", 5) == 0)
483 || (end_subcmd - arg == 4 && STRNCMP(arg, "file", 4) == 0))
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200484 {
485 xp->xp_context = EXPAND_FILES;
486 xp->xp_pattern = skipwhite(end_subcmd);
487 return;
488 }
Yegappan Lakshmanan1fdf84e2022-03-15 10:53:09 +0000489 else if (end_subcmd - arg == 4 && STRNCMP(arg, "func", 4) == 0)
490 {
491 xp->xp_context = EXPAND_USER_FUNC;
492 xp->xp_pattern = skipwhite(end_subcmd);
493 return;
494 }
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200495
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200496 xp->xp_context = EXPAND_NOTHING;
497}
498
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200499static proftime_T inchar_time;
500
501/*
502 * Called when starting to wait for the user to type a character.
503 */
504 void
505prof_inchar_enter(void)
506{
507 profile_start(&inchar_time);
508}
509
510/*
511 * Called when finished waiting for the user to type a character.
512 */
513 void
514prof_inchar_exit(void)
515{
516 profile_end(&inchar_time);
517 profile_add(&prof_wait_time, &inchar_time);
518}
519
520
521/*
522 * Return TRUE when a function defined in the current script should be
523 * profiled.
524 */
525 int
526prof_def_func(void)
527{
528 if (current_sctx.sc_sid > 0)
Bram Moolenaar21b9e972020-01-26 19:26:46 +0100529 return SCRIPT_ITEM(current_sctx.sc_sid)->sn_pr_force;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200530 return FALSE;
531}
532
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200533/*
534 * Print the count and times for one function or function line.
535 */
536 static void
537prof_func_line(
538 FILE *fd,
539 int count,
540 proftime_T *total,
541 proftime_T *self,
542 int prefer_self) // when equal print only self time
543{
544 if (count > 0)
545 {
546 fprintf(fd, "%5d ", count);
547 if (prefer_self && profile_equal(total, self))
Ernie Rael076de792023-03-16 21:43:15 +0000548 fprintf(fd, PROF_TIME_BLANK);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200549 else
550 fprintf(fd, "%s ", profile_msg(total));
551 if (!prefer_self && profile_equal(total, self))
Ernie Rael076de792023-03-16 21:43:15 +0000552 fprintf(fd, PROF_TIME_BLANK);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200553 else
554 fprintf(fd, "%s ", profile_msg(self));
555 }
556 else
Ernie Rael076de792023-03-16 21:43:15 +0000557 fprintf(fd, " %s%s", PROF_TIME_BLANK, PROF_TIME_BLANK);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200558}
559
560 static void
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200561prof_sort_list(
562 FILE *fd,
563 ufunc_T **sorttab,
564 int st_len,
565 char *title,
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200566 int prefer_self) // when equal print only self time
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200567{
568 int i;
569 ufunc_T *fp;
570
571 fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title);
Ernie Rael076de792023-03-16 21:43:15 +0000572 fprintf(fd, "%s function\n", PROF_TOTALS_HEADER);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200573 for (i = 0; i < 20 && i < st_len; ++i)
574 {
575 fp = sorttab[i];
576 prof_func_line(fd, fp->uf_tm_count, &fp->uf_tm_total, &fp->uf_tm_self,
577 prefer_self);
578 if (fp->uf_name[0] == K_SPECIAL)
579 fprintf(fd, " <SNR>%s()\n", fp->uf_name + 3);
580 else
581 fprintf(fd, " %s()\n", fp->uf_name);
582 }
583 fprintf(fd, "\n");
584}
585
586/*
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200587 * Compare function for total time sorting.
588 */
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200589 static int
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200590prof_total_cmp(const void *s1, const void *s2)
591{
592 ufunc_T *p1, *p2;
593
594 p1 = *(ufunc_T **)s1;
595 p2 = *(ufunc_T **)s2;
596 return profile_cmp(&p1->uf_tm_total, &p2->uf_tm_total);
597}
598
599/*
600 * Compare function for self time sorting.
601 */
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200602 static int
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200603prof_self_cmp(const void *s1, const void *s2)
604{
605 ufunc_T *p1, *p2;
606
607 p1 = *(ufunc_T **)s1;
608 p2 = *(ufunc_T **)s2;
609 return profile_cmp(&p1->uf_tm_self, &p2->uf_tm_self);
610}
611
612/*
613 * Start profiling function "fp".
614 */
615 void
616func_do_profile(ufunc_T *fp)
617{
618 int len = fp->uf_lines.ga_len;
619
620 if (!fp->uf_prof_initialized)
621 {
622 if (len == 0)
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200623 len = 1; // avoid getting error for allocating zero bytes
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200624 fp->uf_tm_count = 0;
625 profile_zero(&fp->uf_tm_self);
626 profile_zero(&fp->uf_tm_total);
627 if (fp->uf_tml_count == NULL)
628 fp->uf_tml_count = ALLOC_CLEAR_MULT(int, len);
629 if (fp->uf_tml_total == NULL)
630 fp->uf_tml_total = ALLOC_CLEAR_MULT(proftime_T, len);
631 if (fp->uf_tml_self == NULL)
632 fp->uf_tml_self = ALLOC_CLEAR_MULT(proftime_T, len);
633 fp->uf_tml_idx = -1;
634 if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL
635 || fp->uf_tml_self == NULL)
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200636 return; // out of memory
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200637 fp->uf_prof_initialized = TRUE;
638 }
639
640 fp->uf_profiling = TRUE;
641}
642
643/*
Yegappan Lakshmanan8ee52af2021-08-09 19:59:06 +0200644 * Save time when starting to invoke another script or function.
645 */
646 static void
647script_prof_save(
648 proftime_T *tm) // place to store wait time
649{
650 scriptitem_T *si;
651
652 if (SCRIPT_ID_VALID(current_sctx.sc_sid))
653 {
654 si = SCRIPT_ITEM(current_sctx.sc_sid);
655 if (si->sn_prof_on && si->sn_pr_nest++ == 0)
656 profile_start(&si->sn_pr_child);
657 }
658 profile_get_wait(tm);
659}
660
661/*
Bram Moolenaarb2049902021-01-24 12:53:53 +0100662 * When calling a function: may initialize for profiling.
663 */
664 void
Bram Moolenaar12d26532021-02-19 19:13:21 +0100665profile_may_start_func(profinfo_T *info, ufunc_T *fp, ufunc_T *caller)
Bram Moolenaarb2049902021-01-24 12:53:53 +0100666{
Bram Moolenaar12d26532021-02-19 19:13:21 +0100667 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
Bram Moolenaarb2049902021-01-24 12:53:53 +0100668 {
Bram Moolenaar12d26532021-02-19 19:13:21 +0100669 info->pi_started_profiling = TRUE;
670 func_do_profile(fp);
Bram Moolenaarb2049902021-01-24 12:53:53 +0100671 }
Bram Moolenaar12d26532021-02-19 19:13:21 +0100672 if (fp->uf_profiling || (caller != NULL && caller->uf_profiling))
673 {
674 ++fp->uf_tm_count;
675 profile_start(&info->pi_call_start);
676 profile_zero(&fp->uf_tm_children);
677 }
678 script_prof_save(&info->pi_wait_start);
Bram Moolenaarb2049902021-01-24 12:53:53 +0100679}
680
681/*
682 * After calling a function: may handle profiling. profile_may_start_func()
683 * must have been called previously.
684 */
685 void
Bram Moolenaar12d26532021-02-19 19:13:21 +0100686profile_may_end_func(profinfo_T *info, ufunc_T *fp, ufunc_T *caller)
Bram Moolenaarb2049902021-01-24 12:53:53 +0100687{
688 profile_end(&info->pi_call_start);
689 profile_sub_wait(&info->pi_wait_start, &info->pi_call_start);
690 profile_add(&fp->uf_tm_total, &info->pi_call_start);
691 profile_self(&fp->uf_tm_self, &info->pi_call_start, &fp->uf_tm_children);
Bram Moolenaar12d26532021-02-19 19:13:21 +0100692 if (caller != NULL && caller->uf_profiling)
Bram Moolenaarb2049902021-01-24 12:53:53 +0100693 {
Bram Moolenaar12d26532021-02-19 19:13:21 +0100694 profile_add(&caller->uf_tm_children, &info->pi_call_start);
695 profile_add(&caller->uf_tml_children, &info->pi_call_start);
Bram Moolenaarb2049902021-01-24 12:53:53 +0100696 }
697 if (info->pi_started_profiling)
698 // make a ":profdel func" stop profiling the function
699 fp->uf_profiling = FALSE;
700}
701
702/*
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200703 * Prepare profiling for entering a child or something else that is not
704 * counted for the script/function itself.
705 * Should always be called in pair with prof_child_exit().
706 */
707 void
708prof_child_enter(
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200709 proftime_T *tm) // place to store waittime
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200710{
711 funccall_T *fc = get_current_funccal();
712
Bram Moolenaarca16c602022-09-06 18:57:08 +0100713 if (fc != NULL && fc->fc_func->uf_profiling)
714 profile_start(&fc->fc_prof_child);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200715 script_prof_save(tm);
716}
717
718/*
719 * Take care of time spent in a child.
720 * Should always be called after prof_child_enter().
721 */
722 void
723prof_child_exit(
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200724 proftime_T *tm) // where waittime was stored
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200725{
726 funccall_T *fc = get_current_funccal();
727
Bram Moolenaarca16c602022-09-06 18:57:08 +0100728 if (fc != NULL && fc->fc_func->uf_profiling)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200729 {
Bram Moolenaarca16c602022-09-06 18:57:08 +0100730 profile_end(&fc->fc_prof_child);
731 profile_sub_wait(tm, &fc->fc_prof_child); // don't count waiting time
732 profile_add(&fc->fc_func->uf_tm_children, &fc->fc_prof_child);
733 profile_add(&fc->fc_func->uf_tml_children, &fc->fc_prof_child);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200734 }
735 script_prof_restore(tm);
736}
737
738/*
739 * Called when starting to read a function line.
740 * "sourcing_lnum" must be correct!
741 * When skipping lines it may not actually be executed, but we won't find out
742 * until later and we need to store the time now.
743 */
744 void
Bram Moolenaarb2049902021-01-24 12:53:53 +0100745func_line_start(void *cookie, long lnum)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200746{
747 funccall_T *fcp = (funccall_T *)cookie;
Bram Moolenaarca16c602022-09-06 18:57:08 +0100748 ufunc_T *fp = fcp->fc_func;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200749
Bram Moolenaarb2049902021-01-24 12:53:53 +0100750 if (fp->uf_profiling && lnum >= 1 && lnum <= fp->uf_lines.ga_len)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200751 {
Bram Moolenaarb2049902021-01-24 12:53:53 +0100752 fp->uf_tml_idx = lnum - 1;
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200753 // Skip continuation lines.
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200754 while (fp->uf_tml_idx > 0 && FUNCLINE(fp, fp->uf_tml_idx) == NULL)
755 --fp->uf_tml_idx;
756 fp->uf_tml_execed = FALSE;
757 profile_start(&fp->uf_tml_start);
758 profile_zero(&fp->uf_tml_children);
759 profile_get_wait(&fp->uf_tml_wait);
760 }
761}
762
763/*
764 * Called when actually executing a function line.
765 */
766 void
767func_line_exec(void *cookie)
768{
769 funccall_T *fcp = (funccall_T *)cookie;
Bram Moolenaarca16c602022-09-06 18:57:08 +0100770 ufunc_T *fp = fcp->fc_func;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200771
772 if (fp->uf_profiling && fp->uf_tml_idx >= 0)
773 fp->uf_tml_execed = TRUE;
774}
775
776/*
777 * Called when done with a function line.
778 */
779 void
780func_line_end(void *cookie)
781{
782 funccall_T *fcp = (funccall_T *)cookie;
Bram Moolenaarca16c602022-09-06 18:57:08 +0100783 ufunc_T *fp = fcp->fc_func;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200784
785 if (fp->uf_profiling && fp->uf_tml_idx >= 0)
786 {
787 if (fp->uf_tml_execed)
788 {
789 ++fp->uf_tml_count[fp->uf_tml_idx];
790 profile_end(&fp->uf_tml_start);
791 profile_sub_wait(&fp->uf_tml_wait, &fp->uf_tml_start);
792 profile_add(&fp->uf_tml_total[fp->uf_tml_idx], &fp->uf_tml_start);
793 profile_self(&fp->uf_tml_self[fp->uf_tml_idx], &fp->uf_tml_start,
794 &fp->uf_tml_children);
795 }
796 fp->uf_tml_idx = -1;
797 }
798}
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200799
800/*
801 * Dump the profiling results for all functions in file "fd".
802 */
803 static void
804func_dump_profile(FILE *fd)
805{
806 hashtab_T *functbl;
807 hashitem_T *hi;
808 int todo;
809 ufunc_T *fp;
810 int i;
811 ufunc_T **sorttab;
812 int st_len = 0;
813 char_u *p;
814
815 functbl = func_tbl_get();
816 todo = (int)functbl->ht_used;
817 if (todo == 0)
818 return; // nothing to dump
819
820 sorttab = ALLOC_MULT(ufunc_T *, todo);
821
Yegappan Lakshmanan14113fd2023-03-07 17:13:51 +0000822 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo)
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200823 {
824 if (!HASHITEM_EMPTY(hi))
825 {
826 --todo;
827 fp = HI2UF(hi);
828 if (fp->uf_prof_initialized)
829 {
830 if (sorttab != NULL)
831 sorttab[st_len++] = fp;
832
833 if (fp->uf_name[0] == K_SPECIAL)
834 fprintf(fd, "FUNCTION <SNR>%s()\n", fp->uf_name + 3);
835 else
836 fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
Bram Moolenaar16358802019-08-30 18:37:26 +0200837 if (fp->uf_script_ctx.sc_sid > 0)
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200838 {
Bram Moolenaar16358802019-08-30 18:37:26 +0200839 p = home_replace_save(NULL,
840 get_scriptname(fp->uf_script_ctx.sc_sid));
841 if (p != NULL)
842 {
Bram Moolenaar181d4f52019-09-18 22:04:56 +0200843 fprintf(fd, " Defined: %s:%ld\n",
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200844 p, (long)fp->uf_script_ctx.sc_lnum);
Bram Moolenaar16358802019-08-30 18:37:26 +0200845 vim_free(p);
846 }
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200847 }
848 if (fp->uf_tm_count == 1)
849 fprintf(fd, "Called 1 time\n");
850 else
851 fprintf(fd, "Called %d times\n", fp->uf_tm_count);
852 fprintf(fd, "Total time: %s\n", profile_msg(&fp->uf_tm_total));
853 fprintf(fd, " Self time: %s\n", profile_msg(&fp->uf_tm_self));
854 fprintf(fd, "\n");
Ernie Rael076de792023-03-16 21:43:15 +0000855 fprintf(fd, "%s\n", PROF_TOTALS_HEADER);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200856
857 for (i = 0; i < fp->uf_lines.ga_len; ++i)
858 {
859 if (FUNCLINE(fp, i) == NULL)
860 continue;
861 prof_func_line(fd, fp->uf_tml_count[i],
862 &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE);
863 fprintf(fd, "%s\n", FUNCLINE(fp, i));
864 }
865 fprintf(fd, "\n");
866 }
867 }
868 }
869
870 if (sorttab != NULL && st_len > 0)
871 {
872 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
873 prof_total_cmp);
874 prof_sort_list(fd, sorttab, st_len, "TOTAL", FALSE);
875 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
876 prof_self_cmp);
877 prof_sort_list(fd, sorttab, st_len, "SELF", TRUE);
878 }
879
880 vim_free(sorttab);
881}
882
883/*
884 * Start profiling script "fp".
885 */
886 void
887script_do_profile(scriptitem_T *si)
888{
889 si->sn_pr_count = 0;
890 profile_zero(&si->sn_pr_total);
891 profile_zero(&si->sn_pr_self);
892
893 ga_init2(&si->sn_prl_ga, sizeof(sn_prl_T), 100);
894 si->sn_prl_idx = -1;
895 si->sn_prof_on = TRUE;
896 si->sn_pr_nest = 0;
897}
898
899/*
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200900 * Count time spent in children after invoking another script or function.
901 */
902 void
903script_prof_restore(proftime_T *tm)
904{
905 scriptitem_T *si;
906
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +0000907 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
908 return;
909
910 si = SCRIPT_ITEM(current_sctx.sc_sid);
911 if (si->sn_prof_on && --si->sn_pr_nest == 0)
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200912 {
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +0000913 profile_end(&si->sn_pr_child);
914 profile_sub_wait(tm, &si->sn_pr_child); // don't count wait time
915 profile_add(&si->sn_pr_children, &si->sn_pr_child);
916 profile_add(&si->sn_prl_children, &si->sn_pr_child);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200917 }
918}
919
920/*
921 * Dump the profiling results for all scripts in file "fd".
922 */
923 static void
924script_dump_profile(FILE *fd)
925{
926 int id;
927 scriptitem_T *si;
928 int i;
929 FILE *sfd;
930 sn_prl_T *pp;
931
932 for (id = 1; id <= script_items.ga_len; ++id)
933 {
Bram Moolenaar21b9e972020-01-26 19:26:46 +0100934 si = SCRIPT_ITEM(id);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200935 if (si->sn_prof_on)
936 {
937 fprintf(fd, "SCRIPT %s\n", si->sn_name);
938 if (si->sn_pr_count == 1)
939 fprintf(fd, "Sourced 1 time\n");
940 else
941 fprintf(fd, "Sourced %d times\n", si->sn_pr_count);
942 fprintf(fd, "Total time: %s\n", profile_msg(&si->sn_pr_total));
943 fprintf(fd, " Self time: %s\n", profile_msg(&si->sn_pr_self));
944 fprintf(fd, "\n");
Ernie Rael076de792023-03-16 21:43:15 +0000945 fprintf(fd, "%s\n", PROF_TOTALS_HEADER);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200946
947 sfd = mch_fopen((char *)si->sn_name, "r");
948 if (sfd == NULL)
949 fprintf(fd, "Cannot open file!\n");
950 else
951 {
952 // Keep going till the end of file, so that trailing
953 // continuation lines are listed.
954 for (i = 0; ; ++i)
955 {
956 if (vim_fgets(IObuff, IOSIZE, sfd))
957 break;
958 // When a line has been truncated, append NL, taking care
959 // of multi-byte characters .
960 if (IObuff[IOSIZE - 2] != NUL && IObuff[IOSIZE - 2] != NL)
961 {
962 int n = IOSIZE - 2;
963
964 if (enc_utf8)
965 {
966 // Move to the first byte of this char.
967 // utf_head_off() doesn't work, because it checks
968 // for a truncated character.
969 while (n > 0 && (IObuff[n] & 0xc0) == 0x80)
970 --n;
971 }
972 else if (has_mbyte)
973 n -= mb_head_off(IObuff, IObuff + n);
974 IObuff[n] = NL;
975 IObuff[n + 1] = NUL;
976 }
977 if (i < si->sn_prl_ga.ga_len
978 && (pp = &PRL_ITEM(si, i))->snp_count > 0)
979 {
980 fprintf(fd, "%5d ", pp->snp_count);
981 if (profile_equal(&pp->sn_prl_total, &pp->sn_prl_self))
982 fprintf(fd, " ");
983 else
984 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total));
985 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_self));
986 }
987 else
988 fprintf(fd, " ");
989 fprintf(fd, "%s", IObuff);
990 }
991 fclose(sfd);
992 }
993 fprintf(fd, "\n");
994 }
995 }
996}
997
998/*
999 * Dump the profiling info.
1000 */
1001 void
1002profile_dump(void)
1003{
1004 FILE *fd;
1005
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +00001006 if (profile_fname == NULL)
1007 return;
1008
1009 fd = mch_fopen((char *)profile_fname, "w");
1010 if (fd == NULL)
1011 semsg(_(e_cant_open_file_str), profile_fname);
1012 else
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001013 {
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +00001014 script_dump_profile(fd);
1015 func_dump_profile(fd);
1016 fclose(fd);
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001017 }
1018}
1019
1020/*
1021 * Called when starting to read a script line.
1022 * "sourcing_lnum" must be correct!
1023 * When skipping lines it may not actually be executed, but we won't find out
1024 * until later and we need to store the time now.
1025 */
1026 void
1027script_line_start(void)
1028{
1029 scriptitem_T *si;
1030 sn_prl_T *pp;
1031
Bram Moolenaare3d46852020-08-29 13:39:17 +02001032 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001033 return;
Bram Moolenaar21b9e972020-01-26 19:26:46 +01001034 si = SCRIPT_ITEM(current_sctx.sc_sid);
Bram Moolenaar1a47ae32019-12-29 23:04:25 +01001035 if (si->sn_prof_on && SOURCING_LNUM >= 1)
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001036 {
1037 // Grow the array before starting the timer, so that the time spent
1038 // here isn't counted.
1039 (void)ga_grow(&si->sn_prl_ga,
Bram Moolenaar1a47ae32019-12-29 23:04:25 +01001040 (int)(SOURCING_LNUM - si->sn_prl_ga.ga_len));
1041 si->sn_prl_idx = SOURCING_LNUM - 1;
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001042 while (si->sn_prl_ga.ga_len <= si->sn_prl_idx
1043 && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen)
1044 {
1045 // Zero counters for a line that was not used before.
1046 pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len);
1047 pp->snp_count = 0;
1048 profile_zero(&pp->sn_prl_total);
1049 profile_zero(&pp->sn_prl_self);
1050 ++si->sn_prl_ga.ga_len;
1051 }
1052 si->sn_prl_execed = FALSE;
1053 profile_start(&si->sn_prl_start);
1054 profile_zero(&si->sn_prl_children);
1055 profile_get_wait(&si->sn_prl_wait);
1056 }
1057}
1058
1059/*
1060 * Called when actually executing a function line.
1061 */
1062 void
1063script_line_exec(void)
1064{
1065 scriptitem_T *si;
1066
Bram Moolenaare3d46852020-08-29 13:39:17 +02001067 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001068 return;
Bram Moolenaar21b9e972020-01-26 19:26:46 +01001069 si = SCRIPT_ITEM(current_sctx.sc_sid);
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001070 if (si->sn_prof_on && si->sn_prl_idx >= 0)
1071 si->sn_prl_execed = TRUE;
1072}
1073
1074/*
1075 * Called when done with a script line.
1076 */
1077 void
1078script_line_end(void)
1079{
1080 scriptitem_T *si;
1081 sn_prl_T *pp;
1082
Bram Moolenaare3d46852020-08-29 13:39:17 +02001083 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001084 return;
Bram Moolenaar21b9e972020-01-26 19:26:46 +01001085 si = SCRIPT_ITEM(current_sctx.sc_sid);
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001086 if (si->sn_prof_on && si->sn_prl_idx >= 0
1087 && si->sn_prl_idx < si->sn_prl_ga.ga_len)
1088 {
1089 if (si->sn_prl_execed)
1090 {
1091 pp = &PRL_ITEM(si, si->sn_prl_idx);
1092 ++pp->snp_count;
1093 profile_end(&si->sn_prl_start);
1094 profile_sub_wait(&si->sn_prl_wait, &si->sn_prl_start);
1095 profile_add(&pp->sn_prl_total, &si->sn_prl_start);
1096 profile_self(&pp->sn_prl_self, &si->sn_prl_start,
1097 &si->sn_prl_children);
1098 }
1099 si->sn_prl_idx = -1;
1100 }
1101}
1102# endif // FEAT_PROFILE
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02001103
1104#endif