-module(gflambe). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -define(FILEPATH, "src/gflambe.gleam"). -export([apply/2, capture/3]). -export_type([eflambe_format/0, eflambe_open_program/0, eflambe_options/0, gflambe_function/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " # Gflambe\n" " The main gflambe module. Defines the two functions that\n" " let you start the process of generating the flame graph.\n" ). -type eflambe_format() :: svg | brendan_gregg. -type eflambe_open_program() :: speedscope | hotspot. -type eflambe_options() :: {output_format, eflambe_format()} | {output_directory, binary()} | {open, eflambe_open_program()}. -type gflambe_function() :: {gflambe_function, binary(), binary(), integer()}. -file("src/gflambe.gleam", 59). ?DOC( " This method will run the specified anonymous function given\n" " as the first parameter and generate a flame graph from its execution.\n" " The third argument is an options array that may be empty\n" "\n" " ## Example\n" " ```gleam\n" " gflambe.apply(\n" " fn() {\n" " string.append(\"hello\", \"world\")\n" " Nil\n" " },\n" " [],\n" " )\n" " ```\n" ). -spec apply(fun(() -> nil), list(eflambe_options())) -> any(). apply(Function, Options) -> eflambe:apply({Function, []}, Options). -file("src/gflambe.gleam", 80). ?DOC( " Start a process that waits for the function specified as the \n" " first argument to be run and creates its corresponding flame graph.\n" " The function must be executed at least `number_of_calls_to_capture`\n" " times for the graph to be generated. The third argument is an options\n" " array that may be empty.\n" "\n" " ## Example\n" " ```gleam\n" " gflambe.capture(GflambeFunction(\"gleam@string\", \"append\", 2), 1, [])\n" " ```\n" ). -spec capture(gflambe_function(), integer(), list(eflambe_options())) -> any(). capture(Function, Number_of_calls_to_capture, Options) -> {gflambe_function, Module, Function_name, Arity} = Function, Module_atom = erlang:binary_to_atom(Module), Function_name_atom = erlang:binary_to_atom(Function_name), eflambe:capture( {Module_atom, Function_name_atom, Arity}, Number_of_calls_to_capture, Options ).