# `DalaDev.Profiling`
[🔗](https://github.com/manhvu/dala_dev/blob/main/lib/dala_dev/profiling.ex#L1)

Performance profiling for dala Elixir nodes using :eprof and :fprof.

Provides CPU profiling, flame graphs, and performance analysis
for dala Elixir cluster nodes.

## Examples:

    # Profile a function on a node
    {:ok, profile} = DalaDev.Profiling.profile(
      :"dala_qa@192.168.1.5",
      fn -> MyApp.heavy_computation() end
    )

    # Analyze profile
    {:ok, analysis} = DalaDev.Profiling.analyze(profile)

    # Generate flame graph (HTML)
    DalaDev.Profiling.flame_graph(profile, "flame.html")

# `analysis`

```elixir
@type analysis() :: map()
```

# `node_ref`

```elixir
@type node_ref() :: node() | DalaDev.Device.t() | String.t()
```

# `profile_data`

```elixir
@type profile_data() :: term()
```

# `analyze`

```elixir
@spec analyze(profile_data()) :: {:ok, analysis()} | {:error, term()}
```

Analyze profile data and generate a summary.

Returns a map with:
- `:total_time` - Total execution time
- `:calls` - Number of function calls
- `:top_functions` - List of {module, function, time, calls}
- `:bottlenecks` - Functions with highest time consumption

# `flame_graph`

```elixir
@spec flame_graph(
  profile_data(),
  keyword()
) :: {:ok, String.t() | :ok} | {:error, term()}
```

Generate a flame graph from profile data.

Options:
- `:format` - :html (default) or :text
- `:output` - Output file path (optional)

Returns the report content or :ok if saved to file.

# `profile`

```elixir
@spec profile(node_ref(), (-&gt; any()), keyword()) ::
  {:ok, profile_data()} | {:error, term()}
```

Profile a function on a remote node using :eprof.

Options:
- `:timeout` - RPC timeout in ms (default: 60_000)
- `:duration` - Profile duration in ms (default: 10_000)

Returns `{:ok, profile_data}` or `{:error, reason}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
