Mercurial > vim
annotate src/profiler.c @ 32475:a44d7e4ac1c0 v9.0.1569
patch 9.0.1569: cannot use "this.member" in lambda in class method
Commit: https://github.com/vim/vim/commit/2bd6a09691fc71974ca7ab5973f8e08fdd2a889a
Author: h-east <h.east.727@gmail.com>
Date: Fri May 19 19:01:17 2023 +0100
patch 9.0.1569: cannot use "this.member" in lambda in class method
Problem: Cannot use "this.member" in lambda in class method.
Solution: Adjust check for reserved keyword. (Hirohito Higashi,
closes #12416, closes #12076, closes #12336)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 19 May 2023 20:15:04 +0200 |
parents | d863a33cb220 |
children | 448aef880252 |
rev | line source |
---|---|
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * profiler.c: vim script profiler |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 #if defined(FEAT_EVAL) || defined(PROTO) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 # if defined(FEAT_PROFILE) || defined(FEAT_RELTIME) || defined(PROTO) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 * Store the current time in "tm". |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 profile_start(proftime_T *tm) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 # ifdef MSWIN |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 QueryPerformanceCounter(tm); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 # else |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
27 PROF_GET_TIME(tm); |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 # endif |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 * Compute the elapsed time from "tm" till now and store in "tm". |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 profile_end(proftime_T *tm) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 proftime_T now; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 # ifdef MSWIN |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 QueryPerformanceCounter(&now); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 tm->QuadPart = now.QuadPart - tm->QuadPart; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 # else |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
43 PROF_GET_TIME(&now); |
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
44 tm->tv_fsec = now.tv_fsec - tm->tv_fsec; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 tm->tv_sec = now.tv_sec - tm->tv_sec; |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
46 if (tm->tv_fsec < 0) |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 { |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
48 tm->tv_fsec += TV_FSEC_SEC; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 --tm->tv_sec; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 # endif |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 * Subtract the time "tm2" from "tm". |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 profile_sub(proftime_T *tm, proftime_T *tm2) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 # ifdef MSWIN |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 tm->QuadPart -= tm2->QuadPart; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 # else |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
63 tm->tv_fsec -= tm2->tv_fsec; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 tm->tv_sec -= tm2->tv_sec; |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
65 if (tm->tv_fsec < 0) |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 { |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
67 tm->tv_fsec += TV_FSEC_SEC; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 --tm->tv_sec; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 # endif |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 * Return a string that represents the time in "tm". |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 * Uses a static buffer! |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 char * |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 profile_msg(proftime_T *tm) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 static char buf[50]; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 # ifdef MSWIN |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 LARGE_INTEGER fr; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 QueryPerformanceFrequency(&fr); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 # else |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
88 sprintf(buf, PROF_TIME_FORMAT, (long)tm->tv_sec, (long)tm->tv_fsec); |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 # endif |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 return buf; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 * Return a float that represents the time in "tm". |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 float_T |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 profile_float(proftime_T *tm) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 { |
30310
029c59bf78f1
patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
99 # ifdef MSWIN |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 LARGE_INTEGER fr; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 QueryPerformanceFrequency(&fr); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 return (float_T)tm->QuadPart / (float_T)fr.QuadPart; |
30310
029c59bf78f1
patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
104 # else |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
105 return (float_T)tm->tv_sec + (float_T)tm->tv_fsec / (float_T)TV_FSEC_SEC; |
30310
029c59bf78f1
patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
106 # endif |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 * Put the time "msec" past now in "tm". |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 profile_setlimit(long msec, proftime_T *tm) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 { |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
115 if (msec <= 0) // no limit |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 profile_zero(tm); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 else |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 # ifdef MSWIN |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 LARGE_INTEGER fr; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 QueryPerformanceCounter(tm); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 QueryPerformanceFrequency(&fr); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 tm->QuadPart += (LONGLONG)((double)msec / 1000.0 * (double)fr.QuadPart); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 # else |
32471
d863a33cb220
patch 9.0.1567: profiler calculation may be wrong on 32 bit builds
Bram Moolenaar <Bram@vim.org>
parents:
32186
diff
changeset
|
126 varnumber_T fsec; // this should be 64 bit if possible |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
128 PROF_GET_TIME(tm); |
32471
d863a33cb220
patch 9.0.1567: profiler calculation may be wrong on 32 bit builds
Bram Moolenaar <Bram@vim.org>
parents:
32186
diff
changeset
|
129 fsec = (varnumber_T)tm->tv_fsec |
d863a33cb220
patch 9.0.1567: profiler calculation may be wrong on 32 bit builds
Bram Moolenaar <Bram@vim.org>
parents:
32186
diff
changeset
|
130 + (varnumber_T)msec * (varnumber_T)(TV_FSEC_SEC / 1000); |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
131 tm->tv_fsec = fsec % (long)TV_FSEC_SEC; |
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
132 tm->tv_sec += fsec / (long)TV_FSEC_SEC; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 # endif |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 * 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
|
139 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 int |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 profile_passed_limit(proftime_T *tm) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 proftime_T now; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 # ifdef MSWIN |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
146 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
|
147 return FALSE; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 QueryPerformanceCounter(&now); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 return (now.QuadPart > tm->QuadPart); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 # else |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
151 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
|
152 return FALSE; |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
153 PROF_GET_TIME(&now); |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 return (now.tv_sec > tm->tv_sec |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
155 || (now.tv_sec == tm->tv_sec && now.tv_fsec > tm->tv_fsec)); |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 # endif |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 * 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
|
161 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 profile_zero(proftime_T *tm) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 # ifdef MSWIN |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 tm->QuadPart = 0; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 # else |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
168 tm->tv_fsec = 0; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 tm->tv_sec = 0; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 # endif |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
173 # endif // FEAT_PROFILE || FEAT_RELTIME |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 |
30310
029c59bf78f1
patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
175 #if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_PROFILE) |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 # if defined(HAVE_MATH_H) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 # include <math.h> |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 # endif |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 * 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
|
182 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 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
|
185 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 if (count == 0) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 profile_zero(tm2); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 else |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 # ifdef MSWIN |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 tm2->QuadPart = tm->QuadPart / count; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 # else |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
193 double fsec = (tm->tv_sec * (float_T)TV_FSEC_SEC + tm->tv_fsec) |
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
194 / count; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
196 tm2->tv_sec = floor(fsec / (float_T)TV_FSEC_SEC); |
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
197 tm2->tv_fsec = vim_round(fsec - (tm2->tv_sec * (float_T)TV_FSEC_SEC)); |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
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 |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
218 tm->tv_fsec += tm2->tv_fsec; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 tm->tv_sec += tm2->tv_sec; |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
220 if (tm->tv_fsec >= TV_FSEC_SEC) |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 { |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
222 tm->tv_fsec -= TV_FSEC_SEC; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
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 |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
242 && total->tv_fsec <= children->tv_fsec)) |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
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 |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
279 return (tm1->tv_fsec == tm2->tv_fsec && tm1->tv_sec == tm2->tv_sec); |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
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) |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
293 return tm2->tv_fsec - tm1->tv_fsec; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
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 |
32118
04d9dff67d99
patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file
Bram Moolenaar <Bram@vim.org>
parents:
31778
diff
changeset
|
340 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo) |
28373
2ddf8aa1252c
patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents:
28091
diff
changeset
|
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", |
28373
2ddf8aa1252c
patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents:
28091
diff
changeset
|
440 "stop", |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 "pause", |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 "continue", |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 "func", |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 "file", |
28373
2ddf8aa1252c
patch 8.2.4712: only get profiling information after exiting
Bram Moolenaar <Bram@vim.org>
parents:
28091
diff
changeset
|
445 "dump", |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 NULL |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 }; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 * 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
|
451 * specific expansion. |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 char_u * |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 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
|
455 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 switch (pexpand_what) |
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 case PEXP_SUBCMD: |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 return (char_u *)pexpand_cmds[idx]; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 default: |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 return NULL; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 * 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
|
467 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 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
|
470 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 char_u *end_subcmd; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
473 // Default: expand subcommands. |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 xp->xp_context = EXPAND_PROFILE; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 pexpand_what = PEXP_SUBCMD; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 xp->xp_pattern = arg; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 end_subcmd = skiptowhite(arg); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 if (*end_subcmd == NUL) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 return; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 |
28091
554f493902ea
patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
482 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
|
483 || (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
|
484 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 xp->xp_context = EXPAND_FILES; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 xp->xp_pattern = skipwhite(end_subcmd); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 return; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 } |
28091
554f493902ea
patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
489 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
|
490 { |
554f493902ea
patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
491 xp->xp_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
|
492 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
|
493 return; |
554f493902ea
patch 8.2.4570: no command line completion for :profile and :profdel
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
494 } |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 xp->xp_context = EXPAND_NOTHING; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 static proftime_T inchar_time; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 * 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
|
503 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 prof_inchar_enter(void) |
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 profile_start(&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 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 * 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
|
512 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 prof_inchar_exit(void) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 profile_end(&inchar_time); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 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
|
518 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 * 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
|
523 * profiled. |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 int |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 prof_def_func(void) |
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 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
|
529 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
|
530 return FALSE; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
533 /* |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
534 * 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
|
535 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
536 static void |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
537 prof_func_line( |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
538 FILE *fd, |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
539 int count, |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
540 proftime_T *total, |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
541 proftime_T *self, |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
542 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
|
543 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
544 if (count > 0) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
545 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
546 fprintf(fd, "%5d ", count); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
547 if (prefer_self && profile_equal(total, self)) |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
548 fprintf(fd, PROF_TIME_BLANK); |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
549 else |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
550 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
|
551 if (!prefer_self && profile_equal(total, self)) |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
552 fprintf(fd, PROF_TIME_BLANK); |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
553 else |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
554 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
|
555 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
556 else |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
557 fprintf(fd, " %s%s", PROF_TIME_BLANK, PROF_TIME_BLANK); |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
558 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
559 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
560 static void |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 prof_sort_list( |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 FILE *fd, |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 ufunc_T **sorttab, |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 int st_len, |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 char *title, |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
566 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
|
567 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 int i; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 ufunc_T *fp; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title); |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
572 fprintf(fd, "%s function\n", PROF_TOTALS_HEADER); |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 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
|
574 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 fp = sorttab[i]; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 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
|
577 prefer_self); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 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
|
579 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
|
580 else |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 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
|
582 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 fprintf(fd, "\n"); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 * Compare function for total time sorting. |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 */ |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
589 static int |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 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
|
591 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 ufunc_T *p1, *p2; |
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 p1 = *(ufunc_T **)s1; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 p2 = *(ufunc_T **)s2; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 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
|
597 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 * Compare function for self time sorting. |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 */ |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
602 static int |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 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
|
604 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 ufunc_T *p1, *p2; |
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 p1 = *(ufunc_T **)s1; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 p2 = *(ufunc_T **)s2; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 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
|
610 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 * Start profiling function "fp". |
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 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 func_do_profile(ufunc_T *fp) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 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
|
619 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 if (!fp->uf_prof_initialized) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 if (len == 0) |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
623 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
|
624 fp->uf_tm_count = 0; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 profile_zero(&fp->uf_tm_self); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 profile_zero(&fp->uf_tm_total); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 if (fp->uf_tml_count == NULL) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 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
|
629 if (fp->uf_tml_total == NULL) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 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
|
631 if (fp->uf_tml_self == NULL) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 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
|
633 fp->uf_tml_idx = -1; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 || 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
|
636 return; // out of memory |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 fp->uf_prof_initialized = TRUE; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 fp->uf_profiling = TRUE; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 /* |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
644 * 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
|
645 */ |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
646 static void |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
647 script_prof_save( |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
648 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
|
649 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
650 scriptitem_T *si; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
651 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
652 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
|
653 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
658 profile_get_wait(tm); |
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 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
23976
diff
changeset
|
661 /* |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
662 * 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
|
663 */ |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
664 void |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
665 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
|
666 { |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
667 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
|
668 { |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
669 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
|
670 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
|
671 } |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
672 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
|
673 { |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
674 ++fp->uf_tm_count; |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
675 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
|
676 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
|
677 } |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
678 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
|
679 } |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
680 |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
681 /* |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
682 * 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
|
683 * 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
|
684 */ |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
685 void |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
686 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
|
687 { |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
688 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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 { |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
694 profile_add(&caller->uf_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
|
695 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
|
696 } |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
697 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
|
698 // 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
|
699 fp->uf_profiling = FALSE; |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
700 } |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
701 |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
702 /* |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 * 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
|
704 * counted for the script/function itself. |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 * 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
|
706 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 prof_child_enter( |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
709 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
|
710 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 funccall_T *fc = get_current_funccal(); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
712 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
713 if (fc != NULL && fc->fc_func->uf_profiling) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
714 profile_start(&fc->fc_prof_child); |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 script_prof_save(tm); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 * 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
|
720 * 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
|
721 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 prof_child_exit( |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
724 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
|
725 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 funccall_T *fc = get_current_funccal(); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
728 if (fc != NULL && fc->fc_func->uf_profiling) |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
730 profile_end(&fc->fc_prof_child); |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
731 profile_sub_wait(tm, &fc->fc_prof_child); // don't count waiting time |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
732 profile_add(&fc->fc_func->uf_tm_children, &fc->fc_prof_child); |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
733 profile_add(&fc->fc_func->uf_tml_children, &fc->fc_prof_child); |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 script_prof_restore(tm); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 * 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
|
740 * "sourcing_lnum" must be correct! |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 * 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
|
742 * 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
|
743 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 void |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
745 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
|
746 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 funccall_T *fcp = (funccall_T *)cookie; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
748 ufunc_T *fp = fcp->fc_func; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
750 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
|
751 { |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
752 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
|
753 // Skip continuation lines. |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 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
|
755 --fp->uf_tml_idx; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 fp->uf_tml_execed = FALSE; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 profile_start(&fp->uf_tml_start); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 profile_zero(&fp->uf_tml_children); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 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
|
760 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 * 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
|
765 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 func_line_exec(void *cookie) |
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 funccall_T *fcp = (funccall_T *)cookie; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
770 ufunc_T *fp = fcp->fc_func; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 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
|
773 fp->uf_tml_execed = TRUE; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 /* |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 * 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
|
778 */ |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 void |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 func_line_end(void *cookie) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 funccall_T *fcp = (funccall_T *)cookie; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
28373
diff
changeset
|
783 ufunc_T *fp = fcp->fc_func; |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 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
|
786 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 if (fp->uf_tml_execed) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 ++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
|
790 profile_end(&fp->uf_tml_start); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 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
|
792 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
|
793 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
|
794 &fp->uf_tml_children); |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 fp->uf_tml_idx = -1; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 } |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
799 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
800 /* |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
801 * 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
|
802 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
803 static void |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
804 func_dump_profile(FILE *fd) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
805 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
806 hashtab_T *functbl; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
807 hashitem_T *hi; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
808 int todo; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
809 ufunc_T *fp; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
810 int i; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
811 ufunc_T **sorttab; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
812 int st_len = 0; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
813 char_u *p; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
814 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
815 functbl = func_tbl_get(); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
816 todo = (int)functbl->ht_used; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
817 if (todo == 0) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
818 return; // nothing to dump |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
819 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
820 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
|
821 |
32118
04d9dff67d99
patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file
Bram Moolenaar <Bram@vim.org>
parents:
31778
diff
changeset
|
822 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo) |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
823 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
824 if (!HASHITEM_EMPTY(hi)) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
825 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
826 --todo; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
827 fp = HI2UF(hi); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
828 if (fp->uf_prof_initialized) |
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 if (sorttab != NULL) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
831 sorttab[st_len++] = fp; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
832 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
833 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
|
834 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
|
835 else |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
836 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
|
837 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
|
838 { |
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
|
839 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
|
840 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
|
841 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
|
842 { |
18120
ed222e264905
patch 8.1.2055: not easy to jump to function line from profile
Bram Moolenaar <Bram@vim.org>
parents:
17899
diff
changeset
|
843 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
|
844 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
|
845 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
|
846 } |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
847 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
848 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
|
849 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
|
850 else |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
851 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
|
852 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
|
853 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
|
854 fprintf(fd, "\n"); |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
855 fprintf(fd, "%s\n", PROF_TOTALS_HEADER); |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
856 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
857 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
|
858 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
859 if (FUNCLINE(fp, i) == NULL) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
860 continue; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
861 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
|
862 &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
|
863 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
|
864 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
865 fprintf(fd, "\n"); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
866 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
867 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
868 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
869 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
870 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
|
871 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
872 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
|
873 prof_total_cmp); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
874 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
|
875 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
|
876 prof_self_cmp); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
877 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
|
878 } |
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 vim_free(sorttab); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
881 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
882 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
883 /* |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
884 * Start profiling script "fp". |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
885 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
886 void |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
887 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
|
888 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
889 si->sn_pr_count = 0; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
890 profile_zero(&si->sn_pr_total); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
891 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
|
892 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
893 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
|
894 si->sn_prl_idx = -1; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
895 si->sn_prof_on = TRUE; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
896 si->sn_pr_nest = 0; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
897 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
898 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
899 /* |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
900 * 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
|
901 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
902 void |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
903 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
|
904 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
905 scriptitem_T *si; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
906 |
31778
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
907 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
908 return; |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
909 |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
910 si = SCRIPT_ITEM(current_sctx.sc_sid); |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
911 if (si->sn_prof_on && --si->sn_pr_nest == 0) |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
912 { |
31778
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
913 profile_end(&si->sn_pr_child); |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
914 profile_sub_wait(tm, &si->sn_pr_child); // don't count wait time |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
915 profile_add(&si->sn_pr_children, &si->sn_pr_child); |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
916 profile_add(&si->sn_prl_children, &si->sn_pr_child); |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
917 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
918 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
919 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
920 /* |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
921 * 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
|
922 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
923 static void |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
924 script_dump_profile(FILE *fd) |
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 int id; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
927 scriptitem_T *si; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
928 int i; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
929 FILE *sfd; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
930 sn_prl_T *pp; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
931 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
932 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
|
933 { |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
934 si = SCRIPT_ITEM(id); |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
935 if (si->sn_prof_on) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
936 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
937 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
|
938 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
|
939 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
|
940 else |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
941 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
|
942 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
|
943 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
|
944 fprintf(fd, "\n"); |
32160
98774a275d6d
patch 9.0.1411: accuracy of profiling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
32118
diff
changeset
|
945 fprintf(fd, "%s\n", PROF_TOTALS_HEADER); |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
946 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
947 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
|
948 if (sfd == NULL) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
949 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
|
950 else |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
951 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
952 // 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
|
953 // continuation lines are listed. |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
954 for (i = 0; ; ++i) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
955 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
956 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
|
957 break; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
958 // 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
|
959 // of multi-byte characters . |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
960 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
|
961 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
962 int n = IOSIZE - 2; |
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 (enc_utf8) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
965 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
966 // 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
|
967 // 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
|
968 // for a truncated character. |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
969 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
|
970 --n; |
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 else if (has_mbyte) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
973 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
|
974 IObuff[n] = NL; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
975 IObuff[n + 1] = NUL; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
976 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
977 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
|
978 && (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
|
979 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
980 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
|
981 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
|
982 fprintf(fd, " "); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
983 else |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
984 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total)); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
985 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
|
986 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
987 else |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
988 fprintf(fd, " "); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
989 fprintf(fd, "%s", IObuff); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
990 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
991 fclose(sfd); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
992 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
993 fprintf(fd, "\n"); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
994 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
995 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
996 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
997 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
998 /* |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
999 * Dump the profiling info. |
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 void |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1002 profile_dump(void) |
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 FILE *fd; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1005 |
31778
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1006 if (profile_fname == NULL) |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1007 return; |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1008 |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1009 fd = mch_fopen((char *)profile_fname, "w"); |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1010 if (fd == NULL) |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1011 semsg(_(e_cant_open_file_str), profile_fname); |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1012 else |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1013 { |
31778
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1014 script_dump_profile(fd); |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1015 func_dump_profile(fd); |
579c846086eb
patch 9.0.1221: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1016 fclose(fd); |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1017 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1018 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1019 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1020 /* |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1021 * 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
|
1022 * "sourcing_lnum" must be correct! |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1023 * 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
|
1024 * 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
|
1025 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1026 void |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1027 script_line_start(void) |
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 scriptitem_T *si; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1030 sn_prl_T *pp; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1031 |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
19191
diff
changeset
|
1032 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
|
1033 return; |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1034 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
|
1035 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
|
1036 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1037 // 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
|
1038 // here isn't counted. |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1039 (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
|
1040 (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
|
1041 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
|
1042 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
|
1043 && 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
|
1044 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1045 // 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
|
1046 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
|
1047 pp->snp_count = 0; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1048 profile_zero(&pp->sn_prl_total); |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1049 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
|
1050 ++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
|
1051 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1052 si->sn_prl_execed = FALSE; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1053 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
|
1054 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
|
1055 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
|
1056 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1057 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1058 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1059 /* |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1060 * 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
|
1061 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1062 void |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1063 script_line_exec(void) |
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 scriptitem_T *si; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1066 |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
19191
diff
changeset
|
1067 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
|
1068 return; |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1069 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
|
1070 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
|
1071 si->sn_prl_execed = TRUE; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1072 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1073 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1074 /* |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1075 * 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
|
1076 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1077 void |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1078 script_line_end(void) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1079 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1080 scriptitem_T *si; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1081 sn_prl_T *pp; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1082 |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
19191
diff
changeset
|
1083 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
|
1084 return; |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1085 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
|
1086 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
|
1087 && 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
|
1088 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1089 if (si->sn_prl_execed) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1090 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1091 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
|
1092 ++pp->snp_count; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1093 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
|
1094 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
|
1095 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
|
1096 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
|
1097 &si->sn_prl_children); |
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 si->sn_prl_idx = -1; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1100 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1101 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
1102 # endif // FEAT_PROFILE |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 #endif |