Skip to content

Commit

Permalink
Add StackProf-based profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jul 9, 2016
1 parent b22c2d8 commit d0c48dc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/nanoc/cli/commands/compile.rb
Expand Up @@ -350,6 +350,29 @@ def log(level, action, path, duration)
end
end

# Records a profile using StackProf
class StackProfProfiler < Listener
PROFILE_FILE = 'tmp/profile'

# @see Listener#enable_for?
def self.enable_for?(_command_runner)
# TODO: Extract
ENV.fetch('NANOC_FEAT_PROFILER', 'false') == 'y'
end

# @see Listener#start
def start
require 'stackprof'
StackProf.start(mode: :cpu)
end

# @see Listener#stop
def stop
StackProf.stop
StackProf.results(PROFILE_FILE)
end
end

attr_accessor :listener_classes

def initialize(options, arguments, command)
Expand Down Expand Up @@ -388,6 +411,7 @@ def default_listener_classes
Nanoc::CLI::Commands::Compile::TimingRecorder,
Nanoc::CLI::Commands::Compile::GCController,
Nanoc::CLI::Commands::Compile::FileActionPrinter,
Nanoc::CLI::Commands::Compile::StackProfProfiler,
]
end

Expand Down

0 comments on commit d0c48dc

Please sign in to comment.