---
title: "Export simulation telemetry to CSV in C#"
url: https://recursiveai.org/onescope/cookbook/export-replay-track-samples/
description: "Scan a OneScope simulation replay in C#, read the step and value from a numeric telemetry track, and export the samples as CSV for plotting."
version: "1.0.0"
---

# Export simulation telemetry to CSV in C#

**OneScope** is a free, open-source viewer for simulation recordings, with a desktop window or command-line control, from Recursive AI. MIT or Apache-2.0.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneScope.Sdk) · [GitHub](https://github.com/recursive-ai-oss/onescope-csharp) · [Docs](https://recursiveai.org/onescope/docs/) · [Download example (.zip)](https://recursiveai.org/onescope/cookbook/export-replay-track-samples/export-replay-track-samples.zip)

Export a numeric track, the series of values a module records with `sink.Sample`. Use `CounterModule.cs` and `counter.replay` from the zip.

```shell
dotnet add package RecursiveAI.OneScope.Sdk
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
var history = CounterModule
    .OpenHistory("counter.replay");
history.Scan();
var track = history.Tracks.Single(
    t => t.Info.Id == "count");
if (track.Truncated)
    throw new InvalidOperationException(
        "Incomplete track.");
Console.WriteLine("step,count");
foreach (var sample in track.Samples)
{
    long step = sample.Step;
    double value = sample.Value;
    FormattableString row = $"{step},{value}";
    Console.WriteLine(
        FormattableString.Invariant(row));
}
```

Unzip [the example](https://recursiveai.org/onescope/cookbook/export-replay-track-samples/export-replay-track-samples.zip), then `dotnet run`.

```text
step,count
1,2
2,4
3,6
4,8
```

## Program and sample recording

The included `counter.replay` contains:

```text
COUNT 4
```

`OpenHistory` is a helper in `CounterModule.cs` that reads the file, calls the module’s `Open` method, and creates a `History`. The module reads this recording as four steps. The counter adds two each step, and `Advance` calls `sink.Sample("count", Count)` to record each new count. The program prints CSV to standard output; to save it instead, use the file-writing variation below.

If `track.Truncated` is true, the track reached its sample cap; the example stops instead of labeling the CSV as complete.

## Variations

To save the CSV directly, replace the `Console.WriteLine` block after the truncation check:

```csharp
using var csv = File.CreateText("count.csv");
csv.WriteLine("step,count");
foreach (var sample in track.Samples)
    csv.WriteLine(FormattableString.Invariant($"{sample.Step},{sample.Value}"));
```

## Related recipes

- [Record custom timeline events](https://recursiveai.org/onescope/cookbook/record-custom-replay-timeline-events/)
- [Seek to a specific tick](https://recursiveai.org/onescope/cookbook/seek-simulation-replay-to-step/)

## The short answer

Open the recording with its module, create a `History`, and call `Scan()` before reading the track. Find the numeric track by its ID and write each `TrackSample.Step` and `TrackSample.Value` as a row. This exports the samples the module emits while replaying; it does not infer values for steps that produced no sample.

## How do you plot replay telemetry and check for missing samples?

Use the tick as the horizontal coordinate and the numeric sample as the vertical coordinate. The file-writing variation saves both columns through `File.CreateText`; load `count.csv` into a spreadsheet or plotter with `step` as the x value and `count` as the y value. Use invariant formatting even if the example happens to contain whole numbers. A decimal comma in a fractional sample would otherwise share the same character as your CSV field separator. Keep units in the column name or the chart label when they matter. Do not label raw ticks as seconds unless you know the simulation’s tick duration.

Select the track by ID rather than by its order in the list: a module can declare several tracks, and event or marker tracks carry labels rather than a numeric series. `Scan()` fills the timeline and returns the time cursor to where it started. Check `Truncated` before treating the rows as the full series. For a bounded recording, you can raise `ScopeHistoryOptions.MaxTrackSamples` when constructing the history and scan again with the new history; the cap is per track.
