Module: Arborist::CLI::Start
- Extended by:
- Subcommand
- Defined in:
- lib/arborist/command/start.rb
Overview
Command to start a Arborist daemon
Constant Summary collapse
- VALID_DAEMONS =
%w[ manager monitors observers ]
Class Method Summary collapse
-
.default_profile_filename(mode, runner) ⇒ Object
Return a filename for a StackProf profile run over the given
runner
. -
.parse_profile_args(arg, runner) ⇒ Object
Set up the StackProf profiler to run in the given
mode
. -
.start(runner, profile_mode = nil) ⇒ Object
Start the specified
runner
instance after setting up the environment for it. -
.with_profiling_enabled(profile_arg, runner, &block) ⇒ Object
Wrap the profiler around the specified
callable
.
Methods included from Subcommand
display_table, error_string, exit_now!, extended, headline_string, help_now!, highlight_string, hl, prompt, skips_around, skips_post, skips_pre, success_string, unless_dryrun, visible_chars
Class Method Details
.default_profile_filename(mode, runner) ⇒ Object
Return a filename for a StackProf profile run over the given runner
.
104 105 106 107 108 109 110 111 112 |
# File 'lib/arborist/command/start.rb', line 104 def self::default_profile_filename( mode, runner ) basename = runner.class.name.gsub( /.*::/, '' ) return "%s-%s-%s.%d.dump" % [ basename, mode, Time.now.strftime('%Y%m%d%H%M%S'), Process.pid, ] end |
.parse_profile_args(arg, runner) ⇒ Object
Set up the StackProf profiler to run in the given mode
.
95 96 97 98 99 100 |
# File 'lib/arborist/command/start.rb', line 95 def self::parse_profile_args( arg, runner ) profile_mode, profile_filename = arg.split( ':', 2 ) profile_filename ||= self.default_profile_filename( profile_mode, runner ) return profile_mode, profile_filename end |
.start(runner, profile_mode = nil) ⇒ Object
Start the specified runner
instance after setting up the environment for it.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/arborist/command/start.rb', line 68 def start( runner, profile_mode=nil ) Process.setproctitle( runner.class.name ) if profile_mode self.with_profiling_enabled( profile_mode, runner ) do runner.run end else runner.run end end |
.with_profiling_enabled(profile_arg, runner, &block) ⇒ Object
Wrap the profiler around the specified callable
.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/arborist/command/start.rb', line 82 def self::with_profiling_enabled( profile_arg, runner, &block ) require 'stackprof' mode, outfile = self.parse_profile_args( profile_arg, runner ) self.log.info "Profiling in %s mode, outputting to %s" % [ mode, outfile ] StackProf.run( mode: mode.to_sym, out: outfile, &block ) rescue LoadError => err self.log.debug "%p while loading the StackProf profiler: %s" exit_now!( "Couldn't load the profiler; you probably need to `gem install stackprof`", 254 ) end |