> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# TraceEvent

APISummary
`TraceEvent` is a performance instrumentation utility provided by Lynx. Developers can use TraceEvent to flexibly insert trace points in client-side code, recording the execution timing and duration of key functions, tasks, rendering processes, and more.

## Android

### beginSection

Marks the start of a [trace event](https://perfetto.dev/docs/instrumentation/track-events).

```java
public static void beginSection(String category, String name)
public static void beginSection(String category, String name, Map<String, String> args)
```

#### Parameters

##### category

The [category](https://perfetto.dev/docs/instrumentation/track-events#category-configuration) of the trace event.

##### name

The name of the trace event.

#### args (optional)

Custom arguments for the trace event.

#### Examples

```java
TraceEvent.beginSection("render", "measure-layout");
// ... your code ...
TraceEvent.endSection("render", "measure-layout");

// With custom arguments
Map<String, String> args = new HashMap();
args.put("component", "Image");
args.put("size", "large");
TraceEvent.beginSection("render", "draw-image", args);
// ... your code ...
TraceEvent.endSection("render", "draw-image");
```

### endSection

Marks the end of a [trace event](https://perfetto.dev/docs/instrumentation/track-events).

```java
public static void endSection(String category, String name)
```

#### Parameters

##### category

The [category](https://perfetto.dev/docs/instrumentation/track-events#category-configuration) of the trace event.

##### name

The name of the trace event.

#### Examples

```java
TraceEvent.beginSection("logic", "parse-data");
// ... your code ...
TraceEvent.endSection("logic", "parse-data");
```

### instant

Marks an instant trace event.

```java
public static void instant(String category, String name)
public static void instant(String category, String name, Map<String, String> args)
```

#### Parameters

##### category

The [category](https://perfetto.dev/docs/instrumentation/track-events#category-configuration) of the trace event.

##### name

The name of the trace event.

#### args(optional)

Custom arguments for the trace event.

#### Examples

```java
TraceEvent.instant("network", "request-started");

// With custom arguments
Map<String, String> args = new HashMap<>();
args.put("url", "https://example.com");
args.put("method", "GET");
TraceEvent.instant("network", "request-finished", args);
```

## iOS

### beginSection

Marks the start of a [trace event](https://perfetto.dev/docs/instrumentation/track-events).

```objective-c
+ (void)beginSection:(NSString *)category withName:(NSString *)name
+ (void)beginSection:(NSString *)category withName:(NSString *)name debugInfo:(NSDictionary *)args
```

#### Parameters

##### category

The [category](https://perfetto.dev/docs/instrumentation/track-events#category-configuration) of the trace event.

##### name

The name of the trace event.

#### args(optional)

Custom arguments for the trace event.

#### Examples

```objective-c
[LynxTraceEvent beginSection:@"render" withName:@"measure-layout"];
// ... your code ...
[LynxTraceEvent endSection:@"render" withName:@"measure-layout"];

// With custom arguments
[LynxTraceEvent beginSection:@"render" withName:@"draw-image" debugInfo:@{@"component": @"Image", @"size": @"large"}];
// ... your code ...
[LynxTraceEvent endSection:@"render" withName:@"draw-image"];
```

### endSection

Marks the end of a [trace event](https://perfetto.dev/docs/instrumentation/track-events).

```objective-c
+ (void)endSection:(NSString *)category withName:(NSString *)name
```

#### Parameters

##### category

The [category](https://perfetto.dev/docs/instrumentation/track-events#category-configuration) of the trace event.

##### name

The name of the trace event.

#### Examples

```objective-c
[LynxTraceEvent beginSection:@"logic" withName:@"parse-data"];
// ... your code ...
[LynxTraceEvent endSection:@"logic" withName:@"parse-data"];
```

### instant

Marks an instant trace event.

```objective-c
+ (void)instant:(NSString *)category withName:(NSString *)name
+ (void)instant:(NSString *)category withName:(NSString *)name debugInfo:(NSDictionary *)args
```

#### Parameters

##### category

The [category](https://perfetto.dev/docs/instrumentation/track-events#category-configuration) of the trace event.

##### name

The name of the trace event.

#### args(optional)

Custom arguments for the trace event.

#### Examples

```objective-c
[LynxTraceEvent instant:@"network" withName:@"request-started"];
// With custom arguments
[LynxTraceEvent instant:@"network" withName:@"request-finished" debugInfo:@{@"url": @"https://example.com", @"method": @"GET"}];
```

## Harmony

### beginSection

Marks the start of a [trace event](https://perfetto.dev/docs/instrumentation/track-events).

```typescript
static void beginSection(traceCategory: TraceCategory, name: string, args?: Record<string, string>)
```

#### Parameters

##### category

The [category](https://perfetto.dev/docs/instrumentation/track-events#category-configuration) of the trace event.

```typescript
export enum TraceCategory {
  Lynx = 'lynx',
  Vitals = 'vitals',
  Other = 'other'
}
```

##### name

The name of the trace event.

#### args (optional)

Custom arguments for the trace event.

#### Examples

```javascript
TraceEvent.beginSection(TraceCategory.Other, "measure-layout");
// ... your code ...
TraceEvent.endSection(TraceCategory.Other, "measure-layout");

// With custom arguments
const args: Record<string, string> = {
  "src": "https://example.com",
  "size": "large"
}
TraceEvent.beginSection(TraceCategory.Other, "draw-image", args);
// ... your code ...
TraceEvent.endSection(TraceCategory.Other, "draw-image");
```

### endSection

Marks the end of a [trace event](https://perfetto.dev/docs/instrumentation/track-events).

```typescript
static void endSection(traceCategory: TraceCategory, name: string)
```

#### Parameters

##### category

The [category](https://perfetto.dev/docs/instrumentation/track-events#category-configuration) of the trace event.

```typescript
export enum TraceCategory {
  Lynx = 'lynx',
  Vitals = 'vitals',
  Other = 'other'
}
```

##### name

The name of the trace event.

#### Examples

```javascript
TraceEvent.beginSection(TraceCategory.Other, "parse-data");
// ... your code ...
TraceEvent.endSection(TraceCategory.Other, "parse-data");
```

### instant

Marks an instant trace event.

```typescript
static instant(traceCategory: TraceCategory, name: string, args?: Record<string, string>)
```

#### Parameters

##### category

The [category](https://perfetto.dev/docs/instrumentation/track-events#category-configuration) of the trace event.

##### name

The name of the trace event.

#### args(optional)

Custom arguments for the trace event.

#### Examples

```javascript
TraceEvent.instant(TraceCategory.Other, "request-started");

// With custom arguments
const args: Record<string, string> = {
  "url": "https://example.com",
  "method": "GET"
}
TraceEvent.instant(TraceCategory.Other, "request-finished", args);
```

## Desktop (C API)

Desktop public embedder API exposes trace helpers through C API macros.

### beginSection

Marks the start of a trace section. It must be paired with `LYNX_CAPI_TRACE_END` using the same category and name.

```c
LYNX_CAPI_TRACE_BEGIN(category, name);
```

### endSection

Marks the end of a trace section.

```c
LYNX_CAPI_TRACE_END(category, name);
```

### instant

Records an instant trace event.

```c
LYNX_CAPI_TRACE_INSTANT(category, name);
```

### counter

Records a counter trace event.

```c
LYNX_CAPI_TRACE_COUNTER(category, name, value, incremental);
```

#### Examples

```c
void DecodeImage() {
  LYNX_CAPI_TRACE_BEGIN("image", "DecodeImage");
  // ... your code ...
  LYNX_CAPI_TRACE_END("image", "DecodeImage");
}

LYNX_CAPI_TRACE_INSTANT("network", "RequestStarted");
LYNX_CAPI_TRACE_COUNTER("cache", "EntryCount", 42, false);
```

## Compatibility

**Compatibility Table**

**Query:** `lynx-native-api.trace-event`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-native-api/trace-event.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| trace-event | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.7) | Yes (3.7) | No |

**`trace-event`**

TraceEvent

**Specifications:**

