diff options
Diffstat (limited to 'src/nvim/profile.c')
-rw-r--r-- | src/nvim/profile.c | 146 |
1 files changed, 61 insertions, 85 deletions
diff --git a/src/nvim/profile.c b/src/nvim/profile.c index fd024f2d38..53ff57dacb 100644 --- a/src/nvim/profile.c +++ b/src/nvim/profile.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include <assert.h> #include <math.h> #include <stdbool.h> @@ -9,14 +6,16 @@ #include <stdlib.h> #include <string.h> -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/debugger.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" #include "nvim/eval/userfunc.h" #include "nvim/ex_cmds_defs.h" #include "nvim/fileio.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/gettext.h" #include "nvim/globals.h" @@ -24,14 +23,13 @@ #include "nvim/keycodes.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/option_defs.h" +#include "nvim/os/fs.h" #include "nvim/os/os.h" #include "nvim/os/time.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/profile.h" #include "nvim/runtime.h" -#include "nvim/types.h" -#include "nvim/vim.h" +#include "nvim/types_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "profile.c.generated.h" @@ -232,23 +230,23 @@ void profile_reset(void) { // Reset sourced files. for (int id = 1; id <= script_items.ga_len; id++) { - scriptitem_T *si = &SCRIPT_ITEM(id); + scriptitem_T *si = SCRIPT_ITEM(id); if (si->sn_prof_on) { - si->sn_prof_on = false; - si->sn_pr_force = false; - si->sn_pr_child = profile_zero(); - si->sn_pr_nest = 0; - si->sn_pr_count = 0; - si->sn_pr_total = profile_zero(); - si->sn_pr_self = profile_zero(); - si->sn_pr_start = profile_zero(); - si->sn_pr_children = profile_zero(); + si->sn_prof_on = false; + si->sn_pr_force = false; + si->sn_pr_child = profile_zero(); + si->sn_pr_nest = 0; + si->sn_pr_count = 0; + si->sn_pr_total = profile_zero(); + si->sn_pr_self = profile_zero(); + si->sn_pr_start = profile_zero(); + si->sn_pr_children = profile_zero(); ga_clear(&si->sn_prl_ga); - si->sn_prl_start = profile_zero(); + si->sn_prl_start = profile_zero(); si->sn_prl_children = profile_zero(); - si->sn_prl_wait = profile_zero(); - si->sn_prl_idx = -1; - si->sn_prl_execed = 0; + si->sn_prl_wait = profile_zero(); + si->sn_prl_idx = -1; + si->sn_prl_execed = 0; } } @@ -262,22 +260,22 @@ void profile_reset(void) todo--; ufunc_T *uf = HI2UF(hi); if (uf->uf_prof_initialized) { - uf->uf_profiling = 0; - uf->uf_tm_count = 0; - uf->uf_tm_total = profile_zero(); - uf->uf_tm_self = profile_zero(); - uf->uf_tm_children = profile_zero(); + uf->uf_profiling = 0; + uf->uf_tm_count = 0; + uf->uf_tm_total = profile_zero(); + uf->uf_tm_self = profile_zero(); + uf->uf_tm_children = profile_zero(); for (int i = 0; i < uf->uf_lines.ga_len; i++) { uf->uf_tml_count[i] = 0; uf->uf_tml_total[i] = uf->uf_tml_self[i] = 0; } - uf->uf_tml_start = profile_zero(); + uf->uf_tml_start = profile_zero(); uf->uf_tml_children = profile_zero(); - uf->uf_tml_wait = profile_zero(); - uf->uf_tml_idx = -1; - uf->uf_tml_execed = 0; + uf->uf_tml_wait = profile_zero(); + uf->uf_tml_idx = -1; + uf->uf_tml_execed = 0; } } } @@ -290,11 +288,8 @@ void ex_profile(exarg_T *eap) { static proftime_T pause_time; - char *e; - int len; - - e = skiptowhite(eap->arg); - len = (int)(e - eap->arg); + char *e = skiptowhite(eap->arg); + int len = (int)(e - eap->arg); e = skipwhite(e); if (len == 5 && strncmp(eap->arg, "start", 5) == 0 && *e != NUL) { @@ -302,13 +297,13 @@ void ex_profile(exarg_T *eap) profile_fname = expand_env_save_opt(e, true); do_profiling = PROF_YES; profile_set_wait(profile_zero()); - set_vim_var_nr(VV_PROFILING, 1L); + set_vim_var_nr(VV_PROFILING, 1); } else if (do_profiling == PROF_NONE) { emsg(_("E750: First use \":profile start {fname}\"")); } else if (strcmp(eap->arg, "stop") == 0) { profile_dump(); do_profiling = PROF_NONE; - set_vim_var_nr(VV_PROFILING, 0L); + set_vim_var_nr(VV_PROFILING, 0); profile_reset(); } else if (strcmp(eap->arg, "pause") == 0) { if (do_profiling == PROF_YES) { @@ -407,7 +402,7 @@ bool prof_def_func(void) FUNC_ATTR_PURE { if (current_sctx.sc_sid > 0) { - return SCRIPT_ITEM(current_sctx.sc_sid).sn_pr_force; + return SCRIPT_ITEM(current_sctx.sc_sid)->sn_pr_force; } return false; } @@ -438,13 +433,10 @@ static void prof_func_line(FILE *fd, int count, const proftime_T *total, const p /// @param prefer_self when equal print only self time static void prof_sort_list(FILE *fd, ufunc_T **sorttab, int st_len, char *title, bool prefer_self) { - int i; - ufunc_T *fp; - fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title); fprintf(fd, "count total (s) self (s) function\n"); - for (i = 0; i < 20 && i < st_len; i++) { - fp = sorttab[i]; + for (int i = 0; i < 20 && i < st_len; i++) { + ufunc_T *fp = sorttab[i]; prof_func_line(fd, fp->uf_tm_count, &fp->uf_tm_total, &fp->uf_tm_self, prefer_self); if ((uint8_t)fp->uf_name[0] == K_SPECIAL) { @@ -513,8 +505,8 @@ void prof_child_enter(proftime_T *tm) { funccall_T *fc = get_current_funccal(); - if (fc != NULL && fc->func->uf_profiling) { - fc->prof_child = profile_start(); + if (fc != NULL && fc->fc_func->uf_profiling) { + fc->fc_prof_child = profile_start(); } script_prof_save(tm); @@ -528,14 +520,14 @@ void prof_child_exit(proftime_T *tm) { funccall_T *fc = get_current_funccal(); - if (fc != NULL && fc->func->uf_profiling) { - fc->prof_child = profile_end(fc->prof_child); + if (fc != NULL && fc->fc_func->uf_profiling) { + fc->fc_prof_child = profile_end(fc->fc_prof_child); // don't count waiting time - fc->prof_child = profile_sub_wait(*tm, fc->prof_child); - fc->func->uf_tm_children = - profile_add(fc->func->uf_tm_children, fc->prof_child); - fc->func->uf_tml_children = - profile_add(fc->func->uf_tml_children, fc->prof_child); + fc->fc_prof_child = profile_sub_wait(*tm, fc->fc_prof_child); + fc->fc_func->uf_tm_children = + profile_add(fc->fc_func->uf_tm_children, fc->fc_prof_child); + fc->fc_func->uf_tml_children = + profile_add(fc->fc_func->uf_tml_children, fc->fc_prof_child); } script_prof_restore(tm); } @@ -547,7 +539,7 @@ void prof_child_exit(proftime_T *tm) void func_line_start(void *cookie) { funccall_T *fcp = (funccall_T *)cookie; - ufunc_T *fp = fcp->func; + ufunc_T *fp = fcp->fc_func; if (fp->uf_profiling && SOURCING_LNUM >= 1 && SOURCING_LNUM <= fp->uf_lines.ga_len) { fp->uf_tml_idx = SOURCING_LNUM - 1; @@ -566,7 +558,7 @@ void func_line_start(void *cookie) void func_line_exec(void *cookie) { funccall_T *fcp = (funccall_T *)cookie; - ufunc_T *fp = fcp->func; + ufunc_T *fp = fcp->fc_func; if (fp->uf_profiling && fp->uf_tml_idx >= 0) { fp->uf_tml_execed = true; @@ -577,7 +569,7 @@ void func_line_exec(void *cookie) void func_line_end(void *cookie) { funccall_T *fcp = (funccall_T *)cookie; - ufunc_T *fp = fcp->func; + ufunc_T *fp = fcp->fc_func; if (fp->uf_profiling && fp->uf_tml_idx >= 0) { if (fp->uf_tml_execed) { @@ -598,23 +590,19 @@ void func_line_end(void *cookie) static void func_dump_profile(FILE *fd) { hashtab_T *const functbl = func_tbl_get(); - hashitem_T *hi; - int todo; - ufunc_T *fp; - ufunc_T **sorttab; int st_len = 0; - todo = (int)functbl->ht_used; + int todo = (int)functbl->ht_used; if (todo == 0) { return; // nothing to dump } - sorttab = xmalloc(sizeof(ufunc_T *) * (size_t)todo); + ufunc_T **sorttab = xmalloc(sizeof(ufunc_T *) * (size_t)todo); - for (hi = functbl->ht_array; todo > 0; hi++) { + for (hashitem_T *hi = functbl->ht_array; todo > 0; hi++) { if (!HASHITEM_EMPTY(hi)) { todo--; - fp = HI2UF(hi); + ufunc_T *fp = HI2UF(hi); if (fp->uf_prof_initialized) { sorttab[st_len++] = fp; @@ -689,10 +677,8 @@ void profile_init(scriptitem_T *si) /// @param tm place to store wait time void script_prof_save(proftime_T *tm) { - scriptitem_T *si; - if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) { - si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && si->sn_pr_nest++ == 0) { si->sn_pr_child = profile_start(); } @@ -707,7 +693,7 @@ void script_prof_restore(const proftime_T *tm) return; } - scriptitem_T *si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && --si->sn_pr_nest == 0) { si->sn_pr_child = profile_end(si->sn_pr_child); // don't count wait time @@ -720,12 +706,10 @@ void script_prof_restore(const proftime_T *tm) /// Dump the profiling results for all scripts in file "fd". static void script_dump_profile(FILE *fd) { - scriptitem_T *si; - FILE *sfd; sn_prl_T *pp; for (int id = 1; id <= script_items.ga_len; id++) { - si = &SCRIPT_ITEM(id); + scriptitem_T *si = SCRIPT_ITEM(id); if (si->sn_prof_on) { fprintf(fd, "SCRIPT %s\n", si->sn_name); if (si->sn_pr_count == 1) { @@ -738,7 +722,7 @@ static void script_dump_profile(FILE *fd) fprintf(fd, "\n"); fprintf(fd, "count total (s) self (s)\n"); - sfd = os_fopen(si->sn_name, "r"); + FILE *sfd = os_fopen(si->sn_name, "r"); if (sfd == NULL) { fprintf(fd, "Cannot open file!\n"); } else { @@ -807,13 +791,10 @@ void profile_dump(void) /// until later and we need to store the time now. void script_line_start(void) { - scriptitem_T *si; - sn_prl_T *pp; - if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) { return; } - si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && SOURCING_LNUM >= 1) { // Grow the array before starting the timer, so that the time spent // here isn't counted. @@ -822,7 +803,7 @@ void script_line_start(void) while (si->sn_prl_ga.ga_len <= si->sn_prl_idx && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen) { // Zero counters for a line that was not used before. - pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len); + sn_prl_T *pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len); pp->snp_count = 0; pp->sn_prl_total = profile_zero(); pp->sn_prl_self = profile_zero(); @@ -838,12 +819,10 @@ void script_line_start(void) /// Called when actually executing a function line. void script_line_exec(void) { - scriptitem_T *si; - if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) { return; } - si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && si->sn_prl_idx >= 0) { si->sn_prl_execed = true; } @@ -852,17 +831,14 @@ void script_line_exec(void) /// Called when done with a function line. void script_line_end(void) { - scriptitem_T *si; - sn_prl_T *pp; - if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) { return; } - si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && si->sn_prl_idx >= 0 && si->sn_prl_idx < si->sn_prl_ga.ga_len) { if (si->sn_prl_execed) { - pp = &PRL_ITEM(si, si->sn_prl_idx); + sn_prl_T *pp = &PRL_ITEM(si, si->sn_prl_idx); pp->snp_count++; si->sn_prl_start = profile_end(si->sn_prl_start); si->sn_prl_start = profile_sub_wait(si->sn_prl_wait, si->sn_prl_start); |