comparison src/profiler.c @ 23717:e3720756acdc v8.2.2400

patch 8.2.2400: Vim9: compiled functions are not profiled Commit: https://github.com/vim/vim/commit/b204990346ca857802b174afe8a7fbb05e4f318e Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 24 12:53:53 2021 +0100 patch 8.2.2400: Vim9: compiled functions are not profiled Problem: Vim9: compiled functions are not profiled. Solution: Add initial changes to profile compiled functions. Fix that a script-local function was hard to debug.
author Bram Moolenaar <Bram@vim.org>
date Sun, 24 Jan 2021 13:00:06 +0100
parents a98211c3e14e
children 03819ebd3e6d
comparison
equal deleted inserted replaced
23716:777aaba7c0ef 23717:e3720756acdc
553 553
554 fp->uf_profiling = TRUE; 554 fp->uf_profiling = TRUE;
555 } 555 }
556 556
557 /* 557 /*
558 * When calling a function: may initialize for profiling.
559 */
560 void
561 profile_may_start_func(profinfo_T *info, ufunc_T *fp, funccall_T *fc)
562 {
563 if (do_profiling == PROF_YES)
564 {
565 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
566 {
567 info->pi_started_profiling = TRUE;
568 func_do_profile(fp);
569 }
570 if (fp->uf_profiling
571 || (fc->caller != NULL && fc->caller->func->uf_profiling))
572 {
573 ++fp->uf_tm_count;
574 profile_start(&info->pi_call_start);
575 profile_zero(&fp->uf_tm_children);
576 }
577 script_prof_save(&info->pi_wait_start);
578 }
579 }
580
581 /*
582 * After calling a function: may handle profiling. profile_may_start_func()
583 * must have been called previously.
584 */
585 void
586 profile_may_end_func(profinfo_T *info, ufunc_T *fp, funccall_T *fc)
587 {
588 profile_end(&info->pi_call_start);
589 profile_sub_wait(&info->pi_wait_start, &info->pi_call_start);
590 profile_add(&fp->uf_tm_total, &info->pi_call_start);
591 profile_self(&fp->uf_tm_self, &info->pi_call_start, &fp->uf_tm_children);
592 if (fc->caller != NULL && fc->caller->func->uf_profiling)
593 {
594 profile_add(&fc->caller->func->uf_tm_children, &info->pi_call_start);
595 profile_add(&fc->caller->func->uf_tml_children, &info->pi_call_start);
596 }
597 if (info->pi_started_profiling)
598 // make a ":profdel func" stop profiling the function
599 fp->uf_profiling = FALSE;
600 }
601
602 /*
558 * Prepare profiling for entering a child or something else that is not 603 * Prepare profiling for entering a child or something else that is not
559 * counted for the script/function itself. 604 * counted for the script/function itself.
560 * Should always be called in pair with prof_child_exit(). 605 * Should always be called in pair with prof_child_exit().
561 */ 606 */
562 void 607 void
595 * "sourcing_lnum" must be correct! 640 * "sourcing_lnum" must be correct!
596 * When skipping lines it may not actually be executed, but we won't find out 641 * When skipping lines it may not actually be executed, but we won't find out
597 * until later and we need to store the time now. 642 * until later and we need to store the time now.
598 */ 643 */
599 void 644 void
600 func_line_start(void *cookie) 645 func_line_start(void *cookie, long lnum)
601 { 646 {
602 funccall_T *fcp = (funccall_T *)cookie; 647 funccall_T *fcp = (funccall_T *)cookie;
603 ufunc_T *fp = fcp->func; 648 ufunc_T *fp = fcp->func;
604 649
605 if (fp->uf_profiling && SOURCING_LNUM >= 1 650 if (fp->uf_profiling && lnum >= 1 && lnum <= fp->uf_lines.ga_len)
606 && SOURCING_LNUM <= fp->uf_lines.ga_len) 651 {
607 { 652 fp->uf_tml_idx = lnum - 1;
608 fp->uf_tml_idx = SOURCING_LNUM - 1;
609 // Skip continuation lines. 653 // Skip continuation lines.
610 while (fp->uf_tml_idx > 0 && FUNCLINE(fp, fp->uf_tml_idx) == NULL) 654 while (fp->uf_tml_idx > 0 && FUNCLINE(fp, fp->uf_tml_idx) == NULL)
611 --fp->uf_tml_idx; 655 --fp->uf_tml_idx;
612 fp->uf_tml_execed = FALSE; 656 fp->uf_tml_execed = FALSE;
613 profile_start(&fp->uf_tml_start); 657 profile_start(&fp->uf_tml_start);