patch 8.2.4712: only get profiling information after exiting
Problem: Only get profiling information after exiting.
Solution: Add "profile dump" and "profile stop". (Marco Hinz, Yegappan
Lakshmanan, closes #10107)
diff --git a/src/profiler.c b/src/profiler.c
index f1b9a40..8b6b810 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -299,6 +299,82 @@
static proftime_T pause_time;
/*
+ * Reset all profiling information.
+ */
+ static void
+profile_reset(void)
+{
+ int id;
+ int todo;
+ hashtab_T *functbl;
+ hashitem_T *hi;
+
+ // Reset sourced files.
+ for (id = 1; id <= script_items.ga_len; id++)
+ {
+ scriptitem_T *si = SCRIPT_ITEM(id);
+ if (si->sn_prof_on)
+ {
+ si->sn_prof_on = FALSE;
+ si->sn_pr_force = FALSE;
+ profile_zero(&si->sn_pr_child);
+ si->sn_pr_nest = 0;
+ si->sn_pr_count = 0;
+ profile_zero(&si->sn_pr_total);
+ profile_zero(&si->sn_pr_self);
+ profile_zero(&si->sn_pr_start);
+ profile_zero(&si->sn_pr_children);
+ ga_clear(&si->sn_prl_ga);
+ profile_zero(&si->sn_prl_start);
+ profile_zero(&si->sn_prl_children);
+ profile_zero(&si->sn_prl_wait);
+ si->sn_prl_idx = -1;
+ si->sn_prl_execed = 0;
+ }
+ }
+
+ // Reset functions.
+ functbl = func_tbl_get();
+ todo = (int)functbl->ht_used;
+
+ for (hi = functbl->ht_array; todo > 0; ++hi)
+ {
+ ufunc_T *fp;
+ int i;
+
+ if (HASHITEM_EMPTY(hi))
+ continue;
+
+ todo--;
+ fp = HI2UF(hi);
+ if (fp->uf_prof_initialized)
+ {
+ fp->uf_profiling = 0;
+ fp->uf_prof_initialized = FALSE;
+ fp->uf_tm_count = 0;
+ profile_zero(&fp->uf_tm_total);
+ profile_zero(&fp->uf_tm_self);
+ profile_zero(&fp->uf_tm_children);
+
+ for (i = 0; i < fp->uf_lines.ga_len; i++)
+ {
+ fp->uf_tml_count[i] = 0;
+ profile_zero(&fp->uf_tml_total[i]);
+ profile_zero(&fp->uf_tml_self[i]);
+ }
+
+ profile_zero(&fp->uf_tml_start);
+ profile_zero(&fp->uf_tml_children);
+ profile_zero(&fp->uf_tml_wait);
+ fp->uf_tml_idx = -1;
+ fp->uf_tml_execed = 0;
+ }
+ }
+
+ VIM_CLEAR(profile_fname);
+}
+
+/*
* ":profile cmd args"
*/
void
@@ -313,7 +389,7 @@
if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL)
{
- vim_free(profile_fname);
+ VIM_CLEAR(profile_fname);
profile_fname = expand_env_save_opt(e, TRUE);
do_profiling = PROF_YES;
profile_zero(&prof_wait_time);
@@ -321,6 +397,13 @@
}
else if (do_profiling == PROF_NONE)
emsg(_(e_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);
+ profile_reset();
+ }
else if (STRCMP(eap->arg, "pause") == 0)
{
if (do_profiling == PROF_YES)
@@ -336,6 +419,8 @@
}
do_profiling = PROF_YES;
}
+ else if (STRCMP(eap->arg, "dump") == 0)
+ profile_dump();
else
{
// The rest is similar to ":breakadd".
@@ -353,16 +438,20 @@
static char *pexpand_cmds[] = {
"start",
#define PROFCMD_START 0
+ "stop",
+#define PROFCMD_STOP 1
"pause",
-#define PROFCMD_PAUSE 1
+#define PROFCMD_PAUSE 2
"continue",
-#define PROFCMD_CONTINUE 2
+#define PROFCMD_CONTINUE 3
"func",
-#define PROFCMD_FUNC 3
+#define PROFCMD_FUNC 4
"file",
-#define PROFCMD_FILE 4
+#define PROFCMD_DUMP 5
+ "dump",
+#define PROFCMD_FILE 6
NULL
-#define PROFCMD_LAST 5
+#define PROFCMD_LAST 7
};
/*