Class: AppMap::Algorithm::Stats
- Inherits:
-
StatsStruct
- Object
- Struct
- StatsStruct
- AppMap::Algorithm::Stats
- Defined in:
- lib/appmap/algorithm/stats.rb
Overview
Compute AppMap statistics.
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from StatsStruct
Instance Method Summary collapse
Instance Method Details
#perform(limit: nil) ⇒ Object
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 |
# File 'lib/appmap/algorithm/stats.rb', line 61 def perform(limit: nil) events = appmap['events'] || [] frequency_calc = lambda do |key_func| events_by_key = events.inject(Hash.new(0)) do |memo, event| key = key_func.call(event) memo.tap do memo[key] += 1 if key end end events_by_key.map do |key, count| Frequency.new(key, count) end end class_name_func = ->(event) { event['defined_class'] } full_name_func = lambda do |event| call = event['event'] == 'call' class_name = event['defined_class'] static = event['static'] function_name = event['method_id'] [ class_name, static ? '.' : '#', function_name ].join if call && class_name && !static.nil? && function_name end class_frequency = frequency_calc.call(class_name_func) method_frequency = frequency_calc.call(full_name_func) Result.new(class_frequency, method_frequency) end |