Class: Fluent::WerkzeugProfilerInput::WerkzeugProfilerParser
- Inherits:
-
Object
- Object
- Fluent::WerkzeugProfilerInput::WerkzeugProfilerParser
- Defined in:
- lib/fluent/plugin/in_werkzeug_profiler.rb
Instance Method Summary collapse
- #divide(lines) ⇒ Object
-
#initialize ⇒ WerkzeugProfilerParser
constructor
A new instance of WerkzeugProfilerParser.
- #parse(values) ⇒ Object
Constructor Details
#initialize ⇒ WerkzeugProfilerParser
Returns a new instance of WerkzeugProfilerParser.
33 34 35 36 37 38 |
# File 'lib/fluent/plugin/in_werkzeug_profiler.rb', line 33 def initialize() @keys = ['uri', 'tot_ncalls', 'prim_ncalls', 'tottime', 'tot_percall', 'cumtime', 'cum_percall', 'filename:lineno(function)'] @record_size = @keys.length - 2 @path = nil @time = nil end |
Instance Method Details
#divide(lines) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fluent/plugin/in_werkzeug_profiler.rb', line 47 def divide(lines) records = [] for line in lines do # remove empty lines if line == "\n" next end if line.start_with?('-') @path = nil @time = nil next end if line.start_with?('PATH:') path = line.split(nil)[1] @path = path[1..path.length-2] @time = Time.now.to_i next end if @path == nil || @time == nil next elsif line.split(nil)[1] == 'function' || line.strip.start_with?('ncalls', 'Ordered', 'List') next else values = line.split(nil) # divide ncalls ncalls = values[0].split('/') values[0] = ncalls[0] values[1,0] = ncalls[ncalls.length-1] if values.length > @record_size + 1 values[@record_size] = values[@record_size..values.length-1].join(' ') end record = values[0..@record_size] record.unshift(@path) record.unshift(@time) records << record next end end # return records as array return records end |
#parse(values) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/fluent/plugin/in_werkzeug_profiler.rb', line 40 def parse(values) time = values.shift array = [@keys,values].transpose.flatten record = Hash[*array] return time, record end |