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:

Where Next?

Popular in Questions Top

aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
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
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement