blob: 780b958a918d437efb773b88f5ac2cbd11abda63 [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{
Ernie Rael21d32122023-09-02 15:09:18 +0200667 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL,
668 &fp->uf_hash))
Bram Moolenaarb2049902021-01-24 12:53:53 +0100669 {
Bram Moolenaar12d26532021-02-19 19:13:21 +0100670 info->pi_started_profiling = TRUE;
671 func_do_profile(fp);
Bram Moolenaarb2049902021-01-24 12:53:53 +0100672 }
Bram Moolenaar12d26532021-02-19 19:13:21 +0100673 if (fp->uf_profiling || (caller != NULL && caller->uf_profiling))
674 {
675 ++fp->uf_tm_count;
676 profile_start(&info->pi_call_start);
677 profile_zero(&fp->uf_tm_children);
678 }
679 script_prof_save(&info->pi_wait_start);
Bram Moolenaarb2049902021-01-24 12:53:53 +0100680}
681
682/*
683 * After calling a function: may handle profiling. profile_may_start_func()
684 * must have been called previously.
685 */
686 void
Bram Moolenaar12d26532021-02-19 19:13:21 +0100687profile_may_end_func(profinfo_T *info, ufunc_T *fp, ufunc_T *caller)
Bram Moolenaarb2049902021-01-24 12:53:53 +0100688{
689 profile_end(&info->pi_call_start);
690 profile_sub_wait(&info->pi_wait_start, &info->pi_call_start);
691 profile_add(&fp->uf_tm_total, &info->pi_call_start);
692 profile_self(&fp->uf_tm_self, &info->pi_call_start, &fp->uf_tm_children);
Bram Moolenaar12d26532021-02-19 19:13:21 +0100693 if (caller != NULL && caller->uf_profiling)
Bram Moolenaarb2049902021-01-24 12:53:53 +0100694 {
Bram Moolenaar12d26532021-02-19 19:13:21 +0100695 profile_add(&caller->uf_tm_children, &info->pi_call_start);
696 profile_add(&caller->uf_tml_children, &info->pi_call_start);
Bram Moolenaarb2049902021-01-24 12:53:53 +0100697 }
698 if (info->pi_started_profiling)
699 // make a ":profdel func" stop profiling the function
700 fp->uf_profiling = FALSE;
701}
702
703/*
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200704 * Prepare profiling for entering a child or something else that is not
705 * counted for the script/function itself.
706 * Should always be called in pair with prof_child_exit().
707 */
708 void
709prof_child_enter(
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200710 proftime_T *tm) // place to store waittime
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200711{
712 funccall_T *fc = get_current_funccal();
713
Bram Moolenaarca16c602022-09-06 18:57:08 +0100714 if (fc != NULL && fc->fc_func->uf_profiling)
715 profile_start(&fc->fc_prof_child);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200716 script_prof_save(tm);
717}
718
719/*
720 * Take care of time spent in a child.
721 * Should always be called after prof_child_enter().
722 */
723 void
724prof_child_exit(
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200725 proftime_T *tm) // where waittime was stored
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200726{
727 funccall_T *fc = get_current_funccal();
728
Bram Moolenaarca16c602022-09-06 18:57:08 +0100729 if (fc != NULL && fc->fc_func->uf_profiling)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200730 {
Bram Moolenaarca16c602022-09-06 18:57:08 +0100731 profile_end(&fc->fc_prof_child);
732 profile_sub_wait(tm, &fc->fc_prof_child); // don't count waiting time
733 profile_add(&fc->fc_func->uf_tm_children, &fc->fc_prof_child);
734 profile_add(&fc->fc_func->uf_tml_children, &fc->fc_prof_child);
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200735 }
736 script_prof_restore(tm);
737}
738
739/*
740 * Called when starting to read a function line.
741 * "sourcing_lnum" must be correct!
742 * When skipping lines it may not actually be executed, but we won't find out
743 * until later and we need to store the time now.
744 */
745 void
Bram Moolenaarb2049902021-01-24 12:53:53 +0100746func_line_start(void *cookie, long lnum)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200747{
748 funccall_T *fcp = (funccall_T *)cookie;
Bram Moolenaarca16c602022-09-06 18:57:08 +0100749 ufunc_T *fp = fcp->fc_func;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200750
Bram Moolenaarb2049902021-01-24 12:53:53 +0100751 if (fp->uf_profiling && lnum >= 1 && lnum <= fp->uf_lines.ga_len)
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200752 {
Bram Moolenaarb2049902021-01-24 12:53:53 +0100753 fp->uf_tml_idx = lnum - 1;
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200754 // Skip continuation lines.
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200755 while (fp->uf_tml_idx > 0 && FUNCLINE(fp, fp->uf_tml_idx) == NULL)
756 --fp->uf_tml_idx;
757 fp->uf_tml_execed = FALSE;
758 profile_start(&fp->uf_tml_start);
759 profile_zero(&fp->uf_tml_children);
760 profile_get_wait(&fp->uf_tml_wait);
761 }
762}
763
764/*
765 * Called when actually executing a function line.
766 */
767 void
768func_line_exec(void *cookie)
769{
770 funccall_T *fcp = (funccall_T *)cookie;
Bram Moolenaarca16c602022-09-06 18:57:08 +0100771 ufunc_T *fp = fcp->fc_func;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200772
773 if (fp->uf_profiling && fp->uf_tml_idx >= 0)
774 fp->uf_tml_execed = TRUE;
775}
776
777/*
778 * Called when done with a function line.
779 */
780 void
781func_line_end(void *cookie)
782{
783 funccall_T *fcp = (funccall_T *)cookie;
Bram Moolenaarca16c602022-09-06 18:57:08 +0100784 ufunc_T *fp = fcp->fc_func;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +0200785
786 if (fp->uf_profiling && fp->uf_tml_idx >= 0)
787 {
788 if (fp->uf_tml_execed)
789 {
790 ++fp->uf_tml_count[fp->uf_tml_idx];
791 profile_end(&fp->uf_tml_start);
792 profile_sub_wait(&fp->uf_tml_wait, &fp->uf_tml_start);
793 profile_add(&fp->uf_tml_total[fp->uf_tml_idx], &fp->uf_tml_start);
794 profile_self(&fp->uf_tml_self[fp->uf_tml_idx], &fp->uf_tml_start,
795 &fp->uf_tml_children);
796 }
797 fp->uf_tml_idx = -1;
798 }
799}
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200800
801/*
802 * Dump the profiling results for all functions in file "fd".
803 */
804 static void
805func_dump_profile(FILE *fd)
806{
807 hashtab_T *functbl;
808 hashitem_T *hi;
809 int todo;
810 ufunc_T *fp;
811 int i;
812 ufunc_T **sorttab;
813 int st_len = 0;
814 char_u *p;
815
816 functbl = func_tbl_get();
817 todo = (int)functbl->ht_used;
818 if (todo == 0)
819 return; // nothing to dump
820
821 sorttab = ALLOC_MULT(ufunc_T *, todo);
822
Yegappan Lakshmanan14113fd2023-03-07 17:13:51 +0000823 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo)
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200824 {
825 if (!HASHITEM_EMPTY(hi))
826 {
827 --todo;
828 fp = HI2UF(hi);
829 if (fp->uf_prof_initialized)
830 {
831 if (sorttab != NULL)
832 sorttab[st_len++] = fp;
833
834 if (fp->uf_name[0] == K_SPECIAL)
835 fprintf(fd, "FUNCTION <SNR>%s()\n", fp->uf_name + 3);
836 else
837 fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
Bram Moolenaar16358802019-08-30 18:37:26 +0200838 if (fp->uf_script_ctx.sc_sid > 0)
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200839 {
Bram Moolenaar16358802019-08-30 18:37:26 +0200840 p = home_replace_save(NULL,
841 get_scriptname(fp->uf_script_ctx.sc_sid));
842 if (p != NULL)
843 {
Bram Moolenaar181d4f52019-09-18 22:04:56 +0200844 fprintf(fd, " Defined: %s:%ld\n",
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200845 p, (long)fp->uf_script_ctx.sc_lnum);
Bram Moolenaar16358802019-08-30 18:37:26 +0200846 vim_free(p);
847 }
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200848 }
849 if (fp->uf_tm_count == 1)
850 fprintf(fd, "Called 1 time\n");
851 else
852 fprintf(fd, "Called %d times\n", fp->uf_tm_count);
853 fprintf(fd, "Total time: %s\n", profile_msg(&fp->uf_tm_total));
854 fprintf(fd, " Self time: %s\n", profile_msg(&fp->uf_tm_self));
855 fprintf(fd, "\n");
Ernie Rael076de792023-03-16 21:43:15 +0000856 fprintf(fd, "%s\n", PROF_TOTALS_HEADER);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200857
858 for (i = 0; i < fp->uf_lines.ga_len; ++i)
859 {
860 if (FUNCLINE(fp, i) == NULL)
861 continue;
862 prof_func_line(fd, fp->uf_tml_count[i],
863 &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE);
864 fprintf(fd, "%s\n", FUNCLINE(fp, i));
865 }
866 fprintf(fd, "\n");
867 }
868 }
869 }
870
871 if (sorttab != NULL && st_len > 0)
872 {
873 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
874 prof_total_cmp);
875 prof_sort_list(fd, sorttab, st_len, "TOTAL", FALSE);
876 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
877 prof_self_cmp);
878 prof_sort_list(fd, sorttab, st_len, "SELF", TRUE);
879 }
880
881 vim_free(sorttab);
882}
883
884/*
885 * Start profiling script "fp".
886 */
887 void
888script_do_profile(scriptitem_T *si)
889{
890 si->sn_pr_count = 0;
891 profile_zero(&si->sn_pr_total);
892 profile_zero(&si->sn_pr_self);
893
894 ga_init2(&si->sn_prl_ga, sizeof(sn_prl_T), 100);
895 si->sn_prl_idx = -1;
896 si->sn_prof_on = TRUE;
897 si->sn_pr_nest = 0;
898}
899
900/*
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200901 * Count time spent in children after invoking another script or function.
902 */
903 void
904script_prof_restore(proftime_T *tm)
905{
906 scriptitem_T *si;
907
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +0000908 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
909 return;
910
911 si = SCRIPT_ITEM(current_sctx.sc_sid);
912 if (si->sn_prof_on && --si->sn_pr_nest == 0)
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200913 {
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +0000914 profile_end(&si->sn_pr_child);
915 profile_sub_wait(tm, &si->sn_pr_child); // don't count wait time
916 profile_add(&si->sn_pr_children, &si->sn_pr_child);
917 profile_add(&si->sn_prl_children, &si->sn_pr_child);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200918 }
919}
920
921/*
922 * Dump the profiling results for all scripts in file "fd".
923 */
924 static void
925script_dump_profile(FILE *fd)
926{
927 int id;
928 scriptitem_T *si;
929 int i;
930 FILE *sfd;
931 sn_prl_T *pp;
932
933 for (id = 1; id <= script_items.ga_len; ++id)
934 {
Bram Moolenaar21b9e972020-01-26 19:26:46 +0100935 si = SCRIPT_ITEM(id);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200936 if (si->sn_prof_on)
937 {
938 fprintf(fd, "SCRIPT %s\n", si->sn_name);
939 if (si->sn_pr_count == 1)
940 fprintf(fd, "Sourced 1 time\n");
941 else
942 fprintf(fd, "Sourced %d times\n", si->sn_pr_count);
943 fprintf(fd, "Total time: %s\n", profile_msg(&si->sn_pr_total));
944 fprintf(fd, " Self time: %s\n", profile_msg(&si->sn_pr_self));
945 fprintf(fd, "\n");
Ernie Rael076de792023-03-16 21:43:15 +0000946 fprintf(fd, "%s\n", PROF_TOTALS_HEADER);
Bram Moolenaar660a10a2019-07-14 15:48:38 +0200947
948 sfd = mch_fopen((char *)si->sn_name, "r");
949 if (sfd == NULL)
950 fprintf(fd, "Cannot open file!\n");
951 else
952 {
953 // Keep going till the end of file, so that trailing
954 // continuation lines are listed.
955 for (i = 0; ; ++i)
956 {
957 if (vim_fgets(IObuff, IOSIZE, sfd))
958 break;
959 // When a line has been truncated, append NL, taking care
960 // of multi-byte characters .
961 if (IObuff[IOSIZE - 2] != NUL && IObuff[IOSIZE - 2] != NL)
962 {
963 int n = IOSIZE - 2;
964
965 if (enc_utf8)
966 {
967 // Move to the first byte of this char.
968 // utf_head_off() doesn't work, because it checks
969 // for a truncated character.
970 while (n > 0 && (IObuff[n] & 0xc0) == 0x80)
971 --n;
972 }
973 else if (has_mbyte)
974 n -= mb_head_off(IObuff, IObuff + n);
975 IObuff[n] = NL;
976 IObuff[n + 1] = NUL;
977 }
978 if (i < si->sn_prl_ga.ga_len
979 && (pp = &PRL_ITEM(si, i))->snp_count > 0)
980 {
981 fprintf(fd, "%5d ", pp->snp_count);
982 if (profile_equal(&pp->sn_prl_total, &pp->sn_prl_self))
983 fprintf(fd, " ");
984 else
985 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total));
986 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_self));
987 }
988 else
989 fprintf(fd, " ");
990 fprintf(fd, "%s", IObuff);
991 }
992 fclose(sfd);
993 }
994 fprintf(fd, "\n");
995 }
996 }
997}
998
999/*
1000 * Dump the profiling info.
1001 */
1002 void
1003profile_dump(void)
1004{
1005 FILE *fd;
1006
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +00001007 if (profile_fname == NULL)
1008 return;
1009
1010 fd = mch_fopen((char *)profile_fname, "w");
1011 if (fd == NULL)
1012 semsg(_(e_cant_open_file_str), profile_fname);
1013 else
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001014 {
Yegappan Lakshmananf97a2952023-01-18 18:17:48 +00001015 script_dump_profile(fd);
1016 func_dump_profile(fd);
1017 fclose(fd);
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001018 }
1019}
1020
1021/*
1022 * Called when starting to read a script line.
1023 * "sourcing_lnum" must be correct!
1024 * When skipping lines it may not actually be executed, but we won't find out
1025 * until later and we need to store the time now.
1026 */
1027 void
1028script_line_start(void)
1029{
1030 scriptitem_T *si;
1031 sn_prl_T *pp;
1032
Bram Moolenaare3d46852020-08-29 13:39:17 +02001033 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001034 return;
Bram Moolenaar21b9e972020-01-26 19:26:46 +01001035 si = SCRIPT_ITEM(current_sctx.sc_sid);
Bram Moolenaar1a47ae32019-12-29 23:04:25 +01001036 if (si->sn_prof_on && SOURCING_LNUM >= 1)
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001037 {
1038 // Grow the array before starting the timer, so that the time spent
1039 // here isn't counted.
1040 (void)ga_grow(&si->sn_prl_ga,
Bram Moolenaar1a47ae32019-12-29 23:04:25 +01001041 (int)(SOURCING_LNUM - si->sn_prl_ga.ga_len));
1042 si->sn_prl_idx = SOURCING_LNUM - 1;
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001043 while (si->sn_prl_ga.ga_len <= si->sn_prl_idx
1044 && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen)
1045 {
1046 // Zero counters for a line that was not used before.
1047 pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len);
1048 pp->snp_count = 0;
1049 profile_zero(&pp->sn_prl_total);
1050 profile_zero(&pp->sn_prl_self);
1051 ++si->sn_prl_ga.ga_len;
1052 }
1053 si->sn_prl_execed = FALSE;
1054 profile_start(&si->sn_prl_start);
1055 profile_zero(&si->sn_prl_children);
1056 profile_get_wait(&si->sn_prl_wait);
1057 }
1058}
1059
1060/*
1061 * Called when actually executing a function line.
1062 */
1063 void
1064script_line_exec(void)
1065{
1066 scriptitem_T *si;
1067
Bram Moolenaare3d46852020-08-29 13:39:17 +02001068 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001069 return;
Bram Moolenaar21b9e972020-01-26 19:26:46 +01001070 si = SCRIPT_ITEM(current_sctx.sc_sid);
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001071 if (si->sn_prof_on && si->sn_prl_idx >= 0)
1072 si->sn_prl_execed = TRUE;
1073}
1074
1075/*
1076 * Called when done with a script line.
1077 */
1078 void
1079script_line_end(void)
1080{
1081 scriptitem_T *si;
1082 sn_prl_T *pp;
1083
Bram Moolenaare3d46852020-08-29 13:39:17 +02001084 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001085 return;
Bram Moolenaar21b9e972020-01-26 19:26:46 +01001086 si = SCRIPT_ITEM(current_sctx.sc_sid);
Bram Moolenaar660a10a2019-07-14 15:48:38 +02001087 if (si->sn_prof_on && si->sn_prl_idx >= 0
1088 && si->sn_prl_idx < si->sn_prl_ga.ga_len)
1089 {
1090 if (si->sn_prl_execed)
1091 {
1092 pp = &PRL_ITEM(si, si->sn_prl_idx);
1093 ++pp->snp_count;
1094 profile_end(&si->sn_prl_start);
1095 profile_sub_wait(&si->sn_prl_wait, &si->sn_prl_start);
1096 profile_add(&pp->sn_prl_total, &si->sn_prl_start);
1097 profile_self(&pp->sn_prl_self, &si->sn_prl_start,
1098 &si->sn_prl_children);
1099 }
1100 si->sn_prl_idx = -1;
1101 }
1102}
1103# endif // FEAT_PROFILE
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02001104
1105#endif