Module: Estackprof

Defined in:
lib/estackprof.rb,
lib/estackprof/cli.rb,
lib/estackprof/top.rb,
lib/estackprof/list.rb,
lib/estackprof/report.rb,
lib/estackprof/version.rb,
lib/estackprof/flamegraph.rb,
lib/estackprof/middleware.rb

Defined Under Namespace

Classes: CLI, Error, Middleware, Report

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.flamegraph(files:) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/estackprof/flamegraph.rb', line 7

def flamegraph(files:)
  mkdir(tmp_path = './tmp')
  html_path = File.expand_path("#{tmp_path}/flamegraph.html")
  File.open(html_path, 'w') { |f| Report.create([files[0]]).print_d3_flamegraph(f) }
  Launchy.open(html_path)
  html_path
rescue StandardError
  puts 'Dump files are missing or incorrect.'
end

.list(files:, options:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/estackprof/list.rb', line 6

def list(files:, options:)
  io = StringIO.new

  print_by_options(Report.create(files), options, io)

  io.rewind
  io.read.to_s
rescue StandardError
  puts 'Dump files are missing or incorrect.'
end

.mkdir(path) ⇒ Object



19
20
21
# File 'lib/estackprof/flamegraph.rb', line 19

def mkdir(path)
  FileUtils.mkdir_p(path) unless FileTest.exist?(path)
end

.parse_options(options) ⇒ Object



17
18
19
20
21
22
# File 'lib/estackprof/top.rb', line 17

def parse_options(options)
  limit = options[:limit] || 10
  pattern = options[:pattern] && Regexp.new(options[:pattern])
  sort_by_total = options[:cumlative]
  { limit: limit, pattern: pattern, sort_by_total: sort_by_total }
end


19
20
21
22
23
24
25
26
27
# File 'lib/estackprof/list.rb', line 19

def print_by_options(report, options, io)
  if options[:method]
    report.print_method(options[:method], io)
  elsif options[:file]
    report.print_file(options[:file], io)
  else
    report.print_files(false, nil, io)
  end
end

.top(files:, options:) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/estackprof/top.rb', line 6

def top(files:, options:)
  io = StringIO.new
  Report.create(files).print_text(**parse_options(options), out: io)
  io.rewind
  io.read.to_s
rescue StandardError
  puts 'Dump files are missing or incorrect.'
end