class Fluent::RubyMemoryUsageProfilerInput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_ruby_memory_usage_profiler.rb, line 16
def initialize
  super
  require 'memory_usage_profiler'
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_ruby_memory_usage_profiler.rb, line 21
def configure(conf)
  super

  @banner = MemoryUsageProfiler.banner_items

  case @output_type
  when 'event'
    @out = lambda{|result| Fluent::Engine.emit(@tag, Fluent::Engine.now, Hash[ [@banner, result].transpose ])}
  when 'log'
    @loglevel = @loglevel.to_sym
    @out = lambda{|result| $log.send(@loglevel, Hash[ [@banner, 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
    if @out_time
      @file.puts (['time'] + @banner).join("\t")
    else
      @file.puts @banner.join("\t")
    end
    @out = lambda do |result|
      header = @out_time ? [Time.now.strftime(@time_format)] : []
      @file.puts (header + result).join("\t")
    end
  else
    raise Fluent::ConfigError, "invalid output_type '#{@output_type}'"
  end
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_ruby_memory_usage_profiler.rb, line 51
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() click to toggle source
# File lib/fluent/plugin/in_ruby_memory_usage_profiler.rb, line 74
def stop
  @running = false
  @thread.join
end