baupaola

baupaola

Using fprof with unit test - getting FunctionClauseError

Hi, I need profile a slow my function test in suite test.
I used the suggestion of Bryan Stearns (https://selfamusementpark.com/profiling-a-slow-elixir-test)
but it does not work if I have variable or function outside the scope.
My hex version is

System.version
"1.6.4"

I tried iex -S mix profile.fprof --no-compile -e “Mix.Tasks.Test.run([])”, it work but the out is for all my test.
I need profile a single test , i tried iex -S mix profile.fprof --no-compile -e “Mix.Tasks.Test.run([only: "test/test_only_profile_trest.exs"])”

but the output is:

Erlang/OTP 20 [erts-9.3.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

07:53:28.841 application=router module=Router function=start_link/1 [info]  started ... with opts [name: RouterGenServer]
07:53:28.841 application=router module=Router function=init/1 [debug] init Elixir.Router with args -->[]
Warmup...
warning: variable "x" is unused
  test/support/helper.exs:37

warning: variable "tdiff" is unused
  test/support/helper.exs:46

** (FunctionClauseError) no function clause matching in String.split/3    
    
    The following arguments were given to **String.split/3:**
    
        # 1
        {:only, "test/test_only_profile_trest.exs"}
    
        # 2
        ":"
    
        # 3
        []
    
    Attempted function clauses (showing 4 out of 4):
    
        def split(string, %Regex{} = pattern, options) when is_binary(string)
        def split(string, "", options) when is_binary(string)
        def split(string, pattern, []) when is_tuple(pattern) or is_binary(string)
        def split(string, pattern, options) when is_binary(string)
    
    (elixir) lib/string.ex:383: String.split/3
    (ex_unit) lib/ex_unit/filters.ex:17: ExUnit.Filters.parse_path/1
    (mix) lib/mix/tasks/test.ex:338: Mix.Tasks.Test.parse_files/2
    (mix) lib/mix/tasks/test.ex:260: Mix.Tasks.Test.run/1
    (mix) lib/mix/tasks/profile.fprof.ex:167: Mix.Tasks.Profile.Fprof.profile_and_analyse/2
    (mix) lib/mix/tasks/profile.fprof.ex:160: Mix.Tasks.Profile.Fprof.profile/2

My mistake where is?
The key “only” is true for task test.

Thanks in advance.
Paola.

Most Liked

NobbZ

NobbZ

I’m not sure how exactly you write the command into the terminal.

Therefore please try these exact commands (copy and paste) and then show us the full transcript when they fail and properly wrap everything into a codeblock, not only the output, but also the command.

iex -S mix profile.fprof --no-compile -e 'Mix.Tasks.Test.run(["test/router_only_profile_test.exs"])'
iex -S mix profile.fprof --no-compile -e 'Mix.Tasks.Test.run(["--only", "test/router_only_profile_test.exs"])'
NobbZ

NobbZ

You need to specify the list of arguments as if you were giving it at the command line:

Mix.Tasks.Test.run(["--only", "test/test_only_profile_trest.exs"])

Aside of that, --only filters based on @tags, you probably want to pass only the file to run tests from:

Mix.Tasks.Test.run(["test/test_only_profile_trest.exs"])

Finally, I do think you have a typo in the filename :wink:

Last Post!

baupaola

baupaola

Thank you very much for your help, the error was double quotes after -e.
Now work.
Thank.
Paola.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement