Class: ArchUnit::Extraction::ExtractionProfile
- Inherits:
-
Object
- Object
- ArchUnit::Extraction::ExtractionProfile
- Defined in:
- lib/archunit/extraction/extraction_profile.rb
Overview
Mutable per-run timing and counter collector for cold/warm extraction benchmarks.
Constant Summary collapse
- STAGES =
%i[ total project_discovery source_enumeration load_path_discovery file_read prism_parse import_extraction constant_indexing target_resolution target_index edge_classification edge_merge ].freeze
- COUNTERS =
%i[ source_files malformed_files imports unresolved_imports unresolved_constant_references ambiguous_constant_references resolution_cache_hits resolution_cache_misses raw_edges merged_edges ].freeze
Instance Attribute Summary collapse
-
#counters ⇒ Object
readonly
Returns the value of attribute counters.
-
#stage_seconds ⇒ Object
readonly
Returns the value of attribute stage_seconds.
Class Method Summary collapse
Instance Method Summary collapse
-
#cache_hit? ⇒ Boolean
-
#increment(counter, amount = 1) ⇒ Object
-
#initialize(clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }) ⇒ ExtractionProfile
constructor
A new instance of ExtractionProfile.
-
#measure(stage) ⇒ Object
-
#record_cache_hit ⇒ Object
-
#to_h ⇒ Object
Constructor Details
#initialize(clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }) ⇒ ExtractionProfile
Returns a new instance of ExtractionProfile.
48 49 50 51 52 53 54 55 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 48 def initialize(clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }) raise ArgumentError, 'clock must respond to call' unless clock.respond_to?(:call) @clock = clock @stage_seconds = STAGES.to_h { |stage| [stage, 0.0] } @counters = COUNTERS.to_h { |counter| [counter, 0] } @cache_hit = false end |
Instance Attribute Details
#counters ⇒ Object (readonly)
Returns the value of attribute counters.
34 35 36 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 34 def counters @counters end |
#stage_seconds ⇒ Object (readonly)
Returns the value of attribute stage_seconds.
34 35 36 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 34 def stage_seconds @stage_seconds end |
Class Method Details
.measure(profile, stage, &operation) ⇒ Object
36 37 38 39 40 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 36 def self.measure(profile, stage, &operation) return operation.call unless profile profile.measure(stage, &operation) end |
.validate(value) ⇒ Object
42 43 44 45 46 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 42 def self.validate(value) return if value.nil? || value.is_a?(self) raise ArgumentError, 'profile must be an ExtractionProfile value or nil' end |
Instance Method Details
#cache_hit? ⇒ Boolean
78 79 80 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 78 def cache_hit? @cache_hit end |
#increment(counter, amount = 1) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 65 def increment(counter, amount = 1) validate_counter(counter) unless amount.is_a?(Integer) && !amount.negative? raise ArgumentError, 'counter amount must be a non-negative Integer' end @counters[counter] += amount end |
#measure(stage) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 57 def measure(stage) validate_stage(stage) started_at = @clock.call yield ensure @stage_seconds[stage] += @clock.call - started_at if started_at end |
#record_cache_hit ⇒ Object
74 75 76 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 74 def record_cache_hit @cache_hit = true end |
#to_h ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/archunit/extraction/extraction_profile.rb', line 82 def to_h { cache_hit: cache_hit?, stage_seconds: stage_seconds.transform_values { |value| value.round(6) }, counters: counters.dup } end |
ArchUnitRuby