Skip to content
Shalabh Chaturvedi edited this page Apr 7, 2019 · 4 revisions

Profiling

Profiling can reveal performance issues or tight loops. Steps to profile:

  1. Copy the following code in a buffer and howl-moon-eval it.
    • select the entire text
    • press alt_x and type 'howl-moon-eval', then enter
    • press escape to close the popup showing the result
  2. Press f2 to start the profiler
    • this should display a message in the status bar
  3. Perform action that you want to profile
  4. 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
}
Clone this wiki locally