Skip to content

Commit

Permalink
Code cleanup for metrics.
Browse files Browse the repository at this point in the history
Note that this code is actually broken :-\ I didn't take the time to either fix
it or rip it out, but this at least improves matters slightly.
  • Loading branch information
neilconway committed Feb 28, 2014
1 parent 97f8c41 commit 8e3506a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 8 additions & 4 deletions lib/bud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ module Bud
attr_reader :budtime, :inbound, :options, :meta_parser, :viz, :rtracer, :dsock
attr_reader :tables, :builtin_tables, :channels, :zk_tables, :dbm_tables, :app_tables, :lattices
attr_reader :push_sources, :push_elems, :push_joins, :scanners, :merge_targets
attr_reader :this_stratum, :this_rule, :rule_orig_src, :done_bootstrap
attr_reader :this_stratum, :this_rule_context, :done_bootstrap
attr_reader :inside_tick
attr_accessor :stratified_rules
attr_accessor :metrics, :periodics
attr_accessor :this_rule_context, :qualified_name
attr_accessor :qualified_name
attr_reader :running_async

# options to the Bud runtime are passed in a hash, with the following keys
Expand Down Expand Up @@ -136,7 +136,8 @@ def initialize(options={})
@instance_id = ILLEGAL_INSTANCE_ID # Assigned when we start running
@metrics = {}
@endtime = nil
@this_stratum = 0
@this_stratum = -1
@this_rule_id = -1
@push_sorted_elems = nil
@running_async = false
@bud_started = false
Expand Down Expand Up @@ -1253,7 +1254,8 @@ def eval_rules(rules, strat_num)
# of PushElements
@this_stratum = strat_num
rules.each_with_index do |rule, i|
@this_rule_context = rule.bud_obj # user-supplied code blocks will be evaluated in this context at run-time
# user-supplied code blocks will be evaluated in this context at run-time
@this_rule_context = rule.bud_obj
begin
eval_rule(rule.bud_obj, rule.src)
rescue Exception => e
Expand All @@ -1264,6 +1266,8 @@ def eval_rules(rules, strat_num)
raise new_e
end
end
@this_rule_context = nil
@this_stratum = -1
end

######## ids and timers
Expand Down
12 changes: 7 additions & 5 deletions lib/bud/collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,21 @@ def positive_predecessors
public
def tick_metrics
strat_num = bud_instance.this_stratum
rule_num = bud_instance.this_rule
addr = nil
addr = bud_instance.ip_port unless bud_instance.port.nil?
key = { :addr=>addr, :tabname=>qualified_tabname,
:strat_num=>strat_num}

bud_instance.metrics[:collections] ||= {}
bud_instance.metrics[:collections][{:addr=>addr, :tabname=>qualified_tabname, :strat_num=>strat_num, :rule_num=>rule_num}] ||= 0
bud_instance.metrics[:collections][{:addr=>addr, :tabname=>qualified_tabname, :strat_num=>strat_num, :rule_num=>rule_num}] += 1
bud_instance.metrics[:collections][key] ||= 0
bud_instance.metrics[:collections][key] += 1
end

private
def each_from(bufs, &block) # :nodoc: all
do_metrics = bud_instance.options[:metrics]
bufs.each do |b|
b.each_value do |v|
tick_metrics if bud_instance.options[:metrics]
tick_metrics if do_metrics
yield v
end
end
Expand Down

0 comments on commit 8e3506a

Please sign in to comment.