kseg

kseg

How do you profile an entire application

Plenty of guides that show how to profile a specific function, but I can’t figure out how to profile an application (run with --no-halt, if that chances anything). Any pointers?

Most Liked

kseg

kseg

Think I figured it out.

Right at the top of my application’s start function, I added:

:fprof.trace([:start, verbose: true, procs: :all])

spawn fn ->
  :timer.sleep(10_000)
  :fprof.trace(:stop)
  :fprof.profile()
  :fprof.analyse(totals: false, dest: 'prof.analysis')
end

the procs: all makes it profile all processes. I stop the trace after 10 second. This generated a 1.5GB fprof.trace file (so, beware!) The calls to profile/analyze generates a very verbose prof.analysis file (37MB). This file can be explored, but it’s noisy.

I used GitHub - isacssouza/erlgrind: Convert fprof to callgring output · GitHub to convert the file to a callgrind format which then lets you use those sets of tools (like http://kcachegrind.sourceforge.net/html/Home.html).

aseigo

aseigo

I think there’s also a bit of a culture difference: if you instead search for “elixir metrics” you’ll find quite a number of resources for this. “elixir profiling” not nearly as much. This probably reflects some aspects of the culture around, and cultural heritage that have gone into, Elixir. Aaaanyways …

Here’s a decent tool that looks like it may provide what you are after: Exometer, an Elixir wrapper for it (which I haven’t yet tried myself … so ymmv?), and there are a good number of blog entries out there that talk about these tools as used from Elixir.

There are several other instrumentation-based libraries for gathering and tracking metrics for Elixir out there. That includes a couple of 3rd party services which will host the resulting data and who have nice native Elixir libs. But there are also fully self-hosted solutions that a “elixir metrics” on google will discover :slight_smile:

Some random thoughts circling my head about the whole “profiling has a common meaning in other languages / environments”: … wearing my C/C++ (or most other languages I use) hat, yeah I would agree with that. “Profiling” has a fairly static meaning in those contexts.

Elixir’s, or rather the BEAM’s, inherent preemptive code execution (aka processes) and async message passing make a number of traditional profiling techniques and ideas (like “watch how much CPU my app uses pls”) not as clear cut. e.g. in most other platforms I’ve worked with the idea of “hey, can you tell me how many concurrent code paths there are?” is relatively exotic; even in heavily multi-threaded applications I’ve written in C++, I haven’t experienced anywhere near the usual level of dynamic behavior that a typical Elixir application ends up exhibiting which makes tracking / counting / monitoring processes “a thing” that is actually interesting. The preemption can also have interesting effects in more basic measurement techniques in real-world environs, though that can be controlled for in testing environs, but then that lends itself to synthetic micro-benchmarking .. which can be useful, but not always what is needed to demonstrate shipability as artifacts like message bottlenecks will only show up under load.

aseigo

aseigo

Yep, fprof is quite comprehensive; ships with Erlang, so is quit well supported (and been around the block a few times) but .. as you found .. it produces some pretty gnarly output. I wasn’t actually aware of erlgrind, though, that’s awesome :slight_smile: Definitely will have to use that next time …

p.s. kcachegrind ftw.. have used and loved that app for .. gosh .. i don’t know how many years now.

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
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

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
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
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement