Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sabiwara committed May 27, 2024
1 parent bdea259 commit 27e56dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 13 additions & 9 deletions lib/mix/lib/mix/tasks/profile.tprof.ex
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,23 @@ defmodule Mix.Tasks.Profile.Tprof do
fun.()
end

tprof_module().start()
matching = Keyword.get(opts, :matching, {:_, :_, :_})
set_on_spawn = Keyword.get(opts, :set_on_spawn, true)
type = Keyword.get(opts, :type, :time)

sort_by =
case Keyword.get(opts, :sort) do
nil -> :measurement
:calls -> :calls
^type -> :measurement
other -> Mix.raise("Incompatible sort option `#{other}` with type `#{type}`")
nil ->
:measurement

:calls ->
:calls

^type ->
:measurement

other ->
Mix.raise("Incompatible sort option #{inspect(other)} with type #{inspect(type)}")
end

tprof_type = to_tprof_type(type)
Expand All @@ -252,8 +258,6 @@ defmodule Mix.Tasks.Profile.Tprof do

inspected = tprof_module().inspect({tprof_type, traces}, :process, sort_by)

tprof_module().stop()

results =
inspected
|> Enum.map(fn {pid, {^tprof_type, measurement_total, call_results}} ->
Expand Down Expand Up @@ -284,11 +288,11 @@ defmodule Mix.Tasks.Profile.Tprof do
end

defp get_filter_value!(type, time, _memory) when is_integer(time) and type != :time do
Mix.raise("Incompatible use of time option with type `#{type}`")
Mix.raise("Incompatible use of time option with type #{inspect(type)}")
end

defp get_filter_value!(type, _time, memory) when is_integer(memory) and type != :memory do
Mix.raise("Incompatible use of memory option with type `#{type}`")
Mix.raise("Incompatible use of memory option with type #{inspect(type)}")
end

defp get_filter_value!(:time, time, nil) when is_integer(time), do: time
Expand Down
8 changes: 4 additions & 4 deletions lib/mix/test/mix/tasks/profile.tprof_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,25 @@ defmodule Mix.Tasks.Profile.TprofTest do

test "errors on incompatible options", context do
in_tmp(context.test, fn ->
message = "Incompatible sort option `memory` with type `time`"
message = "Incompatible sort option :memory with type :time"

assert_raise Mix.Error, message, fn ->
capture_io(fn -> Tprof.run(["-e", @expr, "--sort", "memory"]) end)
end

message = "Incompatible sort option `time` with type `calls`"
message = "Incompatible sort option :time with type :calls"

assert_raise Mix.Error, message, fn ->
capture_io(fn -> Tprof.run(["-e", @expr, "--type", "calls", "--sort", "time"]) end)
end

message = "Incompatible use of memory option with type `time`"
message = "Incompatible use of memory option with type :time"

assert_raise Mix.Error, message, fn ->
capture_io(fn -> Tprof.run(["-e", @expr, "--time", "1", "--memory", "2"]) end)
end

message = "Incompatible use of time option with type `calls`"
message = "Incompatible use of time option with type :calls"

assert_raise Mix.Error, message, fn ->
capture_io(fn -> Tprof.run(["-e", @expr, "--type", "calls", "--time", "1"]) end)
Expand Down

0 comments on commit 27e56dc

Please sign in to comment.