> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Performance Monitor • Rust AI Agent SDK

> PerformanceMonitor: Performance monitor for tracking function and API performance.

# PerformanceMonitor

> Defined in the [**telemetry**](../modules/telemetry) module.

<Badge color="orange">Rust AI Agent SDK</Badge>

Performance monitor for tracking function and API performance.

## Fields

| Name         | Type                                 | Description                   |
| ------------ | ------------------------------------ | ----------------------------- |
| `functions`  | `Arc&lt;RwLock&lt;HashMap&lt;String` | Function statistics           |
| `apis`       | `Arc&lt;RwLock&lt;HashMap&lt;String` | API statistics                |
| `start_time` | `Instant`                            | Start time                    |
| `enabled`    | `bool`                               | Whether monitoring is enabled |

## Methods

### `new`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn new() -> Self
```

Create a new monitor.

### `enable`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn enable(&mut self) -> ()
```

Enable monitoring.

### `disable`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn disable(&mut self) -> ()
```

Disable monitoring.

### `is_enabled`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn is_enabled(&self) -> bool
```

Check if enabled.

### `track_function`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn track_function(&self, name: &str, duration: Duration) -> ()
```

Track a function call.

**Parameters:**

| Name       | Type       |
| ---------- | ---------- |
| `name`     | `&str`     |
| `duration` | `Duration` |

### `track_api`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn track_api(&self, endpoint: &str, duration: Duration, success: bool, status_code: Option<u16>) -> ()
```

Track an API call.

**Parameters:**

| Name          | Type                |
| ------------- | ------------------- |
| `endpoint`    | `&str`              |
| `duration`    | `Duration`          |
| `success`     | `bool`              |
| `status_code` | `Option&lt;u16&gt;` |

### `get_function_stats`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn get_function_stats(&self, name: &str) -> Option<FunctionStats>
```

Get function stats.

**Parameters:**

| Name   | Type   |
| ------ | ------ |
| `name` | `&str` |

### `get_api_stats`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn get_api_stats(&self, endpoint: &str) -> Option<ApiStats>
```

Get API stats.

**Parameters:**

| Name       | Type   |
| ---------- | ------ |
| `endpoint` | `&str` |

### `all_function_stats`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn all_function_stats(&self) -> Vec<FunctionStats>
```

Get all function stats.

### `all_api_stats`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn all_api_stats(&self) -> Vec<ApiStats>
```

Get all API stats.

### `slowest_functions`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn slowest_functions(&self, limit: usize) -> Vec<FunctionStats>
```

Get slowest functions.

**Parameters:**

| Name    | Type    |
| ------- | ------- |
| `limit` | `usize` |

### `slowest_apis`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn slowest_apis(&self, limit: usize) -> Vec<ApiStats>
```

Get slowest APIs.

**Parameters:**

| Name    | Type    |
| ------- | ------- |
| `limit` | `usize` |

### `elapsed`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn elapsed(&self) -> Duration
```

Get elapsed time since start.

### `clear`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn clear(&self) -> ()
```

Clear all data.

### `get_report`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn get_report(&self) -> PerformanceReport
```

Get performance report.

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/telemetry/mod.rs#L164">
  `praisonai/src/telemetry/mod.rs` at line 164
</Card>
