cprof(3)
π cprof β Erlang manual page, section 3 π
okay so bestie, welcome to cprof, the Erlang manual page from section 3, and honestly? she's iconic. lowkey the chillest profiler in the toolbox. let's get into it π
β¨ NAME β¨
cprof β a simple Call Count Profiling Tool using breakpoints for minimal runtime performance impact.
π¦ DESCRIPTION π¦
so the cprof module is what you use to profile a program and find out how many times different functions get called. and the way she keeps the runtime performance impact minimal? breakpoints. breakpoints that literally have counters inside them. no cap. π₯
because it's breakpoints doing the work, you do not need any special compilation of the modules you want to profile. slay. but β and this is important β these breakpoints can only be set on BEAM code, so BIFs cannot be call-count traced. it's giving "limitations, but make it clear". π
the size of the call counters is the host machine word size. one bit gets used when pausing the counter, which means the maximum counter value for a 32-bit host is 2,147,483,647. do with that what you will, bestie. π§
the profiling result comes back as a term containing a sorted list of entries, one entry per module. each module entry contains a sorted list of functions. and the sorting order in both cases is decreasing call count. so the loudest functions are right at the top. main character energy, fr fr. π
call count tracing is lightweight compared to other forms of tracing, like eprof or fprof, since no trace messages have to be generated. some measurements indicates that the performance degradation is about 10 percent. ok that's actually so good. β
for more information and some examples, see the User's Guide for cprof. iykyk π
πΈ DATA TYPES πΈ
okay here's the shape of everything you'll be handed back, bestie β vibes only, types exactly as they are:
func_analysis_list() ::
[{mfa(), FuncCallCount :: non_neg_integer()}].
mod_analysis() ::
{Mod :: module(),
ModCallCount :: non_neg_integer(),
FuncAnalysisList :: func_analysis_list()}.
mod_analysis_list() :: [mod_analysis()].
π FUNCTIONS π
π analyse(Limit)
analyse(Limit) ->
{AllCallCount :: non_neg_integer(),
ModAnalysisList :: mod_analysis_list()}
when Limit :: non_neg_integer();
(Mod) -> ModAnalysis :: mod_analysis() when Mod ::
module().
collect call counters for one or more modules. that's the whole job. π
- if
ModLimitis a module name (an atom), this call is equivalent toanalyse(ModLimit, 1). - if
ModLimitis an integer, this function callsanalyse(Module, ModLimit)for eachModulethat is currently loaded (except thecprofmodule itself). the result from those calls are returned in a list.
π analyse(Mod, Limit)
analyse(Mod, Limit) -> ModAnalysis :: mod_analysis()
when Mod :: module(), Limit :: non_neg_integer().
collects and analyses all call counters for module Module. obsessed. β¨
this function returns:
{Module, ModuleCount, FuncAnalysisList}
where FuncAnalysisList is a list of tuples, one for each function:
{{Module, FunctionName, Arity}, FuncCallCount}
β οΈ okay listen. if call counters are still running whileanalyse/0,1,2is executing, the result could be inconsistent. this happens if the process executinganalyse/0,1,2is scheduled out so some other process can increment the counters that are being analysed. callingpause()before analysing takes care of that problem. so like... pause first. please. π
also: all functions with a FuncCallCount lower than Limit are excluded from FuncAnalysisList. they are still included in ModCallCount, though. so they're not ghosted completely, just not in the main list. π«Ά
π pause()
pause() -> non_neg_integer().
pause call count tracing for all functions in all modules, and stop it for all functions in modules to be loaded.
this call is equivalent to pause('_', '_', '_') + stop({on_load}). periodt. π
π pause(FuncSpec)
pause(FuncSpec) -> non_neg_integer()
when
FuncSpec ::
(Mod :: module()) | mfa() | {FS :: term()}.
- if
FuncSpecis an atom, it is assumed to be a module name, and this call is equivalent topause(FuncSpec, '_', '_'). - if
FuncSpecis an MFA tuple,{Module, Name, Arity}, this call is equivalent topause(Module, Name, Arity). - if
FuncSpecis tuple{FS},FSis the first argument toerlang:trace_pattern/3. for example, ifFuncSpecis{on_load}, call counters will be paused for all functions in modules to be loaded. cute. π
π pause(Mod, Func, Arity)
pause(Mod, Func, Arity) -> non_neg_integer()
when Mod :: module(), Func :: atom(), Arity :: arity().
pause call counters for matching functions in matching modules. πΈ
the call counters for all matching functions that have call count breakpoints are paused at their current count.
return the number of matching functions that can have call count breakpoints, the same as start/* with the same arguments would have returned. π
π restart(FuncSpec)
restart(FuncSpec) -> non_neg_integer()
when
FuncSpec ::
(Mod :: module()) | mfa() | {FS :: term()}.
- if
FuncSpecis an atom, it is assumed to be a module name, and this call is equivalent torestart(FuncSpec, '_', '_'). - if
FuncSpecis an MFA tuple,{Module, Name, Arity}, this call is equivalent torestart(Module, Name, Arity). - if
FuncSpecis tuple{FS},FSis the first argument toerlang:trace_pattern/3. for example, ifFuncSpecis{on_load}, call counters will be set to zero and running for all functions in modules to be loaded. fresh start energy fr fr. π±
π restart(Mod, Func, Arity)
restart(Mod, Func, Arity) -> non_neg_integer()
when Mod :: module(), Func :: atom(), Arity :: arity().
restart call counters for the matching functions in matching modules that are call-count traced. π¦
the call counters for all matching functions that has call count breakpoints are set to zero and running.
return the number of matching functions that can have call count breakpoints, the same as start/* with the same arguments would have returned.
π start()
start() -> non_neg_integer().
start call count tracing for all functions in all modules, and also for all functions in modules to be loaded.
this is equivalent to start('_', '_', '_') + start({on_load}). let's GOOO π₯
π start(FuncSpec)
start(FuncSpec) -> non_neg_integer()
when
FuncSpec ::
(Mod :: module()) | mfa() | {FS :: term()}.
- if
FuncSpecis an atom, it is assumed to be a module name, and this call is equivalent tostart(FuncSpec, '_', '_'). - if
FuncSpecis an MFA tuple,{Module, Name, Arity}, this call is equivalent tostart(Module, Name, Arity). - if
FuncSpecis tuple{FS},FSis the first argument toerlang:trace_pattern/3. for example, ifFuncSpecis{on_load}, call counters will be set to zero and running for all functions in modules to be loaded. π
π start(Mod, Func, Arity)
start(Mod, Func, Arity) -> non_neg_integer()
when Mod :: module(), Func :: atom(), Arity :: arity().
start call count tracing for matching functions in matching modules. β
set call count breakpoints on the matching functions that has no call count breakpoints. call counters are set to zero and running for all matching functions.
return the number of matching functions that has call count breakpoints. no notes. π
π stop()
stop() -> non_neg_integer().
stop call count tracing for all functions in all modules, and also for all functions in modules to be loaded.
this is equivalent to stop('_', '_', '_') + stop({on_load}). okay wrap it up, we're done here π
π stop(FuncSpec)
stop(FuncSpec) -> non_neg_integer()
when
FuncSpec :: (Mod :: module()) | mfa() | {FS ::
term()}.
- if
FuncSpecis an atom, it is assumed to be a module name, and this call is equivalent tostop(FuncSpec, '_', '_'). - if
FuncSpecis an MFA tuple,{Module, Name, Arity}, this call is equivalent tostop(Module, Name, Arity). - if
FuncSpecis tuple{FS},FSis the first argument toerlang:trace_pattern/3. for example, ifFuncSpecis{on_load}, call counters be disabled for all functions in modules to be loaded. (yes, the original says it like that. i'm not touching it. π)
π stop(Mod, Func, Arity)
stop(Mod, Func, Arity) -> non_neg_integer()
when Mod :: module(), Func :: atom(), Arity :: arity().
stop call count tracing for matching functions in matching modules. π¦
remove call count breakpoints from the matching functions that has call count breakpoints.
return the number of matching functions that can have call count breakpoints, which is the same as start/* with the same arguments would have returned.
and that's the whole page, bestie. every flag, every counter, every '_', every typo preserved, every vibe immaculate. π
this gorgeous thing ships from Ericsson AB, it's part of tools 4.2.2, and the footer stamps it as the cprof(3) page of the Erlang manual. k bye, go profile something and tell me the call counts. πβ¨
π¦ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms