Skip to content

Commit

Permalink
Add --profile flag to compile command
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jul 10, 2016
1 parent 4977fd3 commit e456973
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/nanoc/cli/commands/compile.rb
Expand Up @@ -14,6 +14,7 @@
SKIP - The item was deemed not outdated and was therefore not recompiled
EOS
flag nil, :profile, 'profile compilation' if Nanoc::Feature.enabled?('PROFILER')

module Nanoc::CLI::Commands
class Compile < ::Nanoc::CLI::CommandRunner
Expand Down Expand Up @@ -366,6 +367,28 @@ def log(level, action, path, duration)
end
end

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

# @see Listener#enable_for?
def self.enable_for?(command_runner)
command_runner.options.fetch(:profile, false)
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 @@ -404,6 +427,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 e456973

Please sign in to comment.