Class: Hone::Correlator
- Inherits:
-
Object
- Object
- Hone::Correlator
- Defined in:
- lib/hone/correlator.rb
Overview
Correlates static analysis findings with runtime profiler data to prioritize optimizations based on actual CPU and allocation impact.
Hone's core value proposition is that not all optimization opportunities are equal. A pattern detected in a hot method that consumes 10% of CPU time is far more valuable to fix than the same pattern in cold initialization code.
The Correlator bridges static and dynamic analysis by:
- Looking up which method contains each finding
- Retrieving CPU percentage from profiler data (if available)
- Retrieving allocation percentage from memory profile (if available)
- Assigning priority based on thresholds and optimization type
- Sorting findings by impact (hottest first)
Constant Summary collapse
- HOT_THRESHOLD =
Threshold for hot methods: >5% of CPU/allocation time These represent critical optimization targets
5.0- WARM_THRESHOLD =
Threshold for warm methods: 1-5% of CPU/allocation time These are worth optimizing but less urgent than hot
1.0- PRIORITIES =
Multi-dimension priority levels assigned to findings based on CPU/allocation usage
i[hot_cpu hot_alloc jit_unfriendly warm cold unknown].freeze
Instance Attribute Summary collapse
-
#hot_threshold ⇒ Float
readonly
Threshold for hot methods.
-
#warm_threshold ⇒ Float
readonly
Threshold for warm methods.
Class Method Summary collapse
-
.filter_by_priority(findings, priority) ⇒ Array<Finding>
Returns findings filtered by priority level.
-
.group_by_priority(findings) ⇒ Hash<Symbol, Array<Finding>>
Groups findings by priority for reporting.
-
.summary(findings) ⇒ Hash
Returns summary statistics for correlated findings.
Instance Method Summary collapse
-
#correlate(findings) ⇒ Array<Finding>
Correlates findings with runtime profile data.
-
#initialize(method_map:, cpu_profile: nil, memory_profile: nil, profile_data: nil, hot_threshold: HOT_THRESHOLD, warm_threshold: WARM_THRESHOLD) ⇒ Correlator
constructor
Creates a new Correlator with method mapping and optional profiler data.
Constructor Details
#initialize(method_map:, cpu_profile: nil, memory_profile: nil, profile_data: nil, hot_threshold: HOT_THRESHOLD, warm_threshold: WARM_THRESHOLD) ⇒ Correlator
Creates a new Correlator with method mapping and optional profiler data.
72 73 74 75 76 77 78 79 80 |
# File 'lib/hone/correlator.rb', line 72 def initialize(method_map:, cpu_profile: nil, memory_profile: nil, profile_data: nil, hot_threshold: HOT_THRESHOLD, warm_threshold: WARM_THRESHOLD) @method_map = method_map # Support backward compatibility: profile_data is treated as cpu_profile @cpu_profile = cpu_profile || profile_data @memory_profile = memory_profile @hot_threshold = hot_threshold @warm_threshold = warm_threshold end |
Instance Attribute Details
#hot_threshold ⇒ Float (readonly)
Returns Threshold for hot methods.
83 84 85 |
# File 'lib/hone/correlator.rb', line 83 def hot_threshold @hot_threshold end |
#warm_threshold ⇒ Float (readonly)
Returns Threshold for warm methods.
86 87 88 |
# File 'lib/hone/correlator.rb', line 86 def warm_threshold @warm_threshold end |
Class Method Details
.filter_by_priority(findings, priority) ⇒ Array<Finding>
Returns findings filtered by priority level.
124 125 126 |
# File 'lib/hone/correlator.rb', line 124 def self.filter_by_priority(findings, priority) findings.select { |f| f.priority == priority } end |
.group_by_priority(findings) ⇒ Hash<Symbol, Array<Finding>>
Groups findings by priority for reporting.
133 134 135 |
# File 'lib/hone/correlator.rb', line 133 def self.group_by_priority(findings) findings.group_by(&:priority) end |
.summary(findings) ⇒ Hash
Returns summary statistics for correlated findings.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/hone/correlator.rb', line 142 def self.summary(findings) by_priority = group_by_priority(findings) { total: findings.size, hot_cpu: by_priority[:hot_cpu]&.size || 0, hot_alloc: by_priority[:hot_alloc]&.size || 0, jit_unfriendly: by_priority[:jit_unfriendly]&.size || 0, warm: by_priority[:warm]&.size || 0, cold: by_priority[:cold]&.size || 0, unknown: by_priority[:unknown]&.size || 0, max_cpu_percent: findings.filter_map(&:cpu_percent).max || 0.0, total_cpu_percent: findings.filter_map(&:cpu_percent).sum, max_alloc_percent: findings.filter_map(&:alloc_percent).max || 0.0, total_alloc_percent: findings.filter_map(&:alloc_percent).sum } end |
Instance Method Details
#correlate(findings) ⇒ Array<Finding>
Correlates findings with runtime profile data.
For each finding, this method:
- Looks up the containing method using the MethodMap
- Queries the profiler for CPU percentage (if cpu_profile present)
- Queries the profiler for allocation percentage (if memory_profile present)
- Calculates priority based on thresholds and optimization type
- Returns enriched findings sorted by impact (descending)
110 111 112 113 114 115 116 |
# File 'lib/hone/correlator.rb', line 110 def correlate(findings) enriched = findings.map do |finding| enrich_finding(finding) end sort_by_impact(enriched) end |