-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.vim
More file actions
131 lines (122 loc) · 3.51 KB
/
profile.vim
File metadata and controls
131 lines (122 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
" add to end of .vimrc
" outputs key timings for each key pair
" remove when done as uses up processor
" ================= profiler ==================
augroup profiler
autocmd!
autocmd TextChangedI * :call ProfilerTextChanged()
autocmd CursorHoldI, InsertEnter * :call ProfilerReset()
autocmd BufWritePost * :call ProfilerWrite()
augroup END
function ProfilerTextChanged()
let info=timer_info(s:timerID)
let remain=info[0].remaining
" remaining time counts down
let delay= s:lasttime - remain
" get last char typed
let l:last = strpart(getline('.'),col('.')-2,1)
" skip delays >= 1 second to avoid spurious times
if delay < 1000
let l:pair = s:lastkey . l:last
if has_key(s:keycount, l:pair)
let s:keycount[l:pair] = s:keycount[l:pair] + 1
let s:keytimes[l:pair] = s:keytimes[l:pair] + delay
endif
endif
let s:lasttime = remain
let s:lastkey = l:last
endfunction
function ProfilerReset()
" echom "lastkey: " . s:lastkey
" echom "lasttime: " . s:lasttime
let s:lastkey = ""
endfunction
function ProfilerTimeOut()
echom "profiler timeout - shouldnt get here"
endfunction
function ProfilerInit()
let s:lastkey = ""
let s:keycount = {}
let s:keytimes = {}
let l:len = strlen(s:charsString)
let i = 0
while i < l:len
let c = strpart( s:charsString, i, 1)
let i += 1
let j = 0
while j < l:len
let c2 = strpart( s:charsString, j, 1)
let j += 1
let pair = c . c2
let s:keycount[l:pair] = 0
let s:keytimes[l:pair] = 0
endwhile
endwhile
" only way to get millisecond timer
let s:timerID= timer_start(1000 * 60 * 24, function('ProfilerTimeOut'), {'repeat': -1})
" timer still counts down when paused, just doesn't trigger
call timer_pause(s:timerID,1)
let s:lasttime = 0
endfunction
function ProfilerWrite()
" initialisation
let l:count = ""
let l:times = ""
let beforecount = {}
let beforetimes = {}
let l:len = strlen(s:charsString)
let j = 0
while j < l:len
let beforecount[j] = 0
let beforetimes[j] = 0
let j += 1
endwhile
let total = 0
let i = 0
while i < l:len
let c = strpart( s:charsString, i, 1)
let j = 0
while j < l:len
let c2 = strpart( s:charsString, j, 1)
let pair = c . c2
let total += s:keycount[l:pair]
let l:count =l:count . "," . s:keycount[l:pair]
let l:times =l:times . "," . s:keytimes[l:pair]
" count delays before each key - but only if not on own (ie not reset before key)
let beforecount[j] = beforecount[j] + s:keycount[l:pair]
let beforetimes[j] = beforetimes[j] + s:keytimes[l:pair]
let j += 1
endwhile
let i += 1
endwhile
" only write if enough keypresses so not just editing
if total > 100
let j = 0
let beforecs=""
let beforets=""
while j < l:len
let beforecs=beforecs . "," . beforecount[j]
let beforets=beforets . "," . beforetimes[j]
let j += 1
endwhile
let l:count =l:count . "\n"
let l:times =l:times . "\n"
let beforecs=beforecs . "\n"
let beforets=beforets . "\n"
if writefile([l:count],expand("~/.vim/keycount.csv"),"a")
echom 'write error'
endif
if writefile([l:times],expand("~/.vim/keytimes.csv"),"a")
echom 'write error'
endif
if writefile([beforecs],expand("~/.vim/beforecount.csv"),"a")
echom 'write error'
endif
if writefile([beforets],expand("~/.vim/beforetimes.csv"),"a")
echom 'write error'
endif
endif
endfunction
" keys we want to record pairs of
let s:charsString = "abcdefghijklmnopqrstuvwxyz!\";',. "
call ProfilerInit()