EZProfiler.CodeProfiler (ezprofiler v0.1.0)
This module handles code profiling. The user hits 'c' or 'c label' and any process whose code calls the function 'EZCodeProfiler.start_profiling' will be profiled until 'EZCodeProfiler.stop_profiling` is called. Only a single process at a time can be profiled. Other profiling functions allow for pipe profiling and function profiling. The module is loaded from the escript, replacing the one in the release, the reverse happens when the escript terminates. The module in the release has functions like: def start_profiling() do end So they are all no-ops with no run-time cost. There is a minimal run-time cost when the module is loaded, as much as a message to an Agent.
Link to this section Summary
Functions
Profiles a specific function
Starts profiling a function using label (atom) or an anonymous function to target the results.
Starts profiling a function in a pipe.
Starts profiling a function in a pipe using label (atom) or an anonymous function to target the results.
Starts profiling a block of code, must call EZProfiler.CodeProfiler.stop_code_profiling()
to stop and present the results.
Starts profiling a block of code using a label (atom) or an anonymous function to target the results.
Stops profiling a block oof code started with start_code_profiling(..)
Link to this section Functions
function_profiling(fun, args)
Profiles a specific function
example
Example
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.function_profiling(&bar/1, [x])
end
function_profiling(fun, args, label_or_fun)
Starts profiling a function using label (atom) or an anonymous function to target the results.
example-atom
Example (atom)
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.function_profiling(&bar/1, [x], :my_label)
end
example-anonymous-function
Example (anonymous function)
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.function_profiling(&bar/1, [x], fn -> if should_i_profile?(y), do: :my_label, else: :nok end)
end
Then in the ezprofiler
console:
waiting..(4)> c my_label
waiting..(5)>
Code profiling enabled with a label of :my_label
waiting..(5)>
Got a start profiling from source code with label of :my_label
NOTE: If anonymous function is used it must return an atom (label) to allow profiling ot the atom :nok
to not profile.
pipe_profiling(arg, fun, args)
Starts profiling a function in a pipe.
example
Example
def foo(data) do
x = function1()
data
|> bar()
|> EZProfiler.CodeProfiler.pipe_profiling(&baz/1, [x])
|> function2()
end
NOTE: It is advisable to filter results with --mf
or the u
option in the ezprofiler
console
pipe_profiling(arg, fun, args, label_or_fun)
Starts profiling a function in a pipe using label (atom) or an anonymous function to target the results.
example-atom
Example (atom)
def foo(data) do
x = function1()
data
|> bar()
|> EZProfiler.CodeProfiler.pipe_profiling(&baz/1, [x], :my_label)
|> function2()
end
example-anonymous-function
Example (anonymous function)
def foo(data) do
x = function1()
data
|> bar()
|> EZProfiler.CodeProfiler.pipe_profiling(&baz/1, [x], fn -> if should_i_profile?(x), do: :my_label, else: :nok end)
|> function2()
end
Then in the ezprofiler
console:
waiting..(4)> c my_label
waiting..(5)>
Code profiling enabled with a label of :my_label
waiting..(5)>
Got a start profiling from source code with label of :my_label
NOTE: If anonymous function is used it must return an atom (label) to allow profiling ot the atom :nok
to not profile.
NOTE: It is advisable to filter results with --mf
or the u
option in the ezprofiler
console
start_code_profiling()
Starts profiling a block of code, must call EZProfiler.CodeProfiler.stop_code_profiling()
to stop and present the results.
example
Example
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.start_code_profiling()
bar(x)
baz(y)
EZProfiler.CodeProfiler.stop_code_profiling()
end
start_code_profiling(label_or_fun)
Starts profiling a block of code using a label (atom) or an anonymous function to target the results.
example-atom
Example (atom)
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.start_code_profiling(:my_label)
bar(x)
baz(y)
EZProfiler.CodeProfiler.stop_code_profiling()
end
example-anonymous-function
Example (anonymous function)
EZProfiler.CodeProfiler.start_code_profiling(fn -> if should_i_profile?(foo), do: :my_label, else: :nok end)
case do_send_email(email, private_key) do
:ok ->
EZProfiler.CodeProfiler.stop_code_profiling()
Then in the ezprofiler
console:
waiting..(4)> c my_label
waiting..(5)>
Code profiling enabled with a label of :my_label
waiting..(5)>
Got a start profiling from source code with label of :my_label
NOTE: If anonymous function is used it must return an atom (label) to allow profiling ot the atom :nok
to not profile.
stop_code_profiling()
Stops profiling a block oof code started with start_code_profiling(..)