]> granicus.if.org Git - vim/commitdiff
patch 8.1.0130: ":profdel func" does not work if func was called already v8.1.0130
authorBram Moolenaar <Bram@vim.org>
Sat, 30 Jun 2018 16:28:03 +0000 (18:28 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 30 Jun 2018 16:28:03 +0000 (18:28 +0200)
Problem:    ":profdel func" does not work if func was called already.
            (Dominique Pelle)
Solution:   Reset uf_profiling and add a flag to indicate initialization was
            done.

src/structs.h
src/userfunc.c
src/version.c

index a2de2441e930316c0055403491e444d6b838ab09..ec109eb893022ee9d10a2295a797cdfd825aca6f 100644 (file)
@@ -1345,6 +1345,7 @@ typedef struct
     garray_T   uf_lines;       /* function lines */
 #ifdef FEAT_PROFILE
     int                uf_profiling;   /* TRUE when func is being profiled */
+    int                uf_prof_initialized;
     /* profiling the function as a whole */
     int                uf_tm_count;    /* nr of calls */
     proftime_T uf_tm_total;    /* time spent in function + children */
index 08112689df8894103a921539b649a4160fa69c55..1c17737ac7f76b6c914d1f03b11dac456623caf6 100644 (file)
@@ -293,10 +293,6 @@ get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate)
            fp->uf_scoped = NULL;
 
 #ifdef FEAT_PROFILE
-       fp->uf_tml_count = NULL;
-       fp->uf_tml_total = NULL;
-       fp->uf_tml_self = NULL;
-       fp->uf_profiling = FALSE;
        if (prof_def_func())
            func_do_profile(fp);
 #endif
@@ -706,6 +702,7 @@ call_user_func(
 #ifdef FEAT_PROFILE
     proftime_T wait_start;
     proftime_T call_start;
+    int                started_profiling = FALSE;
 #endif
 
     /* If depth of calling is getting too high, don't execute the function */
@@ -921,7 +918,10 @@ call_user_func(
     if (do_profiling == PROF_YES)
     {
        if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
+       {
+           started_profiling = TRUE;
            func_do_profile(fp);
+       }
        if (fp->uf_profiling
                    || (fc->caller != NULL && fc->caller->func->uf_profiling))
        {
@@ -965,6 +965,9 @@ call_user_func(
            profile_add(&fc->caller->func->uf_tm_children, &call_start);
            profile_add(&fc->caller->func->uf_tml_children, &call_start);
        }
+       if (started_profiling)
+           // make a ":profdel func" stop profiling the function
+           fp->uf_profiling = FALSE;
     }
 #endif
 
@@ -2522,23 +2525,28 @@ func_do_profile(ufunc_T *fp)
 {
     int                len = fp->uf_lines.ga_len;
 
-    if (len == 0)
-       len = 1;  /* avoid getting error for allocating zero bytes */
-    fp->uf_tm_count = 0;
-    profile_zero(&fp->uf_tm_self);
-    profile_zero(&fp->uf_tm_total);
-    if (fp->uf_tml_count == NULL)
-       fp->uf_tml_count = (int *)alloc_clear((unsigned) (sizeof(int) * len));
-    if (fp->uf_tml_total == NULL)
-       fp->uf_tml_total = (proftime_T *)alloc_clear((unsigned)
-                                                 (sizeof(proftime_T) * len));
-    if (fp->uf_tml_self == NULL)
-       fp->uf_tml_self = (proftime_T *)alloc_clear((unsigned)
-                                                 (sizeof(proftime_T) * len));
-    fp->uf_tml_idx = -1;
-    if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL
-                                                  || fp->uf_tml_self == NULL)
-       return;     /* out of memory */
+    if (!fp->uf_prof_initialized)
+    {
+       if (len == 0)
+           len = 1;  /* avoid getting error for allocating zero bytes */
+       fp->uf_tm_count = 0;
+       profile_zero(&fp->uf_tm_self);
+       profile_zero(&fp->uf_tm_total);
+       if (fp->uf_tml_count == NULL)
+           fp->uf_tml_count = (int *)alloc_clear(
+                                              (unsigned)(sizeof(int) * len));
+       if (fp->uf_tml_total == NULL)
+           fp->uf_tml_total = (proftime_T *)alloc_clear(
+                                        (unsigned)(sizeof(proftime_T) * len));
+       if (fp->uf_tml_self == NULL)
+           fp->uf_tml_self = (proftime_T *)alloc_clear(
+                                        (unsigned)(sizeof(proftime_T) * len));
+       fp->uf_tml_idx = -1;
+       if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL
+                                                   || fp->uf_tml_self == NULL)
+           return;         /* out of memory */
+       fp->uf_prof_initialized = TRUE;
+    }
 
     fp->uf_profiling = TRUE;
 }
@@ -2568,7 +2576,7 @@ func_dump_profile(FILE *fd)
        {
            --todo;
            fp = HI2UF(hi);
-           if (fp->uf_profiling)
+           if (fp->uf_prof_initialized)
            {
                if (sorttab != NULL)
                    sorttab[st_len++] = fp;
index f4399cc5c9dc5669714718c155ae01f866fab499..bc3d06a3219d13ad2c5d7ce40a0f0b8fbd7d5b63 100644 (file)
@@ -789,6 +789,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    130,
 /**/
     129,
 /**/