-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from binaryseed/metric-merge-opt
Optimize metric collection with counters
- Loading branch information
Showing
7 changed files
with
90 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,12 @@ | ||
defmodule NewRelic.Metric do | ||
@moduledoc false | ||
|
||
defstruct name: "", | ||
scope: "", | ||
call_count: 0, | ||
max_call_time: 0, | ||
min_call_time: 0, | ||
sum_of_squares: 0, | ||
total_call_time: 0, | ||
total_exclusive_time: 0 | ||
|
||
@moduledoc false | ||
|
||
def merge(one, two) do | ||
%{ | ||
one | ||
| call_count: one.call_count + two.call_count, | ||
max_call_time: max(one.max_call_time, two.max_call_time), | ||
min_call_time: calculate_min_call_time(one.min_call_time, two.min_call_time), | ||
sum_of_squares: one.sum_of_squares + two.sum_of_squares, | ||
total_call_time: one.total_call_time + two.total_call_time, | ||
total_exclusive_time: one.total_exclusive_time + two.total_exclusive_time | ||
} | ||
end | ||
|
||
defp calculate_min_call_time(cur, acc) when cur == 0 or acc == 0, do: max(cur, acc) | ||
defp calculate_min_call_time(cur, acc), do: min(cur, acc) | ||
total_exclusive_time: 0, | ||
min_call_time: 0, | ||
max_call_time: 0, | ||
sum_of_squares: 0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters