Class: Fluent::RubyMemoryUsageProfilerInput
- Inherits:
-
Input
- Object
- Input
- Fluent::RubyMemoryUsageProfilerInput
- Defined in:
- lib/fluent/plugin/in_ruby_memory_usage_profiler.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ RubyMemoryUsageProfilerInput
constructor
A new instance of RubyMemoryUsageProfilerInput.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ RubyMemoryUsageProfilerInput
Returns a new instance of RubyMemoryUsageProfilerInput.
14 15 16 17 |
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 14 def initialize super require 'memory_usage_profiler' end |
Instance Method Details
#configure(conf) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 19 def configure(conf) super = MemoryUsageProfiler. case @output_type when 'event' @out = lambda{|result| Fluent::Engine.emit(@tag, Fluent::Engine.now, Hash[ [, result].transpose ])} when 'log' @loglevel = @loglevel.to_sym @out = lambda{|result| $log.send(@loglevel, Hash[ [, result].transpose ])} when 'file' raise Fluent::ConfigError, "'path' must be specified for 'output_type file'" unless @path @file = (@path == '-' ? STDOUT : open(@path, 'w+')) raise Fluent::ConfigError, "failed to open file '#{@path}' to write" unless @file @file.sync = true @file.puts .join("\t") @out = lambda{|result| @file.puts result.join("\t")} else raise Fluent::ConfigError, "invalid output_type '#{@output_type}'" end end |
#start ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 42 def start super @running = true @thread = Thread.new do begin count = 0 while sleep(1) break unless @running count += 1 next if count < @duration MemoryUsageProfiler.kick(@name) {|result| @out.call(result) } count = 0 end rescue => e $log.error "Unexpected error in ruby_memory_usage_profiler", :error_class => e.class, :error => e end end end |
#stop ⇒ Object
65 66 67 68 |
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 65 def stop @running = false @thread.join end |