cprof(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

πŸ’… 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 ModLimit is a module name (an atom), this call is equivalent to analyse(ModLimit, 1).
  • if ModLimit is an integer, this function calls analyse(Module, ModLimit) for each Module that is currently loaded (except the cprof module 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 while analyse/0,1,2 is executing, the result could be inconsistent. this happens if the process executing analyse/0,1,2 is scheduled out so some other process can increment the counters that are being analysed. calling pause() 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 FuncSpec is an atom, it is assumed to be a module name, and this call is equivalent to pause(FuncSpec, '_', '_').
  • if FuncSpec is an MFA tuple, {Module, Name, Arity}, this call is equivalent to pause(Module, Name, Arity).
  • if FuncSpec is tuple {FS}, FS is the first argument to erlang:trace_pattern/3. for example, if FuncSpec is {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 FuncSpec is an atom, it is assumed to be a module name, and this call is equivalent to restart(FuncSpec, '_', '_').
  • if FuncSpec is an MFA tuple, {Module, Name, Arity}, this call is equivalent to restart(Module, Name, Arity).
  • if FuncSpec is tuple {FS}, FS is the first argument to erlang:trace_pattern/3. for example, if FuncSpec is {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 FuncSpec is an atom, it is assumed to be a module name, and this call is equivalent to start(FuncSpec, '_', '_').
  • if FuncSpec is an MFA tuple, {Module, Name, Arity}, this call is equivalent to start(Module, Name, Arity).
  • if FuncSpec is tuple {FS}, FS is the first argument to erlang:trace_pattern/3. for example, if FuncSpec is {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 FuncSpec is an atom, it is assumed to be a module name, and this call is equivalent to stop(FuncSpec, '_', '_').
  • if FuncSpec is an MFA tuple, {Module, Name, Arity}, this call is equivalent to stop(Module, Name, Arity).
  • if FuncSpec is tuple {FS}, FS is the first argument to erlang:trace_pattern/3. for example, if FuncSpec is {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