View Source cure_profiler (cure v0.1.0)

Cure Runtime Profiler

Collects runtime execution statistics to guide compiler optimizations. Provides lightweight instrumentation and aggregation of:

  • Function call counts and frequencies
  • Hot path detection through call sequences
  • Type usage patterns at runtime
  • Memory allocation patterns
  • Performance metrics

Usage

% Initialize profiling
cure_profiler:start_profiling(),

% Run your code
my_application:run(),

% Collect profile data
ProfileData = cure_profiler:get_profile_data(),

% Use for optimization
OptimizedAST = cure_type_optimizer:optimize_with_profile(AST, ProfileData),

% Stop profiling
cure_profiler:stop_profiling().

Profile Data Format

Profile data is stored as a map with the following structure:

#{
    function_calls => #{FunctionName => CallCount},
    call_sequences => [{Caller, Callee, Count}],
    type_usage => #{Type => UsageCount},
    memory_allocations => #{Function => AllocationSize},
    hot_functions => [FunctionName],
    hot_paths => [[FunctionName]],
    timestamp => Milliseconds
}

Summary

Functions

analyze_profile()

-spec analyze_profile() -> map().

analyze_profile(Opts)

-spec analyze_profile(map()) -> map().

export_profile(Filename)

-spec export_profile(file:filename()) -> ok | {error, term()}.

get_function_stats()

-spec get_function_stats() -> map().

get_hot_functions()

-spec get_hot_functions() -> [atom()].

get_hot_functions(N)

-spec get_hot_functions(pos_integer()) -> [atom()].

get_hot_paths()

-spec get_hot_paths() -> [[atom()]].

get_profile_data()

-spec get_profile_data() -> map().

get_type_usage()

-spec get_type_usage() -> map().

import_profile(Filename)

-spec import_profile(file:filename()) -> ok | {error, term()}.

record_call_sequence(Caller, Callee)

-spec record_call_sequence(atom(), atom()) -> ok.

record_function_call(FunctionName)

-spec record_function_call(atom()) -> ok.

record_function_call(FunctionName, Count)

-spec record_function_call(atom(), pos_integer()) -> ok.

record_memory_allocation(FunctionName, Size)

-spec record_memory_allocation(atom(), non_neg_integer()) -> ok.

record_type_usage(FunctionName, Type)

-spec record_type_usage(atom(), term()) -> ok.

reset_profiling()

-spec reset_profiling() -> ok.

start_profiling()

-spec start_profiling() -> ok.

start_profiling(Config)

-spec start_profiling(map()) -> ok.

stop_profiling()

-spec stop_profiling() -> ok.