|
| 1 | +commit 4f385fb359c5d51bd4a079ffd35bbcc1c6676c4a (HEAD, github/custom-nfa-log, custom-nfa-log) |
| 2 | +Author: guns <self@sungpae.com> |
| 3 | +Date: 9 hours ago |
| 4 | + |
| 5 | + Add custom NFA logging to nfa_regexp.log |
| 6 | + |
| 7 | + The goal is to get a ballpark estimate of the number of steps the regexp |
| 8 | + engine undertakes in a session. One line of logging is done: |
| 9 | + |
| 10 | + * Start of nfa_regmatch() |
| 11 | + * For each character considered |
| 12 | + * For each state of a character considered |
| 13 | + |
| 14 | + Vimm should be compiled with -DDEBUG; if the NFA engine state graphs are |
| 15 | + desired, then also use -DINCLUDE_NFA_DUMP. |
| 16 | + |
| 17 | + This branch can also be found at: |
| 18 | + |
| 19 | + https://github.com/guns/vim/tree/custom-nfa-log |
| 20 | +--- |
| 21 | + src/regexp_nfa.c | 20 +++++++++++++++++--- |
| 22 | + 1 file changed, 17 insertions(+), 3 deletions(-) |
| 23 | + |
| 24 | +diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c |
| 25 | +index 738ac3b..c39f94d 100644 |
| 26 | +--- a/src/regexp_nfa.c |
| 27 | ++++ b/src/regexp_nfa.c |
| 28 | +@@ -24,9 +24,18 @@ |
| 29 | + #ifdef DEBUG |
| 30 | + # define NFA_REGEXP_ERROR_LOG "nfa_regexp_error.log" |
| 31 | + # define ENABLE_LOG |
| 32 | +-# define NFA_REGEXP_DUMP_LOG "nfa_regexp_dump.log" |
| 33 | +-# define NFA_REGEXP_RUN_LOG "nfa_regexp_run.log" |
| 34 | +-# define NFA_REGEXP_DEBUG_LOG "nfa_regexp_debug.log" |
| 35 | ++# ifdef INCLUDE_NFA_DUMP |
| 36 | ++# define NFA_REGEXP_DUMP_LOG "/dev/null" |
| 37 | ++# else |
| 38 | ++# define NFA_REGEXP_DUMP_LOG "nfa_regexp.log" |
| 39 | ++# endif |
| 40 | ++# define NFA_REGEXP_RUN_LOG "/dev/null" |
| 41 | ++# define NFA_REGEXP_DEBUG_LOG "/dev/null" |
| 42 | ++# define LOG(fmt, ...) do { \ |
| 43 | ++ FILE *log = fopen("nfa_regexp.log", "a"); \ |
| 44 | ++ fprintf(log, fmt, __VA_ARGS__); \ |
| 45 | ++ fclose(log); \ |
| 46 | ++} while (0) |
| 47 | + #endif |
| 48 | + |
| 49 | + enum |
| 50 | +@@ -5043,6 +5052,8 @@ nfa_regmatch(prog, start, submatch, m) |
| 51 | + goto theend; |
| 52 | + |
| 53 | + #ifdef ENABLE_LOG |
| 54 | ++ LOG("START nfa_regmatch: alloc=%d pattern=\"%s\"\n", size*2, prog->pattern); |
| 55 | ++ |
| 56 | + log_fd = fopen(NFA_REGEXP_RUN_LOG, "a"); |
| 57 | + if (log_fd != NULL) |
| 58 | + { |
| 59 | +@@ -5129,6 +5140,8 @@ nfa_regmatch(prog, start, submatch, m) |
| 60 | + nextlist->id = nfa_listid + 1; |
| 61 | + |
| 62 | + #ifdef ENABLE_LOG |
| 63 | ++ LOG("# states=%d reginput=\"%s\"\n", thislist->n, reginput); |
| 64 | ++ |
| 65 | + fprintf(log_fd, "------------------------------------------\n"); |
| 66 | + fprintf(log_fd, ">>> Reginput is \"%s\"\n", reginput); |
| 67 | + fprintf(log_fd, ">>> Advanced one character ... Current char is %c (code %d) \n", curc, (int)curc); |
| 68 | +@@ -5161,6 +5174,7 @@ nfa_regmatch(prog, start, submatch, m) |
| 69 | + fprintf(debug, "%s, ", code); |
| 70 | + #endif |
| 71 | + #ifdef ENABLE_LOG |
| 72 | ++ LOG("## computing nextlist: code=\"%s\"\n", code); |
| 73 | + { |
| 74 | + int col; |
| 75 | + |
0 commit comments