Skip to content

Commit

Permalink
Implement mix profile.tprof (#13605)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Klingler authored May 27, 2024
1 parent ae5be31 commit 76fec7e
Show file tree
Hide file tree
Showing 3 changed files with 634 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/mix/lib/mix/tasks/profile.eprof.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ defmodule Mix.Tasks.Profile.Eprof do
calls_opt = Keyword.get(opts, :calls, 0)
time_opt = Keyword.get(opts, :time, 0)

call_results
|> Stream.filter(fn {_mfa, {count, _time}} -> count >= calls_opt end)
|> Stream.filter(fn {_mfa, {_count, time}} -> time >= time_opt end)
Enum.filter(call_results, fn {_mfa, {count, time}} ->
count >= calls_opt and time >= time_opt
end)
end

defp sort_results(call_results, opts) do
Expand Down Expand Up @@ -307,15 +307,10 @@ defmodule Mix.Tasks.Profile.Eprof do
max_lengths = Enum.map(header, &String.length/1)

Enum.reduce(rows, max_lengths, fn row, max_lengths ->
Stream.map(row, &String.length/1)
|> Stream.zip(max_lengths)
|> Enum.map(&max/1)
Enum.zip_with(row, max_lengths, fn cell, length -> String.length(cell) |> max(length) end)
end)
end

defp max({a, b}) when a >= b, do: a
defp max({_, b}), do: b

@format "~-*s ~*s ~*s ~*s ~*s~n"

defp print_row(row, column_lengths) do
Expand Down
Loading

0 comments on commit 76fec7e

Please sign in to comment.