Revision 8fae0052c8e0888953da159045909ea2c1336b3d authored by Semen Zhydenko on 11 February 2018, 02:58:13 UTC, committed by jekyllbot on 11 February 2018, 02:58:13 UTC
Merge pull request 6764
1 parent 33017b7
Raw File
stackprof
#!/usr/bin/env ruby

require "bundler/setup"
require "json"
require "stackprof"
require File.expand_path("../lib/jekyll", __dir__)

MODE = ARGV.first || "cpu"
PROF_OUTPUT_FILE = File.expand_path("../tmp/stackprof-#{MODE}-#{Time.now.strftime("%Y%m%d%H%M")}.dump", __dir__)

puts "Stackprof Mode: #{MODE}"

unless File.exist?(PROF_OUTPUT_FILE)
  StackProf.run(
    mode: MODE.to_sym,
    interval: 100,
    raw: true,
    out: PROF_OUTPUT_FILE
  ) do
    puts "GC Stats:", JSON.pretty_generate(GC.stat)
    GC.disable

    Jekyll::Commands::Build.process({'source' => 'docs'})

    puts 'GC Stats:'
    GC.start(full_mark: true, immediate_sweep: false)
    puts JSON.pretty_generate(GC.stat)
  end
end

options = {
  sort: true,
  limit: 30,
  format: :text,
}

# You can also do other things. Examples:
# https://github.com/tmm1/stackprof/blob/master/bin/stackprof
report = StackProf::Report.new(Marshal.load(IO.binread(PROF_OUTPUT_FILE)))
report.print_text(
  options[:sort],
  options[:limit],
  options[:select_files],
  options[:reject_files],
  options[:select_names],
  options[:reject_names]
)

puts "Results stored in #{PROF_OUTPUT_FILE}"
back to top