Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Forked from tagomoris/gist:2234497
Created March 29, 2012 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frsyuki/2234507 to your computer and use it in GitHub Desktop.
Save frsyuki/2234507 to your computer and use it in GitHub Desktop.
def emit(tag, es, chain)
t = if @sample_unit == :all
'all'
else
tag
end
# Access to @counts SHOULD be protected by mutex, with a heavy penalty.
# Code below is not thread safe, but @counts (counter for sampling rate) is not
# so serious value (and probably will not be broke...),
# then i let here as it is now.
interval = @interval
pairs = []
es.each {|time,record|
c = @counts.fetch(t, 0) + 1
if c % interval == 0
@counts[t] = 0 if c > 0x6fffffff
pairs.push [time, record]
end
}
emit_sampled(tag, pairs)
chain.next
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment