• Stars
    star
    177
  • Rank 208,131 (Top 5 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple code profiler for Elixir using eprof.

ExProf

Build Status hex.pm version hex.pm downloads

A simple code profiler for Elixir using eprof.

It provides a simple macro as a wrapper for Erlang's :eprof profiler.

Install

Add :exprof to deps section of mix.exs.

  def deps do
    [ {:exprof, "~> 0.2.0"} ]
  end

Usage

import "ExProf.Macro", then use "profile" macro to start profiling. It prints out results, and returns them as list of records, along with the result of the profiled block.

defmodule SampleRunner do
  import ExProf.Macro

  @doc "analyze with profile macro"
  def do_analyze do
    profile do
      :timer.sleep 2000
      IO.puts "message\n"
    end
  end

  @doc "get analysis records and sum them up"
  def run do
    {records, _block_result} = do_analyze
    total_percent = Enum.reduce(records, 0.0, &(&1.percent + &2))
    IO.inspect "total = #{total_percent}"
  end
end

Run

An example to use in iex console.

$ iex -S mix
..
iex(1)> SampleRunner.run
message

FUNCTION                                 CALLS      %  TIME  [uS / CALLS]
--------                                 -----    ---  ----  [----------]
'Elixir.IO':puts/2                           1   0.86     1  [      1.00]
io:o_request/3                               1   1.72     2  [      2.00]
io:put_chars/2                               1   1.72     2  [      2.00]
erlang:group_leader/0                        1   1.72     2  [      2.00]
io:request/2                                 1   2.59     3  [      3.00]
io:execute_request/2                         1   2.59     3  [      3.00]
'Elixir.SampleRunner':'-run/0-fun-0-'/0      1   2.59     3  [      3.00]
'Elixir.IO':map_dev/1                        1   3.45     4  [      4.00]
erlang:demonitor/2                           1   4.31     5  [      5.00]
io:io_request/2                              1   6.03     7  [      7.00]
io:wait_io_mon_reply/2                       1   6.90     8  [      8.00]
'Elixir.IO':puts/1                           1   8.62    10  [     10.00]
unicode:characters_to_binary/2               1  11.21    13  [     13.00]
timer:sleep/1                                1  14.66    17  [     17.00]
erlang:monitor/2                             1  31.03    36  [     36.00]
"total = 100.0"

Add a Mix Task

An example to use as mix tasks.

defmodule Mix.Tasks.Exprof do
  @shortdoc "Profile using ExProf"
  use Mix.Task
  import ExProf.Macro

  def run(_mix_args) do
    profile do: do_work(2)
  end

  defp do_work(n) do
    :timer.sleep(n * 1000)
  end
end

More Repositories

1

excoveralls

Coverage report tool for Elixir with coveralls.io integration.
Elixir
796
star
2

exvcr

HTTP request/response recording library for elixir, inspired by VCR.
Elixir
701
star
3

extwitter

Twitter client library for elixir.
Elixir
410
star
4

excheck

Property-based testing library for Elixir (QuickCheck style).
Elixir
317
star
5

exfirebase

An elixir library for accessing the Firebase REST API.
Elixir
87
star
6

oauth2ex

An OAuth 2.0 client library for elixir.
Elixir
57
star
7

kindle-your-highlights

Scrape highlights from kindle.amazon.com
Ruby
48
star
8

exprintf

A printf / sprintf library for Elixir. It works as a wrapper for :io.format.
Elixir
35
star
9

http_server

A simple and self-contained HTTP Server for elixir.
Elixir
12
star
10

spawn_viewer

Trial implementation to visualize process spawning.
Elixir
8
star
11

dynamo_angular

Sample AngularJS scaffolding with dynamo and angular-resource backend.
Elixir
5
star
12

dynamo_firebase

Sample dynamo project for implementing rails-like scaffold page with Firebase backend.
Elixir
4
star
13

ruboto_flickr

Flickr search sample app using Ruboto
Java
4
star
14

big_query

[WIP] Elixir + Google BigQuery Sample
Elixir
4
star
15

dynamo_scaffold

Sample dynamo project for implementing rails-like scaffold page with REST API backend.
Elixir
3
star
16

coverage_sample

sample code for excoveralls
Elixir
3
star
17

chef-cookbook-elixir

Chef cookbook for installing elixir (elixir-lang)
Ruby
3
star
18

exfuture

A trial implementation of future
Elixir
2
star
19

circle_sample

A test project for CircleCI and Elixir.
Elixir
2
star
20

docker-poxa

Dockerfile for poxa installation.
Shell
2
star
21

mono_timer

Pomodoro-style 25 minutes timer rails-app with notification feature.
Ruby
2
star
22

exrtm

An elixir library for remember the milk API.
Elixir
2
star
23

chef-cookbook-dynamo

Chef cookbook for deploying dynamo application (elixir-lang)
Ruby
2
star
24

excov

testing for coverage
Elixir
1
star
25

sample_future

Sample parallel map program for Future on elixir
Elixir
1
star
26

dynamo_sample

Just a sample for deployment trial
Elixir
1
star
27

pogo

simple tool for starting/stopping erlang nodes via the command line
Elixir
1
star
28

angularjs_sample_rails

angularjs sample with angular-resource and rails backend.
Ruby
1
star
29

angularjs_samples

Angular JS sample
JavaScript
1
star
30

ereadline

(WIP) A readline wrapper for Erlang.
C
1
star
31

thought_mapper

[WIP] Thinking assistant tool on comparing options.
Ruby
1
star
32

rtmgo

Remember the milk api client for golang
Go
1
star
33

excoveralls_umbrella

Sample project for excoveralls on umbrella elixir projects.
Elixir
1
star