diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-01-24 12:53:53 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-01-24 12:53:53 +0100 |
commit | b204990346ca857802b174afe8a7fbb05e4f318e (patch) | |
tree | 6660d87cac14e978841c1eaf55994bf8a85f84a9 /src/profiler.c | |
parent | 7cf0c114d690c91ac88c92a1a6f1b1935cb6410f (diff) | |
download | vim-git-b204990346ca857802b174afe8a7fbb05e4f318e.tar.gz |
patch 8.2.2400: Vim9: compiled functions are not profiledv8.2.2400
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.
Diffstat (limited to 'src/profiler.c')
-rw-r--r-- | src/profiler.c | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/src/profiler.c b/src/profiler.c index 7896897a4..46ab3e305 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -555,6 +555,51 @@ func_do_profile(ufunc_T *fp) } /* + * When calling a function: may initialize for profiling. + */ + void +profile_may_start_func(profinfo_T *info, ufunc_T *fp, funccall_T *fc) +{ + if (do_profiling == PROF_YES) + { + if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL)) + { + info->pi_started_profiling = TRUE; + func_do_profile(fp); + } + if (fp->uf_profiling + || (fc->caller != NULL && fc->caller->func->uf_profiling)) + { + ++fp->uf_tm_count; + profile_start(&info->pi_call_start); + profile_zero(&fp->uf_tm_children); + } + script_prof_save(&info->pi_wait_start); + } +} + +/* + * After calling a function: may handle profiling. profile_may_start_func() + * must have been called previously. + */ + void +profile_may_end_func(profinfo_T *info, ufunc_T *fp, funccall_T *fc) +{ + profile_end(&info->pi_call_start); + profile_sub_wait(&info->pi_wait_start, &info->pi_call_start); + profile_add(&fp->uf_tm_total, &info->pi_call_start); + profile_self(&fp->uf_tm_self, &info->pi_call_start, &fp->uf_tm_children); + if (fc->caller != NULL && fc->caller->func->uf_profiling) + { + profile_add(&fc->caller->func->uf_tm_children, &info->pi_call_start); + profile_add(&fc->caller->func->uf_tml_children, &info->pi_call_start); + } + if (info->pi_started_profiling) + // make a ":profdel func" stop profiling the function + fp->uf_profiling = FALSE; +} + +/* * Prepare profiling for entering a child or something else that is not * counted for the script/function itself. * Should always be called in pair with prof_child_exit(). @@ -597,15 +642,14 @@ prof_child_exit( * until later and we need to store the time now. */ void -func_line_start(void *cookie) +func_line_start(void *cookie, long lnum) { funccall_T *fcp = (funccall_T *)cookie; ufunc_T *fp = fcp->func; - if (fp->uf_profiling && SOURCING_LNUM >= 1 - && SOURCING_LNUM <= fp->uf_lines.ga_len) + if (fp->uf_profiling && lnum >= 1 && lnum <= fp->uf_lines.ga_len) { - fp->uf_tml_idx = SOURCING_LNUM - 1; + fp->uf_tml_idx = lnum - 1; // Skip continuation lines. while (fp->uf_tml_idx > 0 && FUNCLINE(fp, fp->uf_tml_idx) == NULL) --fp->uf_tml_idx; |