annotate src/profiler.c @ 29234:96ff6c230a66 v8.2.5136

patch 8.2.5136: debugger test fails when run with valgrind Commit: https://github.com/vim/vim/commit/e366ed4f2c6fa8cb663f1b9599b39d57ddbd8a2a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 19 20:13:56 2022 +0100 patch 8.2.5136: debugger test fails when run with valgrind Problem: Debugger test fails when run with valgrind. Solution: Wait longer when using valgrind.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Jun 2022 21:15:03 +0200
parents 2ddf8aa1252c
children 9874afdacb5f
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
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 gettimeofday(tm, NULL);
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
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 gettimeofday(&now, NULL);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 tm->tv_usec = now.tv_usec - tm->tv_usec;
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;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 if (tm->tv_usec < 0)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 tm->tv_usec += 1000000;
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
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 tm->tv_usec -= tm2->tv_usec;
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;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 if (tm->tv_usec < 0)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 tm->tv_usec += 1000000;
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
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 sprintf(buf, "%3ld.%06ld", (long)tm->tv_sec, (long)tm->tv_usec);
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 # if defined(FEAT_FLOAT) || defined(PROTO)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 * 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
96 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 float_T
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 profile_float(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 LARGE_INTEGER fr;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 QueryPerformanceFrequency(&fr);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 return (float_T)tm->QuadPart / (float_T)fr.QuadPart;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 # else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 return (float_T)tm->tv_sec + (float_T)tm->tv_usec / 1000000.0;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 # endif
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 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110
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 * 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
113 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 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
116 {
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
117 if (msec <= 0) // no limit
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 profile_zero(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 LARGE_INTEGER fr;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 QueryPerformanceCounter(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 QueryPerformanceFrequency(&fr);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 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
127 # else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 long usec;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 gettimeofday(tm, NULL);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 usec = (long)tm->tv_usec + (long)msec * 1000;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 tm->tv_usec = usec % 1000000L;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 tm->tv_sec += usec / 1000000L;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 # endif
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
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 * 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
140 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 int
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 profile_passed_limit(proftime_T *tm)
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 proftime_T now;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 # ifdef MSWIN
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
147 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
148 return FALSE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 QueryPerformanceCounter(&now);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 return (now.QuadPart > tm->QuadPart);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 # else
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
152 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
153 return FALSE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 gettimeofday(&now, NULL);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 return (now.tv_sec > tm->tv_sec
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 || (now.tv_sec == tm->tv_sec && now.tv_usec > tm->tv_usec));
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 # endif
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
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 * 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
162 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 profile_zero(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 tm->QuadPart = 0;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 # else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 tm->tv_usec = 0;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 tm->tv_sec = 0;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
174 # endif // FEAT_PROFILE || FEAT_RELTIME
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 #if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_FLOAT) && defined(FEAT_PROFILE)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 # if defined(HAVE_MATH_H)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 # include <math.h>
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 # endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180
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 * 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
183 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 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
186 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 if (count == 0)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 profile_zero(tm2);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 tm2->QuadPart = tm->QuadPart / count;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 # else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 double usec = (tm->tv_sec * 1000000.0 + tm->tv_usec) / count;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 tm2->tv_sec = floor(usec / 1000000.0);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 tm2->tv_usec = vim_round(usec - (tm2->tv_sec * 1000000.0));
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 # endif
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 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 #endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 # if defined(FEAT_PROFILE) || defined(PROTO)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 * Functions for profiling.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 static proftime_T prof_wait_time;
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 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 * Add the time "tm2" to "tm".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 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
214 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 tm->QuadPart += tm2->QuadPart;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 # else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 tm->tv_usec += tm2->tv_usec;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 tm->tv_sec += tm2->tv_sec;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 if (tm->tv_usec >= 1000000)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 tm->tv_usec -= 1000000;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 ++tm->tv_sec;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 # endif
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 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 * 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
230 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 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
233 {
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
234 // 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
235 // calls.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 #ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 if (total->QuadPart <= children->QuadPart)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 #else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 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
241 || (total->tv_sec == children->tv_sec
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 && total->tv_usec <= children->tv_usec))
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 #endif
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 profile_add(self, total);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 profile_sub(self, children);
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 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 * Get the current waittime.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
252 static void
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 profile_get_wait(proftime_T *tm)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 *tm = prof_wait_time;
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 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 * 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
260 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 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
263 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 proftime_T tm3 = prof_wait_time;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 profile_sub(&tm3, tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 profile_sub(tma, &tm3);
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 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 * 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
272 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
273 static int
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 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
275 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 return (tm1->QuadPart == tm2->QuadPart);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 # else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 return (tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 # endif
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 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 * 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
285 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 int
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 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
288 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 # ifdef MSWIN
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 return (int)(tm2->QuadPart - tm1->QuadPart);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 # else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 if (tm1->tv_sec == tm2->tv_sec)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 return tm2->tv_usec - tm1->tv_usec;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 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
295 # endif
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
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 static char_u *profile_fname = NULL;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 static proftime_T pause_time;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 /*
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
302 * Reset all profiling information.
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
303 */
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
304 static void
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
305 profile_reset(void)
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
306 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
307 int id;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
308 int todo;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
309 hashtab_T *functbl;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
310 hashitem_T *hi;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
311
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
312 // Reset sourced files.
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
313 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
314 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
315 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
316 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
317 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
318 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 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
331 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
332 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
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
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
336 // Reset functions.
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
337 functbl = func_tbl_get();
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
338 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
339
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
340 for (hi = functbl->ht_array; todo > 0; ++hi)
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
341 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
342 ufunc_T *fp;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
343 int i;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
344
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
345 if (HASHITEM_EMPTY(hi))
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
346 continue;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
347
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
348 todo--;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
349 fp = HI2UF(hi);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
350 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
351 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
352 fp->uf_profiling = 0;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
353 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
354 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
355 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
356 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
357 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
358
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
359 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
360 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
361 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
362 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
363 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
364 }
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
365
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_start);
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_children);
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
368 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
369 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
370 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
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
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
374 VIM_CLEAR(profile_fname);
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
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
377 /*
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 * ":profile cmd args"
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 ex_profile(exarg_T *eap)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 char_u *e;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 int len;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 e = skiptowhite(eap->arg);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 len = (int)(e - eap->arg);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 e = skipwhite(e);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 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
391 {
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
392 VIM_CLEAR(profile_fname);
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 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
394 do_profiling = PROF_YES;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 profile_zero(&prof_wait_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 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
397 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 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
399 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
400 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
401 {
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
402 profile_dump();
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
403 do_profiling = PROF_NONE;
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
404 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
405 profile_reset();
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
406 }
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 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
408 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 if (do_profiling == PROF_YES)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 profile_start(&pause_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 do_profiling = PROF_PAUSED;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 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
414 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 if (do_profiling == PROF_PAUSED)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 profile_end(&pause_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 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
419 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 do_profiling = PROF_YES;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 }
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
422 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
423 profile_dump();
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 {
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
426 // 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
427 ex_breakadd(eap);
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 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
431 // Command line expansion for :profile.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 static enum
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 {
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
434 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
435 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
436 } pexpand_what;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 static char *pexpand_cmds[] = {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 "start",
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 #define PROFCMD_START 0
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
441 "stop",
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
442 #define PROFCMD_STOP 1
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 "pause",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
444 #define PROFCMD_PAUSE 2
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 "continue",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
446 #define PROFCMD_CONTINUE 3
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 "func",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
448 #define PROFCMD_FUNC 4
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 "file",
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
450 #define PROFCMD_DUMP 5
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
451 "dump",
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
452 #define PROFCMD_FILE 6
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 NULL
28373
2ddf8aa1252c patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents: 28091
diff changeset
454 #define PROFCMD_LAST 7
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 };
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 * 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
459 * specific expansion.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 char_u *
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 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
463 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 switch (pexpand_what)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 case PEXP_SUBCMD:
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 return (char_u *)pexpand_cmds[idx];
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 default:
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 return NULL;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 * 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
475 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 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
478 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 char_u *end_subcmd;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
481 // Default: expand subcommands.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 xp->xp_context = EXPAND_PROFILE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 pexpand_what = PEXP_SUBCMD;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 xp->xp_pattern = arg;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 end_subcmd = skiptowhite(arg);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 if (*end_subcmd == NUL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489
28091
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
490 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
491 || (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
492 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 xp->xp_context = EXPAND_FILES;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 xp->xp_pattern = skipwhite(end_subcmd);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 return;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 }
28091
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
497 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
498 {
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
499 xp->xp_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
500 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
501 return;
554f493902ea patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
502 }
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 xp->xp_context = EXPAND_NOTHING;
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
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 static proftime_T inchar_time;
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 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
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_enter(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_start(&inchar_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 * 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
520 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 prof_inchar_exit(void)
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 profile_end(&inchar_time);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 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
526 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 * 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
531 * profiled.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 int
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 prof_def_func(void)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 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
537 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
538 return FALSE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
541 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
542 * 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
543 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
544 static void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
545 prof_func_line(
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
546 FILE *fd,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
547 int count,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
548 proftime_T *total,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
549 proftime_T *self,
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
550 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
551 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
552 if (count > 0)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
553 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
554 fprintf(fd, "%5d ", count);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
555 if (prefer_self && profile_equal(total, self))
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
556 fprintf(fd, " ");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
557 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
558 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
559 if (!prefer_self && profile_equal(total, self))
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
560 fprintf(fd, " ");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
561 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
562 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
563 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
564 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
565 fprintf(fd, " ");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
566 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
567
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
568 static void
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 prof_sort_list(
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 FILE *fd,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 ufunc_T **sorttab,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 int st_len,
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 char *title,
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
574 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
575 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 int i;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 ufunc_T *fp;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 fprintf(fd, "count total (s) self (s) function\n");
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 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
582 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 fp = sorttab[i];
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 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
585 prefer_self);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 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
587 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
588 else
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 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
590 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 fprintf(fd, "\n");
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 * Compare function for total time sorting.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 */
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
597 static int
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 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
599 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 ufunc_T *p1, *p2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 p1 = *(ufunc_T **)s1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 p2 = *(ufunc_T **)s2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 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
605 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 * Compare function for self time sorting.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 */
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
610 static int
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 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
612 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 ufunc_T *p1, *p2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 p1 = *(ufunc_T **)s1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 p2 = *(ufunc_T **)s2;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 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
618 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 * Start profiling function "fp".
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 func_do_profile(ufunc_T *fp)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 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
627
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 if (!fp->uf_prof_initialized)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 if (len == 0)
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
631 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
632 fp->uf_tm_count = 0;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 profile_zero(&fp->uf_tm_self);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 profile_zero(&fp->uf_tm_total);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 if (fp->uf_tml_count == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 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
637 if (fp->uf_tml_total == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 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
639 if (fp->uf_tml_self == NULL)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 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
641 fp->uf_tml_idx = -1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 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
643 || 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
644 return; // out of memory
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 fp->uf_prof_initialized = TRUE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 fp->uf_profiling = TRUE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 /*
25567
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
652 * 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
653 */
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
654 static void
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
655 script_prof_save(
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
656 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
657 {
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
658 scriptitem_T *si;
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 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
661 {
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
662 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
663 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
664 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
665 }
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
666 profile_get_wait(tm);
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
667 }
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
668
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
669 /*
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
670 * 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
671 */
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
672 void
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
673 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
674 {
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
675 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
676 {
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
677 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
678 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
679 }
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
680 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
681 {
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
682 ++fp->uf_tm_count;
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
683 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
684 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
685 }
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
686 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
687 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
688
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
689 /*
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
690 * 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
691 * 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
692 */
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
693 void
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
694 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
695 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
696 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
697 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
698 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
699 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
700 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
701 {
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
702 profile_add(&caller->uf_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
703 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
704 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
705 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
706 // 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
707 fp->uf_profiling = FALSE;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
708 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
709
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
710 /*
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 * 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
712 * counted for the script/function itself.
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 * 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
714 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 prof_child_enter(
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
717 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
718 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 funccall_T *fc = get_current_funccal();
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 if (fc != NULL && fc->func->uf_profiling)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 profile_start(&fc->prof_child);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 script_prof_save(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 * 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
728 * 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
729 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 prof_child_exit(
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
732 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
733 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 funccall_T *fc = get_current_funccal();
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 if (fc != NULL && fc->func->uf_profiling)
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 profile_end(&fc->prof_child);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
739 profile_sub_wait(tm, &fc->prof_child); // don't count waiting time
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 profile_add(&fc->func->uf_tm_children, &fc->prof_child);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 profile_add(&fc->func->uf_tml_children, &fc->prof_child);
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 script_prof_restore(tm);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 * 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
748 * "sourcing_lnum" must be correct!
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 * 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
750 * 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
751 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 void
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
753 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
754 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 funccall_T *fcp = (funccall_T *)cookie;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 ufunc_T *fp = fcp->func;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
758 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
759 {
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
760 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
761 // Skip continuation lines.
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 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
763 --fp->uf_tml_idx;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 fp->uf_tml_execed = FALSE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 profile_start(&fp->uf_tml_start);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 profile_zero(&fp->uf_tml_children);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 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
768 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 * 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
773 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 func_line_exec(void *cookie)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 funccall_T *fcp = (funccall_T *)cookie;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 ufunc_T *fp = fcp->func;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 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
781 fp->uf_tml_execed = TRUE;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 /*
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 * 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
786 */
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 void
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 func_line_end(void *cookie)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 funccall_T *fcp = (funccall_T *)cookie;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 ufunc_T *fp = fcp->func;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 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
794 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 if (fp->uf_tml_execed)
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 ++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
798 profile_end(&fp->uf_tml_start);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 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
800 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
801 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
802 &fp->uf_tml_children);
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 fp->uf_tml_idx = -1;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 }
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
807
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
808 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
809 * 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
810 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
811 static void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
812 func_dump_profile(FILE *fd)
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 hashtab_T *functbl;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
815 hashitem_T *hi;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
816 int todo;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
817 ufunc_T *fp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
818 int i;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
819 ufunc_T **sorttab;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
820 int st_len = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
821 char_u *p;
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 functbl = func_tbl_get();
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
824 todo = (int)functbl->ht_used;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
825 if (todo == 0)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
826 return; // nothing to dump
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
827
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
828 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
829
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
830 for (hi = functbl->ht_array; todo > 0; ++hi)
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 (!HASHITEM_EMPTY(hi))
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
833 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
834 --todo;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
835 fp = HI2UF(hi);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
836 if (fp->uf_prof_initialized)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
837 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
838 if (sorttab != NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
839 sorttab[st_len++] = fp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
840
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
841 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
842 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
843 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
844 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
845 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
846 {
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
847 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
848 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
849 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
850 {
18120
ed222e264905 patch 8.1.2055: not easy to jump to function line from profile
Bram Moolenaar <Bram@vim.org>
parents: 17899
diff changeset
851 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
852 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
853 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
854 }
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 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
857 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
858 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
859 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
860 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
861 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
862 fprintf(fd, "\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
863 fprintf(fd, "count total (s) self (s)\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
864
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
865 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
866 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
867 if (FUNCLINE(fp, i) == NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
868 continue;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
869 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
870 &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
871 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
872 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
873 fprintf(fd, "\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
874 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
875 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
876 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
877
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
878 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
879 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
880 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
881 prof_total_cmp);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
882 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
883 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
884 prof_self_cmp);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
885 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
886 }
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 vim_free(sorttab);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
889 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
890
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
891 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
892 * Start profiling script "fp".
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
893 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
894 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
895 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
896 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
897 si->sn_pr_count = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
898 profile_zero(&si->sn_pr_total);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
899 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
900
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
901 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
902 si->sn_prl_idx = -1;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
903 si->sn_prof_on = TRUE;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
904 si->sn_pr_nest = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
905 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
906
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
907 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
908 * 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
909 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
910 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
911 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
912 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
913 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
914
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
915 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
916 {
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
917 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
918 if (si->sn_prof_on && --si->sn_pr_nest == 0)
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 profile_end(&si->sn_pr_child);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
921 profile_sub_wait(tm, &si->sn_pr_child); // don't count wait time
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
922 profile_add(&si->sn_pr_children, &si->sn_pr_child);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
923 profile_add(&si->sn_prl_children, &si->sn_pr_child);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
924 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
925 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
926 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
927
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
928 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
929 * 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
930 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
931 static void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
932 script_dump_profile(FILE *fd)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
933 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
934 int id;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
935 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
936 int i;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
937 FILE *sfd;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
938 sn_prl_T *pp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
939
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
940 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
941 {
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
942 si = SCRIPT_ITEM(id);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
943 if (si->sn_prof_on)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
944 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
945 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
946 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
947 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
948 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
949 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
950 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
951 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
952 fprintf(fd, "\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
953 fprintf(fd, "count total (s) self (s)\n");
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 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
956 if (sfd == NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
957 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
958 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
959 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
960 // 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
961 // continuation lines are listed.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
962 for (i = 0; ; ++i)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
963 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
964 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
965 break;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
966 // 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
967 // of multi-byte characters .
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
968 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
969 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
970 int n = IOSIZE - 2;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
971
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
972 if (enc_utf8)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
973 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
974 // 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
975 // 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
976 // for a truncated character.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
977 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
978 --n;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
979 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
980 else if (has_mbyte)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
981 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
982 IObuff[n] = NL;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
983 IObuff[n + 1] = NUL;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
984 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
985 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
986 && (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
987 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
988 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
989 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
990 fprintf(fd, " ");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
991 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
992 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total));
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
993 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
994 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
995 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
996 fprintf(fd, " ");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
997 fprintf(fd, "%s", IObuff);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
998 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
999 fclose(sfd);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1000 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1001 fprintf(fd, "\n");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1002 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1003 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1004 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1005
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1006 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1007 * Dump the profiling info.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1008 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1009 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1010 profile_dump(void)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1011 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1012 FILE *fd;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1013
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1014 if (profile_fname != NULL)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1015 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1016 fd = mch_fopen((char *)profile_fname, "w");
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1017 if (fd == NULL)
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25567
diff changeset
1018 semsg(_(e_cant_open_file_str), profile_fname);
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1019 else
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1020 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1021 script_dump_profile(fd);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1022 func_dump_profile(fd);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1023 fclose(fd);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1024 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1025 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1026 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1027
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1028 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1029 * 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
1030 * "sourcing_lnum" must be correct!
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1031 * 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
1032 * 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
1033 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1034 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1035 script_line_start(void)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1036 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1037 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1038 sn_prl_T *pp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1039
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
1040 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
1041 return;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1042 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
1043 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
1044 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1045 // 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
1046 // here isn't counted.
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1047 (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
1048 (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
1049 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
1050 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
1051 && 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
1052 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1053 // 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
1054 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
1055 pp->snp_count = 0;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1056 profile_zero(&pp->sn_prl_total);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1057 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
1058 ++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
1059 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1060 si->sn_prl_execed = FALSE;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1061 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
1062 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
1063 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
1064 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1065 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1066
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1067 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1068 * 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
1069 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1070 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1071 script_line_exec(void)
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 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1074
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
1075 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
1076 return;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1077 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
1078 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
1079 si->sn_prl_execed = TRUE;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1080 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1081
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1082 /*
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1083 * 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
1084 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1085 void
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1086 script_line_end(void)
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 scriptitem_T *si;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1089 sn_prl_T *pp;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1090
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
1091 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
1092 return;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1093 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
1094 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
1095 && 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
1096 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1097 if (si->sn_prl_execed)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1098 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1099 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
1100 ++pp->snp_count;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1101 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
1102 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
1103 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
1104 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
1105 &si->sn_prl_children);
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1106 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1107 si->sn_prl_idx = -1;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1108 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1109 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
1110 # endif // FEAT_PROFILE
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 #endif