annotate src/profiler.c @ 32160:98774a275d6d v9.0.1411

patch 9.0.1411: accuracy of profiling is not optimal Commit: https://github.com/vim/vim/commit/076de79ad832558267b3ff903c048df2f4c1a5d6 Author: Ernie Rael <errael@raelity.com> Date: Thu Mar 16 21:43:15 2023 +0000 patch 9.0.1411: accuracy of profiling is not optimal Problem: Accuracy of profiling is not optimal. Solution: Use CLOCK_MONOTONIC if possible. (Ernie Rael, closes https://github.com/vim/vim/issues/12129)
author Bram Moolenaar <Bram@vim.org>
date Thu, 16 Mar 2023 22:45:04 +0100
parents 04d9dff67d99
children 6cfad8cc5f1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * profiler.c: vim script profiler
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 # if defined(FEAT_PROFILE) || defined(FEAT_RELTIME) || defined(PROTO)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * Store the current time in "tm".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 profile_start(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 QueryPerformanceCounter(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
27 PROF_GET_TIME(tm);
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 * Compute the elapsed time from "tm" till now and store in "tm".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 profile_end(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 proftime_T now;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 QueryPerformanceCounter(&now);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 tm->QuadPart = now.QuadPart - tm->QuadPart;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
43 PROF_GET_TIME(&now);
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
44 tm->tv_fsec = now.tv_fsec - tm->tv_fsec;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 tm->tv_sec = now.tv_sec - tm->tv_sec;
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
46 if (tm->tv_fsec < 0)
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 {
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
48 tm->tv_fsec += TV_FSEC_SEC;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 --tm->tv_sec;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 * Subtract the time "tm2" from "tm".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 profile_sub(proftime_T *tm, proftime_T *tm2)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 tm->QuadPart -= tm2->QuadPart;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
63 tm->tv_fsec -= tm2->tv_fsec;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 tm->tv_sec -= tm2->tv_sec;
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
65 if (tm->tv_fsec < 0)
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 {
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
67 tm->tv_fsec += TV_FSEC_SEC;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 --tm->tv_sec;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 * Return a string that represents the time in "tm".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 * Uses a static buffer!
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 char *
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 profile_msg(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 static char buf[50];
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 LARGE_INTEGER fr;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 QueryPerformanceFrequency(&fr);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
88 sprintf(buf, PROF_TIME_FORMAT, (long)tm->tv_sec, (long)tm->tv_fsec);
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 return buf;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 * Return a float that represents the time in "tm".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 float_T
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 profile_float(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 {
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 30124
diff changeset
99 # ifdef MSWIN
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 LARGE_INTEGER fr;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 QueryPerformanceFrequency(&fr);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 return (float_T)tm->QuadPart / (float_T)fr.QuadPart;
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 30124
diff changeset
104 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
105 return (float_T)tm->tv_sec + (float_T)tm->tv_fsec / (float_T)TV_FSEC_SEC;
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 30124
diff changeset
106 # endif
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 * Put the time "msec" past now in "tm".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 profile_setlimit(long msec, proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 {
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
115 if (msec <= 0) // no limit
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 profile_zero(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 LARGE_INTEGER fr;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 QueryPerformanceCounter(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 QueryPerformanceFrequency(&fr);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 tm->QuadPart += (LONGLONG)((double)msec / 1000.0 * (double)fr.QuadPart);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
126 long fsec;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
128 PROF_GET_TIME(tm);
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
129 fsec = (long)tm->tv_fsec + (long)msec * (TV_FSEC_SEC / 1000);
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
130 tm->tv_fsec = fsec % (long)TV_FSEC_SEC;
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
131 tm->tv_sec += fsec / (long)TV_FSEC_SEC;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 * Return TRUE if the current time is past "tm".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 int
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 profile_passed_limit(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 proftime_T now;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 # ifdef MSWIN
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
145 if (tm->QuadPart == 0) // timer was not set
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 return FALSE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 QueryPerformanceCounter(&now);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 return (now.QuadPart > tm->QuadPart);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 # else
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
150 if (tm->tv_sec == 0) // timer was not set
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 return FALSE;
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
152 PROF_GET_TIME(&now);
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 return (now.tv_sec > tm->tv_sec
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
154 || (now.tv_sec == tm->tv_sec && now.tv_fsec > tm->tv_fsec));
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 * Set the time in "tm" to zero.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 profile_zero(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 tm->QuadPart = 0;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
167 tm->tv_fsec = 0;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 tm->tv_sec = 0;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
172 # endif // FEAT_PROFILE || FEAT_RELTIME
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 30124
diff changeset
174 #if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_PROFILE)
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 # if defined(HAVE_MATH_H)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 # include <math.h>
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 * Divide the time "tm" by "count" and store in "tm2".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 profile_divide(proftime_T *tm, int count, proftime_T *tm2)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 if (count == 0)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 profile_zero(tm2);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 tm2->QuadPart = tm->QuadPart / count;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
192 double fsec = (tm->tv_sec * (float_T)TV_FSEC_SEC + tm->tv_fsec)
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
193 / count;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
195 tm2->tv_sec = floor(fsec / (float_T)TV_FSEC_SEC);
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
196 tm2->tv_fsec = vim_round(fsec - (tm2->tv_sec * (float_T)TV_FSEC_SEC));
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 #endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 # if defined(FEAT_PROFILE) || defined(PROTO)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 * Functions for profiling.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 static proftime_T prof_wait_time;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 * Add the time "tm2" to "tm".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 profile_add(proftime_T *tm, proftime_T *tm2)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 tm->QuadPart += tm2->QuadPart;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
217 tm->tv_fsec += tm2->tv_fsec;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 tm->tv_sec += tm2->tv_sec;
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
219 if (tm->tv_fsec >= TV_FSEC_SEC)
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 {
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
221 tm->tv_fsec -= TV_FSEC_SEC;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 ++tm->tv_sec;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 * Add the "self" time from the total time and the children's time.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 profile_self(proftime_T *self, proftime_T *total, proftime_T *children)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 {
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
233 // Check that the result won't be negative. Can happen with recursive
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
234 // calls.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 #ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 if (total->QuadPart <= children->QuadPart)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 #else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 if (total->tv_sec < children->tv_sec
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 || (total->tv_sec == children->tv_sec
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
241 && total->tv_fsec <= children->tv_fsec))
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 #endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 profile_add(self, total);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 profile_sub(self, children);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 * Get the current waittime.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
251 static void
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 profile_get_wait(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 *tm = prof_wait_time;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 * Subtract the passed waittime since "tm" from "tma".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 profile_sub_wait(proftime_T *tm, proftime_T *tma)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 proftime_T tm3 = prof_wait_time;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 profile_sub(&tm3, tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 profile_sub(tma, &tm3);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 * Return TRUE if "tm1" and "tm2" are equal.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
272 static int
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 profile_equal(proftime_T *tm1, proftime_T *tm2)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 return (tm1->QuadPart == tm2->QuadPart);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 # else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
278 return (tm1->tv_fsec == tm2->tv_fsec && tm1->tv_sec == tm2->tv_sec);
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2"
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 int
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 profile_cmp(const proftime_T *tm1, const proftime_T *tm2)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 return (int)(tm2->QuadPart - tm1->QuadPart);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 # else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 if (tm1->tv_sec == tm2->tv_sec)
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
292 return tm2->tv_fsec - tm1->tv_fsec;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 return tm2->tv_sec - tm1->tv_sec;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 static char_u *profile_fname = NULL;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 static proftime_T pause_time;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 /*
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
301 * Reset all profiling information.
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
302 */
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
303 static void
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
304 profile_reset(void)
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
305 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
306 int id;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
307 int todo;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
308 hashtab_T *functbl;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
309 hashitem_T *hi;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
310
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
311 // Reset sourced files.
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
312 for (id = 1; id <= script_items.ga_len; id++)
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
313 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
314 scriptitem_T *si = SCRIPT_ITEM(id);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
315 if (si->sn_prof_on)
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
316 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
317 si->sn_prof_on = FALSE;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
318 si->sn_pr_force = FALSE;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
319 profile_zero(&si->sn_pr_child);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
320 si->sn_pr_nest = 0;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
321 si->sn_pr_count = 0;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
322 profile_zero(&si->sn_pr_total);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
323 profile_zero(&si->sn_pr_self);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
324 profile_zero(&si->sn_pr_start);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
325 profile_zero(&si->sn_pr_children);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
326 ga_clear(&si->sn_prl_ga);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
327 profile_zero(&si->sn_prl_start);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
328 profile_zero(&si->sn_prl_children);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
329 profile_zero(&si->sn_prl_wait);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
330 si->sn_prl_idx = -1;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
331 si->sn_prl_execed = 0;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
332 }
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
333 }
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
334
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
335 // Reset functions.
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
336 functbl = func_tbl_get();
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
337 todo = (int)functbl->ht_used;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
338
32118
04d9dff67d99 patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file
Bram Moolenaar <Bram@vim.org>
parents: 31778
diff changeset
339 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo)
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
340 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
341 ufunc_T *fp;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
342 int i;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
343
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
344 if (HASHITEM_EMPTY(hi))
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
345 continue;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
346
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
347 todo--;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
348 fp = HI2UF(hi);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
349 if (fp->uf_prof_initialized)
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
350 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
351 fp->uf_profiling = 0;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
352 fp->uf_prof_initialized = FALSE;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
353 fp->uf_tm_count = 0;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
354 profile_zero(&fp->uf_tm_total);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
355 profile_zero(&fp->uf_tm_self);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
356 profile_zero(&fp->uf_tm_children);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
357
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
358 for (i = 0; i < fp->uf_lines.ga_len; i++)
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
359 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
360 fp->uf_tml_count[i] = 0;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
361 profile_zero(&fp->uf_tml_total[i]);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
362 profile_zero(&fp->uf_tml_self[i]);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
363 }
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
364
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
365 profile_zero(&fp->uf_tml_start);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
366 profile_zero(&fp->uf_tml_children);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
367 profile_zero(&fp->uf_tml_wait);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
368 fp->uf_tml_idx = -1;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
369 fp->uf_tml_execed = 0;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
370 }
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
371 }
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
372
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
373 VIM_CLEAR(profile_fname);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
374 }
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
375
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
376 /*
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 * ":profile cmd args"
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 ex_profile(exarg_T *eap)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 char_u *e;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 int len;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 e = skiptowhite(eap->arg);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 len = (int)(e - eap->arg);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 e = skipwhite(e);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 {
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
391 VIM_CLEAR(profile_fname);
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 profile_fname = expand_env_save_opt(e, TRUE);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 do_profiling = PROF_YES;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 profile_zero(&prof_wait_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 set_vim_var_nr(VV_PROFILING, 1L);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 else if (do_profiling == PROF_NONE)
26958
d92e0d85923f patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
398 emsg(_(e_first_use_profile_start_fname));
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
399 else if (STRCMP(eap->arg, "stop") == 0)
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
400 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
401 profile_dump();
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
402 do_profiling = PROF_NONE;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
403 set_vim_var_nr(VV_PROFILING, 0L);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
404 profile_reset();
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
405 }
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 else if (STRCMP(eap->arg, "pause") == 0)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 if (do_profiling == PROF_YES)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 profile_start(&pause_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 do_profiling = PROF_PAUSED;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 else if (STRCMP(eap->arg, "continue") == 0)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 if (do_profiling == PROF_PAUSED)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 profile_end(&pause_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 profile_add(&prof_wait_time, &pause_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 do_profiling = PROF_YES;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 }
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
421 else if (STRCMP(eap->arg, "dump") == 0)
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
422 profile_dump();
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 {
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
425 // The rest is similar to ":breakadd".
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 ex_breakadd(eap);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
430 // Command line expansion for :profile.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 static enum
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 {
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
433 PEXP_SUBCMD, // expand :profile sub-commands
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
434 PEXP_FUNC // expand :profile func {funcname}
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 } pexpand_what;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 static char *pexpand_cmds[] = {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 "start",
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 #define PROFCMD_START 0
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
440 "stop",
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
441 #define PROFCMD_STOP 1
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 "pause",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
443 #define PROFCMD_PAUSE 2
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 "continue",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
445 #define PROFCMD_CONTINUE 3
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 "func",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
447 #define PROFCMD_FUNC 4
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 "file",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
449 #define PROFCMD_DUMP 5
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
450 "dump",
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
451 #define PROFCMD_FILE 6
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 NULL
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
453 #define PROFCMD_LAST 7
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 };
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 * Function given to ExpandGeneric() to obtain the profile command
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 * specific expansion.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 char_u *
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 get_profile_name(expand_T *xp UNUSED, int idx)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 switch (pexpand_what)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 case PEXP_SUBCMD:
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 return (char_u *)pexpand_cmds[idx];
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 default:
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 return NULL;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 * Handle command line completion for :profile command.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 set_context_in_profile_cmd(expand_T *xp, char_u *arg)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 char_u *end_subcmd;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
480 // Default: expand subcommands.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 xp->xp_context = EXPAND_PROFILE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 pexpand_what = PEXP_SUBCMD;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 xp->xp_pattern = arg;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 end_subcmd = skiptowhite(arg);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 if (*end_subcmd == NUL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488
28091
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
489 if ((end_subcmd - arg == 5 && STRNCMP(arg, "start", 5) == 0)
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
490 || (end_subcmd - arg == 4 && STRNCMP(arg, "file", 4) == 0))
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 xp->xp_context = EXPAND_FILES;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 xp->xp_pattern = skipwhite(end_subcmd);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 }
28091
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
496 else if (end_subcmd - arg == 4 && STRNCMP(arg, "func", 4) == 0)
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
497 {
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
498 xp->xp_context = EXPAND_USER_FUNC;
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
499 xp->xp_pattern = skipwhite(end_subcmd);
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
500 return;
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
501 }
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 xp->xp_context = EXPAND_NOTHING;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 static proftime_T inchar_time;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 * Called when starting to wait for the user to type a character.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 prof_inchar_enter(void)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 profile_start(&inchar_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 * Called when finished waiting for the user to type a character.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 prof_inchar_exit(void)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 profile_end(&inchar_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 profile_add(&prof_wait_time, &inchar_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 * Return TRUE when a function defined in the current script should be
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 * profiled.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 int
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 prof_def_func(void)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 if (current_sctx.sc_sid > 0)
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
536 return SCRIPT_ITEM(current_sctx.sc_sid)->sn_pr_force;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 return FALSE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
540 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
541 * Print the count and times for one function or function line.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
542 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
543 static void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
544 prof_func_line(
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
545 FILE *fd,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
546 int count,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
547 proftime_T *total,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
548 proftime_T *self,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
549 int prefer_self) // when equal print only self time
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
550 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
551 if (count > 0)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
552 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
553 fprintf(fd, "%5d ", count);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
554 if (prefer_self && profile_equal(total, self))
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
555 fprintf(fd, PROF_TIME_BLANK);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
556 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
557 fprintf(fd, "%s ", profile_msg(total));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
558 if (!prefer_self && profile_equal(total, self))
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
559 fprintf(fd, PROF_TIME_BLANK);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
560 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
561 fprintf(fd, "%s ", profile_msg(self));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
562 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
563 else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
564 fprintf(fd, " %s%s", PROF_TIME_BLANK, PROF_TIME_BLANK);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
565 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
566
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
567 static void
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 prof_sort_list(
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 FILE *fd,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 ufunc_T **sorttab,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 int st_len,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 char *title,
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
573 int prefer_self) // when equal print only self time
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 int i;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 ufunc_T *fp;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title);
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
579 fprintf(fd, "%s function\n", PROF_TOTALS_HEADER);
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 for (i = 0; i < 20 && i < st_len; ++i)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 fp = sorttab[i];
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 prof_func_line(fd, fp->uf_tm_count, &fp->uf_tm_total, &fp->uf_tm_self,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 prefer_self);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 if (fp->uf_name[0] == K_SPECIAL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 fprintf(fd, " <SNR>%s()\n", fp->uf_name + 3);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 fprintf(fd, " %s()\n", fp->uf_name);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 fprintf(fd, "\n");
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 * Compare function for total time sorting.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 */
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
596 static int
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 prof_total_cmp(const void *s1, const void *s2)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 ufunc_T *p1, *p2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 p1 = *(ufunc_T **)s1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 p2 = *(ufunc_T **)s2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 return profile_cmp(&p1->uf_tm_total, &p2->uf_tm_total);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 * Compare function for self time sorting.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 */
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
609 static int
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 prof_self_cmp(const void *s1, const void *s2)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 ufunc_T *p1, *p2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 p1 = *(ufunc_T **)s1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 p2 = *(ufunc_T **)s2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 return profile_cmp(&p1->uf_tm_self, &p2->uf_tm_self);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 * Start profiling function "fp".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 func_do_profile(ufunc_T *fp)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 int len = fp->uf_lines.ga_len;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 if (!fp->uf_prof_initialized)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 if (len == 0)
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
630 len = 1; // avoid getting error for allocating zero bytes
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 fp->uf_tm_count = 0;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 profile_zero(&fp->uf_tm_self);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 profile_zero(&fp->uf_tm_total);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 if (fp->uf_tml_count == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 fp->uf_tml_count = ALLOC_CLEAR_MULT(int, len);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 if (fp->uf_tml_total == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 fp->uf_tml_total = ALLOC_CLEAR_MULT(proftime_T, len);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 if (fp->uf_tml_self == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 fp->uf_tml_self = ALLOC_CLEAR_MULT(proftime_T, len);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 fp->uf_tml_idx = -1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 || fp->uf_tml_self == NULL)
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
643 return; // out of memory
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 fp->uf_prof_initialized = TRUE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 fp->uf_profiling = TRUE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 /*
25567
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
651 * Save time when starting to invoke another script or function.
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
652 */
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
653 static void
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
654 script_prof_save(
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
655 proftime_T *tm) // place to store wait time
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
656 {
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
657 scriptitem_T *si;
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
658
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
659 if (SCRIPT_ID_VALID(current_sctx.sc_sid))
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
660 {
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
661 si = SCRIPT_ITEM(current_sctx.sc_sid);
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
662 if (si->sn_prof_on && si->sn_pr_nest++ == 0)
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
663 profile_start(&si->sn_pr_child);
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
664 }
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
665 profile_get_wait(tm);
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
666 }
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
667
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
668 /*
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
669 * When calling a function: may initialize for profiling.
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
670 */
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
671 void
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
672 profile_may_start_func(profinfo_T *info, ufunc_T *fp, ufunc_T *caller)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
673 {
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
674 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
675 {
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
676 info->pi_started_profiling = TRUE;
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
677 func_do_profile(fp);
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
678 }
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
679 if (fp->uf_profiling || (caller != NULL && caller->uf_profiling))
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
680 {
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
681 ++fp->uf_tm_count;
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
682 profile_start(&info->pi_call_start);
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
683 profile_zero(&fp->uf_tm_children);
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
684 }
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
685 script_prof_save(&info->pi_wait_start);
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
686 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
687
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
688 /*
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
689 * After calling a function: may handle profiling. profile_may_start_func()
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
690 * must have been called previously.
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
691 */
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
692 void
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
693 profile_may_end_func(profinfo_T *info, ufunc_T *fp, ufunc_T *caller)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
694 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
695 profile_end(&info->pi_call_start);
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
696 profile_sub_wait(&info->pi_wait_start, &info->pi_call_start);
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
697 profile_add(&fp->uf_tm_total, &info->pi_call_start);
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
698 profile_self(&fp->uf_tm_self, &info->pi_call_start, &fp->uf_tm_children);
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
699 if (caller != NULL && caller->uf_profiling)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
700 {
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
701 profile_add(&caller->uf_tm_children, &info->pi_call_start);
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
702 profile_add(&caller->uf_tml_children, &info->pi_call_start);
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
703 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
704 if (info->pi_started_profiling)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
705 // make a ":profdel func" stop profiling the function
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
706 fp->uf_profiling = FALSE;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
707 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
708
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
709 /*
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 * Prepare profiling for entering a child or something else that is not
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 * counted for the script/function itself.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 * Should always be called in pair with prof_child_exit().
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 prof_child_enter(
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
716 proftime_T *tm) // place to store waittime
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 funccall_T *fc = get_current_funccal();
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719
30124
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
720 if (fc != NULL && fc->fc_func->uf_profiling)
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
721 profile_start(&fc->fc_prof_child);
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 script_prof_save(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 * Take care of time spent in a child.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 * Should always be called after prof_child_enter().
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 prof_child_exit(
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
731 proftime_T *tm) // where waittime was stored
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 funccall_T *fc = get_current_funccal();
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734
30124
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
735 if (fc != NULL && fc->fc_func->uf_profiling)
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 {
30124
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
737 profile_end(&fc->fc_prof_child);
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
738 profile_sub_wait(tm, &fc->fc_prof_child); // don't count waiting time
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
739 profile_add(&fc->fc_func->uf_tm_children, &fc->fc_prof_child);
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
740 profile_add(&fc->fc_func->uf_tml_children, &fc->fc_prof_child);
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 script_prof_restore(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 * Called when starting to read a function line.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 * "sourcing_lnum" must be correct!
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 * When skipping lines it may not actually be executed, but we won't find out
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 * until later and we need to store the time now.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 void
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
752 func_line_start(void *cookie, long lnum)
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 funccall_T *fcp = (funccall_T *)cookie;
30124
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
755 ufunc_T *fp = fcp->fc_func;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
757 if (fp->uf_profiling && lnum >= 1 && lnum <= fp->uf_lines.ga_len)
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 {
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
759 fp->uf_tml_idx = lnum - 1;
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
760 // Skip continuation lines.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 while (fp->uf_tml_idx > 0 && FUNCLINE(fp, fp->uf_tml_idx) == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 --fp->uf_tml_idx;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 fp->uf_tml_execed = FALSE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 profile_start(&fp->uf_tml_start);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 profile_zero(&fp->uf_tml_children);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 profile_get_wait(&fp->uf_tml_wait);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 * Called when actually executing a function line.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 func_line_exec(void *cookie)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 funccall_T *fcp = (funccall_T *)cookie;
30124
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
777 ufunc_T *fp = fcp->fc_func;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 if (fp->uf_profiling && fp->uf_tml_idx >= 0)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 fp->uf_tml_execed = TRUE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 * Called when done with a function line.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 func_line_end(void *cookie)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 funccall_T *fcp = (funccall_T *)cookie;
30124
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
790 ufunc_T *fp = fcp->fc_func;
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 if (fp->uf_profiling && fp->uf_tml_idx >= 0)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 if (fp->uf_tml_execed)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 ++fp->uf_tml_count[fp->uf_tml_idx];
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 profile_end(&fp->uf_tml_start);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 profile_sub_wait(&fp->uf_tml_wait, &fp->uf_tml_start);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 profile_add(&fp->uf_tml_total[fp->uf_tml_idx], &fp->uf_tml_start);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 profile_self(&fp->uf_tml_self[fp->uf_tml_idx], &fp->uf_tml_start,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 &fp->uf_tml_children);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 fp->uf_tml_idx = -1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 }
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
806
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
807 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
808 * Dump the profiling results for all functions in file "fd".
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
809 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
810 static void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
811 func_dump_profile(FILE *fd)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
812 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
813 hashtab_T *functbl;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
814 hashitem_T *hi;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
815 int todo;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
816 ufunc_T *fp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
817 int i;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
818 ufunc_T **sorttab;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
819 int st_len = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
820 char_u *p;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
821
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
822 functbl = func_tbl_get();
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
823 todo = (int)functbl->ht_used;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
824 if (todo == 0)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
825 return; // nothing to dump
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
826
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
827 sorttab = ALLOC_MULT(ufunc_T *, todo);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
828
32118
04d9dff67d99 patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file
Bram Moolenaar <Bram@vim.org>
parents: 31778
diff changeset
829 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo)
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
830 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
831 if (!HASHITEM_EMPTY(hi))
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
832 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
833 --todo;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
834 fp = HI2UF(hi);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
835 if (fp->uf_prof_initialized)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
836 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
837 if (sorttab != NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
838 sorttab[st_len++] = fp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
839
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
840 if (fp->uf_name[0] == K_SPECIAL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
841 fprintf(fd, "FUNCTION <SNR>%s()\n", fp->uf_name + 3);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
842 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
843 fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
17899
48fd0712dad8 patch 8.1.1946: memory error when profiling a function without a script ID
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
844 if (fp->uf_script_ctx.sc_sid > 0)
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
845 {
17899
48fd0712dad8 patch 8.1.1946: memory error when profiling a function without a script ID
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
846 p = home_replace_save(NULL,
48fd0712dad8 patch 8.1.1946: memory error when profiling a function without a script ID
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
847 get_scriptname(fp->uf_script_ctx.sc_sid));
48fd0712dad8 patch 8.1.1946: memory error when profiling a function without a script ID
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
848 if (p != NULL)
48fd0712dad8 patch 8.1.1946: memory error when profiling a function without a script ID
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
849 {
18120
ed222e264905 patch 8.1.2055: not easy to jump to function line from profile
Bram Moolenaar <Bram@vim.org>
parents: 17899
diff changeset
850 fprintf(fd, " Defined: %s:%ld\n",
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
851 p, (long)fp->uf_script_ctx.sc_lnum);
17899
48fd0712dad8 patch 8.1.1946: memory error when profiling a function without a script ID
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
852 vim_free(p);
48fd0712dad8 patch 8.1.1946: memory error when profiling a function without a script ID
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
853 }
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
854 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
855 if (fp->uf_tm_count == 1)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
856 fprintf(fd, "Called 1 time\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
857 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
858 fprintf(fd, "Called %d times\n", fp->uf_tm_count);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
859 fprintf(fd, "Total time: %s\n", profile_msg(&fp->uf_tm_total));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
860 fprintf(fd, " Self time: %s\n", profile_msg(&fp->uf_tm_self));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
861 fprintf(fd, "\n");
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
862 fprintf(fd, "%s\n", PROF_TOTALS_HEADER);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
863
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
864 for (i = 0; i < fp->uf_lines.ga_len; ++i)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
865 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
866 if (FUNCLINE(fp, i) == NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
867 continue;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
868 prof_func_line(fd, fp->uf_tml_count[i],
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
869 &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
870 fprintf(fd, "%s\n", FUNCLINE(fp, i));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
871 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
872 fprintf(fd, "\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
873 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
874 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
875 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
876
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
877 if (sorttab != NULL && st_len > 0)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
878 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
879 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
880 prof_total_cmp);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
881 prof_sort_list(fd, sorttab, st_len, "TOTAL", FALSE);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
882 qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
883 prof_self_cmp);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
884 prof_sort_list(fd, sorttab, st_len, "SELF", TRUE);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
885 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
886
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
887 vim_free(sorttab);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
888 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
889
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
890 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
891 * Start profiling script "fp".
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
892 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
893 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
894 script_do_profile(scriptitem_T *si)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
895 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
896 si->sn_pr_count = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
897 profile_zero(&si->sn_pr_total);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
898 profile_zero(&si->sn_pr_self);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
899
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
900 ga_init2(&si->sn_prl_ga, sizeof(sn_prl_T), 100);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
901 si->sn_prl_idx = -1;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
902 si->sn_prof_on = TRUE;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
903 si->sn_pr_nest = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
904 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
905
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
906 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
907 * Count time spent in children after invoking another script or function.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
908 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
909 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
910 script_prof_restore(proftime_T *tm)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
911 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
912 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
913
31778
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
914 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
915 return;
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
916
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
917 si = SCRIPT_ITEM(current_sctx.sc_sid);
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
918 if (si->sn_prof_on && --si->sn_pr_nest == 0)
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
919 {
31778
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
920 profile_end(&si->sn_pr_child);
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
921 profile_sub_wait(tm, &si->sn_pr_child); // don't count wait time
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
922 profile_add(&si->sn_pr_children, &si->sn_pr_child);
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
923 profile_add(&si->sn_prl_children, &si->sn_pr_child);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
924 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
925 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
926
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
927 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
928 * Dump the profiling results for all scripts in file "fd".
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
929 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
930 static void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
931 script_dump_profile(FILE *fd)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
932 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
933 int id;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
934 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
935 int i;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
936 FILE *sfd;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
937 sn_prl_T *pp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
938
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
939 for (id = 1; id <= script_items.ga_len; ++id)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
940 {
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
941 si = SCRIPT_ITEM(id);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
942 if (si->sn_prof_on)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
943 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
944 fprintf(fd, "SCRIPT %s\n", si->sn_name);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
945 if (si->sn_pr_count == 1)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
946 fprintf(fd, "Sourced 1 time\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
947 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
948 fprintf(fd, "Sourced %d times\n", si->sn_pr_count);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
949 fprintf(fd, "Total time: %s\n", profile_msg(&si->sn_pr_total));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
950 fprintf(fd, " Self time: %s\n", profile_msg(&si->sn_pr_self));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
951 fprintf(fd, "\n");
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
952 fprintf(fd, "%s\n", PROF_TOTALS_HEADER);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
953
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
954 sfd = mch_fopen((char *)si->sn_name, "r");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
955 if (sfd == NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
956 fprintf(fd, "Cannot open file!\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
957 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
958 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
959 // Keep going till the end of file, so that trailing
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
960 // continuation lines are listed.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
961 for (i = 0; ; ++i)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
962 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
963 if (vim_fgets(IObuff, IOSIZE, sfd))
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
964 break;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
965 // When a line has been truncated, append NL, taking care
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
966 // of multi-byte characters .
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
967 if (IObuff[IOSIZE - 2] != NUL && IObuff[IOSIZE - 2] != NL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
968 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
969 int n = IOSIZE - 2;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
970
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
971 if (enc_utf8)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
972 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
973 // Move to the first byte of this char.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
974 // utf_head_off() doesn't work, because it checks
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
975 // for a truncated character.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
976 while (n > 0 && (IObuff[n] & 0xc0) == 0x80)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
977 --n;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
978 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
979 else if (has_mbyte)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
980 n -= mb_head_off(IObuff, IObuff + n);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
981 IObuff[n] = NL;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
982 IObuff[n + 1] = NUL;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
983 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
984 if (i < si->sn_prl_ga.ga_len
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
985 && (pp = &PRL_ITEM(si, i))->snp_count > 0)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
986 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
987 fprintf(fd, "%5d ", pp->snp_count);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
988 if (profile_equal(&pp->sn_prl_total, &pp->sn_prl_self))
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
989 fprintf(fd, " ");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
990 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
991 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
992 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_self));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
993 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
994 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
995 fprintf(fd, " ");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
996 fprintf(fd, "%s", IObuff);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
997 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
998 fclose(sfd);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
999 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1000 fprintf(fd, "\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1001 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1002 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1003 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1004
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1005 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1006 * Dump the profiling info.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1007 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1008 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1009 profile_dump(void)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1010 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1011 FILE *fd;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1012
31778
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1013 if (profile_fname == NULL)
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1014 return;
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1015
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1016 fd = mch_fopen((char *)profile_fname, "w");
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1017 if (fd == NULL)
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1018 semsg(_(e_cant_open_file_str), profile_fname);
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1019 else
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1020 {
31778
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1021 script_dump_profile(fd);
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1022 func_dump_profile(fd);
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1023 fclose(fd);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1024 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1025 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1026
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1027 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1028 * Called when starting to read a script line.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1029 * "sourcing_lnum" must be correct!
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1030 * When skipping lines it may not actually be executed, but we won't find out
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1031 * until later and we need to store the time now.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1032 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1033 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1034 script_line_start(void)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1035 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1036 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1037 sn_prl_T *pp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1038
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
1039 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1040 return;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1041 si = SCRIPT_ITEM(current_sctx.sc_sid);
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18120
diff changeset
1042 if (si->sn_prof_on && SOURCING_LNUM >= 1)
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1043 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1044 // Grow the array before starting the timer, so that the time spent
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1045 // here isn't counted.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1046 (void)ga_grow(&si->sn_prl_ga,
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18120
diff changeset
1047 (int)(SOURCING_LNUM - si->sn_prl_ga.ga_len));
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18120
diff changeset
1048 si->sn_prl_idx = SOURCING_LNUM - 1;
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1049 while (si->sn_prl_ga.ga_len <= si->sn_prl_idx
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1050 && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1051 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1052 // Zero counters for a line that was not used before.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1053 pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1054 pp->snp_count = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1055 profile_zero(&pp->sn_prl_total);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1056 profile_zero(&pp->sn_prl_self);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1057 ++si->sn_prl_ga.ga_len;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1058 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1059 si->sn_prl_execed = FALSE;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1060 profile_start(&si->sn_prl_start);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1061 profile_zero(&si->sn_prl_children);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1062 profile_get_wait(&si->sn_prl_wait);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1063 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1064 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1065
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1066 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1067 * Called when actually executing a function line.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1068 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1069 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1070 script_line_exec(void)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1071 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1072 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1073
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
1074 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1075 return;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1076 si = SCRIPT_ITEM(current_sctx.sc_sid);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1077 if (si->sn_prof_on && si->sn_prl_idx >= 0)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1078 si->sn_prl_execed = TRUE;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1079 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1080
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1081 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1082 * Called when done with a script line.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1083 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1084 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1085 script_line_end(void)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1086 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1087 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1088 sn_prl_T *pp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1089
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
1090 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1091 return;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1092 si = SCRIPT_ITEM(current_sctx.sc_sid);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1093 if (si->sn_prof_on && si->sn_prl_idx >= 0
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1094 && si->sn_prl_idx < si->sn_prl_ga.ga_len)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1095 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1096 if (si->sn_prl_execed)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1097 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1098 pp = &PRL_ITEM(si, si->sn_prl_idx);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1099 ++pp->snp_count;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1100 profile_end(&si->sn_prl_start);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1101 profile_sub_wait(&si->sn_prl_wait, &si->sn_prl_start);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1102 profile_add(&pp->sn_prl_total, &si->sn_prl_start);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1103 profile_self(&pp->sn_prl_self, &si->sn_prl_start,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1104 &si->sn_prl_children);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1105 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1106 si->sn_prl_idx = -1;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1107 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1108 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1109 # endif // FEAT_PROFILE
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 #endif