Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profiler (behind feature flag) #903

Merged
merged 1 commit into from Jul 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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