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.
16 17 18 19 |
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 16 def initialize super require 'memory_usage_profiler' end |
Instance Method Details
#configure(conf) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 21 def configure(conf) super @banner = MemoryUsageProfiler. 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 ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# 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 ⇒ Object
74 75 76 77 |
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 74 def stop @running = false @thread.join end |