-
Notifications
You must be signed in to change notification settings - Fork 67
Profiling How to
Shalabh Chaturvedi edited this page Apr 7, 2019
·
4 revisions
Profiling can reveal performance issues or tight loops. Steps to profile:
- Copy the following code in a buffer and
howl-moon-eval
it.- select the entire text
- press
alt_x
and type 'howl-moon-eval', thenenter
- press
escape
to close the popup showing the result
- Press
f2
to start the profiler- this should display a message in the status bar
- Perform action that you want to profile
- Press
f3
to stop the profiler and print a report- this opens the report in a new buffer
profile = require 'jit.profile'
{:StyledText} = howl.ui
dumpstack = profile.dumpstack
append = table.insert
local data
start_profile = ->
data = {}
cb = (thread, samples, vmstate)->
append data, dumpstack(thread, '-> l[f] ', 10)
profile.start 'l', cb
log.info 'Started profiler'
show_summary = ->
counts = {}
summary = {}
for line in *data
if counts[line]
counts[line] += 1
else
counts[line] = 1
lines = [k for k in pairs counts]
table.sort lines, (a, b) -> counts[b] < counts[a]
for line in *lines
append summary, {counts[line], line}
b = howl.ui.ActionBuffer!
b\append StyledText.for_table summary
howl.app\open buffer: b
log.info "Done with profiler, got #{#data} samples"
stop_profile = ->
profile.stop!
show_summary data
howl.bindings.push
f2: -> start_profile!
f3: -> stop_profile!
{
:start_profile
:stop_profile
}