EZProfiler.CodeProfiler (ezprofiler v1.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 without any arguments or labels.
Profiles a specific function with arguments and control labels/functions.
Profiles a specific function with arguments and control labels/functions.
Profiles a function in a pipe without any extra arguments.
Profiles a specific function in a pipe with arguments and/or control labels/functions.
Profiles a specific function in a pipe with extra arguments and control labels/functions.
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)
Profiles a specific function without any arguments or labels.
options
Options
- fun: The function (capture) to profile
example
Example
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.function_profiling(&bar/0)
end
function_profiling(fun, options)
Profiles a specific function with arguments and control labels/functions.
options
Options
- fun: The function (capture) to profile
- options: Can be either a list of arguments, a label (atom) or anonymous function returning a label
Starts profiling a function with arguments only:
example
Example
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.function_profiling(&bar/1, [x])
end
Starts profiling a function using label:
example-1
Example
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.function_profiling(&bar/0, :my_label)
end
Starts profiling with an anonymous function:
example-2
Example
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.function_profiling(&bar/0, fn -> if should_i_profile?(y), do: :my_label, else: :nok end)
end
Then in the ezprofiler
console:
waiting..(1)> c
waiting..(2)>
Code profiling enabled
Or with a label:
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 or the atom :nok
to not profile.
function_profiling(fun, args, options)
Profiles a specific function with arguments and control labels/functions.
options
Options
- fun: The function (capture) to profile
- args: The list of arguments to pass to the function
- options: Can be either a label (atom) or anonymous function returning a label
Starts profiling a function using arguments and a label:
example
Example
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.function_profiling(&bar/1, [x], :my_label)
end
Starts profiling a function using arguments and an anonymous function:
example-1
Example
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 or the atom :nok
to not profile.
pipe_profiling(arg, fun)
Profiles a function in a pipe without any extra arguments.
options
Options
- arg: The argument passed in from the previous function/term in the sequence
- fun: The function (capture) to profile
example
Example
def foo(data) do
x = function1()
data
|> bar()
|> EZProfiler.CodeProfiler.pipe_profiling(&baz/1)
|> function2()
end
pipe_profiling(arg, fun, options)
Profiles a specific function in a pipe with arguments and/or control labels/functions.
options
Options
- arg: The argument passed in from the previous function/term in the sequence
- fun: The function (capture) to profile
- options: Can be either extra arguments, a label (atom) or anonymous function returning a label
Starts profiling a function in a pipe using extra arguments:
example
Example
def foo(data) do
x = function1()
data
|> bar()
|> EZProfiler.CodeProfiler.pipe_profiling(&baz/1, [x])
|> function2()
end
Starts profiling a function in a pipe using a label without extra arguments:
example-1
Example
def foo(data) do
x = function1()
data
|> bar()
|> EZProfiler.CodeProfiler.pipe_profiling(&baz/1, :my_label)
|> function2()
end
Starts profiling without extra arguments and an anonymous function:
example-2
Example
def foo(data) do
x = function1()
data
|> bar()
|> EZProfiler.CodeProfiler.pipe_profiling(&baz/1, fn -> if should_i_profile?(x), do: :my_label, else: :nok end)
|> function2()
end
pipe_profiling(arg, fun, args, options)
Profiles a specific function in a pipe with extra arguments and control labels/functions.
options
Options
- arg: The argument passed in from the previous function/term in the sequence
- fun: The function (capture) to profile
- args: The list of extra arguments to pass to the function
- options: Either a label (atom) or anonymous function returning a label
Starts profiling using arguments and a label:
example
Example
def foo(data) do
x = function1()
data
|> bar()
|> EZProfiler.CodeProfiler.pipe_profiling(&baz/1, [x], :my_label)
|> function2()
end
Starts profiling using arguments and an anonymous function:
example-1
Example
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 or the atom :nok
to not profile.
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(options)
Starts profiling a block of code using a label (atom) or an anonymous function to target the results.
options
Options
- options: Can be either a label (atom) or anonymous function returning a label
Starts profiling a function using label:
example
Example
def foo() do
x = function1()
y = function2()
EZProfiler.CodeProfiler.start_code_profiling(:my_label)
bar(x)
baz(y)
EZProfiler.CodeProfiler.stop_code_profiling()
end
Starts profiling a function using an anonymous function:
example-1
Example
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..(1)> c
waiting..(2)>
Code profiling enabled
Or with a label:
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 or the atom :nok
to not profile.
stop_code_profiling()
Stops profiling a block oof code started with start_code_profiling(..)