Skip to content

Commit

Permalink
map_reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
bradhanks committed Jan 25, 2024
1 parent 5441301 commit 241b4b2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/new_relic/sampler/beam.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ defmodule NewRelic.Sampler.Beam do
defp delta(:util, previous, current) do
{active, total} =
Enum.zip(previous, current)
|> Enum.map(fn {{n, a0, t0}, {n, a1, t1}} -> {n, a1 - a0, t1 - t0} end)
|> Enum.reduce({0, 0}, fn {_n, d_a, d_t}, {acc_a, acc_t} -> {acc_a + d_a, acc_t + d_t} end)
|> Enum.map_reduce({0, 0}, fn
{{n, a0, t0}, {n, a1, t1}}, {acc_a, acc_t} ->
{{n, a1 - a0, t1 - t0}, {acc_a + (a1 - a0), acc_t + (t1 - t0)}}
end)
|> elem(1)

safe_div(active, total)
end
Expand Down

0 comments on commit 241b4b2

Please sign in to comment.