annotate src/profiler.c @ 32396:9feee1b0b58a

Added tag v9.0.1529 for changeset 2ed95122d59c114dceacb2f811a92522c8de3c11
author Bram Moolenaar <Bram@vim.org>
date Tue, 09 May 2023 16:15:07 +0200
parents 6cfad8cc5f1d
children d863a33cb220
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",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
439 "stop",
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 "pause",
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 "continue",
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 "func",
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 "file",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
444 "dump",
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 NULL
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 };
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 * 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
450 * specific expansion.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 char_u *
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 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
454 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 switch (pexpand_what)
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 case PEXP_SUBCMD:
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 return (char_u *)pexpand_cmds[idx];
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 default:
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 return NULL;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 }
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
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 * 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
466 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 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
469 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 char_u *end_subcmd;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
472 // Default: expand subcommands.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 xp->xp_context = EXPAND_PROFILE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 pexpand_what = PEXP_SUBCMD;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 xp->xp_pattern = arg;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 end_subcmd = skiptowhite(arg);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 if (*end_subcmd == NUL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480
28091
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
481 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
482 || (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
483 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 xp->xp_context = EXPAND_FILES;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 xp->xp_pattern = skipwhite(end_subcmd);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 }
28091
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
488 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
489 {
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
490 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
491 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
492 return;
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
493 }
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 xp->xp_context = EXPAND_NOTHING;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 static proftime_T inchar_time;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 * 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
502 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 prof_inchar_enter(void)
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 profile_start(&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 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 * 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
511 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 prof_inchar_exit(void)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 profile_end(&inchar_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 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
517 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518
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 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 * 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
522 * profiled.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 int
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 prof_def_func(void)
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 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
528 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
529 return FALSE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
532 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
533 * 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
534 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
535 static void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
536 prof_func_line(
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
537 FILE *fd,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
538 int count,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
539 proftime_T *total,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
540 proftime_T *self,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
541 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
542 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
543 if (count > 0)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
544 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
545 fprintf(fd, "%5d ", count);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
546 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
547 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
548 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
549 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
550 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
551 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
552 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
553 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
554 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
555 else
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
556 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
557 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
558
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
559 static void
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 prof_sort_list(
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 FILE *fd,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 ufunc_T **sorttab,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 int st_len,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 char *title,
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
565 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
566 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 int i;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 ufunc_T *fp;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 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
571 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
572 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
573 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 fp = sorttab[i];
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 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
576 prefer_self);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 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
578 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
579 else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 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
581 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 fprintf(fd, "\n");
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 * Compare function for total time sorting.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 */
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
588 static int
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 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
590 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 ufunc_T *p1, *p2;
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 p1 = *(ufunc_T **)s1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 p2 = *(ufunc_T **)s2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 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
596 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597
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 * Compare function for self time sorting.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 */
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
601 static int
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 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
603 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 ufunc_T *p1, *p2;
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 p1 = *(ufunc_T **)s1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 p2 = *(ufunc_T **)s2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 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
609 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610
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 * Start profiling function "fp".
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 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 func_do_profile(ufunc_T *fp)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 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
618
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 if (!fp->uf_prof_initialized)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 if (len == 0)
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
622 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
623 fp->uf_tm_count = 0;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 profile_zero(&fp->uf_tm_self);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 profile_zero(&fp->uf_tm_total);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 if (fp->uf_tml_count == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 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
628 if (fp->uf_tml_total == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 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
630 if (fp->uf_tml_self == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 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
632 fp->uf_tml_idx = -1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 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
634 || 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
635 return; // out of memory
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 fp->uf_prof_initialized = TRUE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 fp->uf_profiling = TRUE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 /*
25567
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
643 * 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
644 */
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
645 static void
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
646 script_prof_save(
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
647 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
648 {
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
649 scriptitem_T *si;
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
650
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
651 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
652 {
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
653 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
654 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
655 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
656 }
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
657 profile_get_wait(tm);
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
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
660 /*
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
661 * 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
662 */
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
663 void
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
664 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
665 {
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
666 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
667 {
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
668 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
669 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
670 }
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
671 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
672 {
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
673 ++fp->uf_tm_count;
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
674 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
675 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
676 }
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
677 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
678 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
679
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
680 /*
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
681 * 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
682 * 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
683 */
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
684 void
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
685 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
686 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
687 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
688 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
689 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
690 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
691 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
692 {
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
693 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
694 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
695 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
696 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
697 // 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
698 fp->uf_profiling = FALSE;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
699 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
700
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
701 /*
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 * 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
703 * counted for the script/function itself.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 * 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
705 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 prof_child_enter(
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
708 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
709 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 funccall_T *fc = get_current_funccal();
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711
30124
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
712 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
713 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
714 script_prof_save(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716
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 * 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
719 * 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
720 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 prof_child_exit(
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
723 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
724 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 funccall_T *fc = get_current_funccal();
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726
30124
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
727 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
728 {
30124
9874afdacb5f patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents: 28373
diff changeset
729 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
730 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
731 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
732 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
733 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 script_prof_restore(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 * 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
739 * "sourcing_lnum" must be correct!
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 * 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
741 * 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
742 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 void
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
744 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
745 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 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
747 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
748
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
749 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
750 {
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
751 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
752 // Skip continuation lines.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 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
754 --fp->uf_tml_idx;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 fp->uf_tml_execed = FALSE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 profile_start(&fp->uf_tml_start);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 profile_zero(&fp->uf_tml_children);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 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
759 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 * 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
764 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 func_line_exec(void *cookie)
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 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
769 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
770
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 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
772 fp->uf_tml_execed = TRUE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774
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 * 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
777 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 func_line_end(void *cookie)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 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
782 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
783
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 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
785 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 if (fp->uf_tml_execed)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 ++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
789 profile_end(&fp->uf_tml_start);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 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
791 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
792 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
793 &fp->uf_tml_children);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 fp->uf_tml_idx = -1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 }
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
798
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
799 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
800 * 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
801 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
802 static void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
803 func_dump_profile(FILE *fd)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
804 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
805 hashtab_T *functbl;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
806 hashitem_T *hi;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
807 int todo;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
808 ufunc_T *fp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
809 int i;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
810 ufunc_T **sorttab;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
811 int st_len = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
812 char_u *p;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
813
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
814 functbl = func_tbl_get();
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
815 todo = (int)functbl->ht_used;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
816 if (todo == 0)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
817 return; // nothing to dump
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
818
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
819 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
820
32118
04d9dff67d99 patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file
Bram Moolenaar <Bram@vim.org>
parents: 31778
diff changeset
821 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
822 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
823 if (!HASHITEM_EMPTY(hi))
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
824 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
825 --todo;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
826 fp = HI2UF(hi);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
827 if (fp->uf_prof_initialized)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
828 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
829 if (sorttab != NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
830 sorttab[st_len++] = fp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
831
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
832 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
833 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
834 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
835 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
836 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
837 {
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
838 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
839 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
840 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
841 {
18120
ed222e264905 patch 8.1.2055: not easy to jump to function line from profile
Bram Moolenaar <Bram@vim.org>
parents: 17899
diff changeset
842 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
843 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
844 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
845 }
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
846 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
847 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
848 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
849 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
850 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
851 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
852 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
853 fprintf(fd, "\n");
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
854 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
855
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
856 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
857 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
858 if (FUNCLINE(fp, i) == NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
859 continue;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
860 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
861 &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
862 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
863 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
864 fprintf(fd, "\n");
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 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
867 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
868
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
869 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
870 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
871 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
872 prof_total_cmp);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
873 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
874 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
875 prof_self_cmp);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
876 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
877 }
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 vim_free(sorttab);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
880 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
881
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
882 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
883 * Start profiling script "fp".
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
884 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
885 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
886 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
887 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
888 si->sn_pr_count = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
889 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
890 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
891
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
892 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
893 si->sn_prl_idx = -1;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
894 si->sn_prof_on = TRUE;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
895 si->sn_pr_nest = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
896 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
897
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
898 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
899 * 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
900 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
901 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
902 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
903 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
904 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
905
31778
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
906 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
907 return;
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
908
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
909 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
910 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
911 {
31778
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
912 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
913 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
914 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
915 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
916 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
917 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
918
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
919 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
920 * 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
921 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
922 static void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
923 script_dump_profile(FILE *fd)
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 int id;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
926 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
927 int i;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
928 FILE *sfd;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
929 sn_prl_T *pp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
930
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
931 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
932 {
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
933 si = SCRIPT_ITEM(id);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
934 if (si->sn_prof_on)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
935 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
936 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
937 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
938 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
939 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
940 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
941 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
942 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
943 fprintf(fd, "\n");
32160
98774a275d6d patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents: 32118
diff changeset
944 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
945
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
946 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
947 if (sfd == NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
948 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
949 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
950 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
951 // 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
952 // continuation lines are listed.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
953 for (i = 0; ; ++i)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
954 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
955 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
956 break;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
957 // 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
958 // of multi-byte characters .
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
959 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
960 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
961 int n = IOSIZE - 2;
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 (enc_utf8)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
964 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
965 // 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
966 // 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
967 // for a truncated character.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
968 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
969 --n;
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 else if (has_mbyte)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
972 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
973 IObuff[n] = NL;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
974 IObuff[n + 1] = NUL;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
975 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
976 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
977 && (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
978 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
979 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
980 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
981 fprintf(fd, " ");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
982 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
983 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
984 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
985 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
986 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
987 fprintf(fd, " ");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
988 fprintf(fd, "%s", IObuff);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
989 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
990 fclose(sfd);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
991 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
992 fprintf(fd, "\n");
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 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
995 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
996
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 * Dump the profiling info.
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 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1001 profile_dump(void)
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 FILE *fd;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1004
31778
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1005 if (profile_fname == NULL)
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1006 return;
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1007
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1008 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
1009 if (fd == NULL)
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1010 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
1011 else
17381
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 script_dump_profile(fd);
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1014 func_dump_profile(fd);
579c846086eb patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
1015 fclose(fd);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1016 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1017 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1018
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1019 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1020 * 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
1021 * "sourcing_lnum" must be correct!
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1022 * 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
1023 * 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
1024 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1025 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1026 script_line_start(void)
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 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1029 sn_prl_T *pp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1030
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
1031 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
1032 return;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1033 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
1034 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
1035 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1036 // 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
1037 // here isn't counted.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1038 (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
1039 (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
1040 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
1041 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
1042 && 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
1043 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1044 // 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
1045 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
1046 pp->snp_count = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1047 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
1048 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
1049 ++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
1050 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1051 si->sn_prl_execed = FALSE;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1052 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
1053 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
1054 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
1055 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1056 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1057
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 * 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
1060 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1061 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1062 script_line_exec(void)
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 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1065
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
1066 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
1067 return;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1068 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
1069 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
1070 si->sn_prl_execed = TRUE;
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
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1073 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1074 * 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
1075 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1076 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1077 script_line_end(void)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1078 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1079 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1080 sn_prl_T *pp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1081
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
1082 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
1083 return;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1084 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
1085 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
1086 && 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
1087 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1088 if (si->sn_prl_execed)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1089 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1090 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
1091 ++pp->snp_count;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1092 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
1093 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
1094 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
1095 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
1096 &si->sn_prl_children);
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 si->sn_prl_idx = -1;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1099 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1100 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1101 # endif // FEAT_PROFILE
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 #endif