diff --git a/lib/slap/report.ex b/lib/slap/report.ex index f9a7959..32ace5f 100644 --- a/lib/slap/report.ex +++ b/lib/slap/report.ex @@ -1,3 +1,3 @@ defmodule Slap.Report do - defstruct metrics: [], success: 0, total: 0, average_latency: 0, total_iterations: 0, current_iteration: 0 + defstruct metrics: [], codes: %{}, success: 0, total: 0, average_latency: 0, total_iterations: 0, current_iteration: 0 end diff --git a/lib/slap/reporter.ex b/lib/slap/reporter.ex index d9d7721..35b475b 100644 --- a/lib/slap/reporter.ex +++ b/lib/slap/reporter.ex @@ -7,6 +7,7 @@ defmodule Slap.Reporter do def init(_state) do {:ok, %{ metrics: [], + codes: %{}, success: 0, total: 0, average_latency: 0, @@ -38,6 +39,12 @@ defmodule Slap.Reporter do state = %{state | success: state[:success] + 1 } end + count = case Map.has_key?(state.codes, metric.status_code) do + false -> 0 + true -> Map.get(state.codes, metric.status_code) + 1 + end + + state = %{ state | codes: Map.put(state.codes, metric.status_code, count) } state = %{ state | total: state[:total] + 1 } state = %{ state | metrics: state[:metrics] ++ [metric] } state = %{ state | total_time: state[:total_time] + metric.latency } @@ -62,6 +69,7 @@ defmodule Slap.Reporter do %Slap.Report{ success: state.success, metrics: state.metrics, + codes: state.codes, total: state.total, average_latency: state.average_latency, total_iterations: state.total_iterations, diff --git a/lib/slap/reporter_cli.ex b/lib/slap/reporter_cli.ex index f494569..3069e58 100644 --- a/lib/slap/reporter_cli.ex +++ b/lib/slap/reporter_cli.ex @@ -15,7 +15,7 @@ defmodule Slap.ReporterCli do if report.total_iterations > 0 do IO.write "\e[1A" IO.write "\r" - clean(80) + clean(200) IO.write "\r" write(report) IO.write "\n" @@ -32,6 +32,9 @@ defmodule Slap.ReporterCli do end defp write(report) do - IO.write " Total: #{report.total} | Success: #{report.success} | Fail: #{report.total - report.success} | Average latency: #{trunc(report.average_latency / 1000000)} ms" + IO.write " Total: #{report.total} | Success: #{report.success} | Fail: #{report.total - report.success} | Average latency: #{trunc(report.average_latency / 1000000)} ms " + Enum.each(report.codes, fn({k, x}) -> + IO.write(" | #{k} : #{x}") + end) end end