# pprof-format

> Pure JavaScript pprof encoder and decoder

Latest version **2.3.1** (published 2026-08-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install pprof-format
pnpm add pprof-format
yarn add pprof-format
bun add pprof-format
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.3.1 |
| Published | 2026-08-07 |
| First published | 2022-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 492.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 8 |
| Author | Datadog Inc. |
| Maintainers | datadog |
| Keywords | pprof, encode, decode, profile |

## Links

- npm: https://www.npmjs.com/package/pprof-format
- Repository: https://github.com/DataDog/pprof-format
- Homepage: https://github.com/DataDog/pprof-format#readme
- Issues: https://github.com/DataDog/pprof-format/issues
- npm.io page: https://npm.io/package/pprof-format

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 2.3.1 (latest) — 2026-08-07
- 2.3.0 — 2026-07-24
- 2.2.3 — 2026-07-22
- 2.2.2 — 2026-06-16
- 2.2.1 — 2025-08-29
- 2.1.0 — 2024-03-20
- 2.0.7 — 2023-02-27
- 2.0.6 — 2023-01-28
- 2.0.5 — 2023-01-09
- 2.0.4 — 2022-10-17
- 2.0.3 — 2022-10-15
- 2.0.2 — 2022-10-15
- 2.0.1 — 2022-10-15
- 2.0.0 — 2022-10-15
- 1.0.1 — 2022-07-30
- … 1 more at https://npm.io/package/pprof-format/versions

## README

# pprof-format

A pure JavaScript PProf encoder and decoder library with zero dependencies and
browser support. No protobuf, because the pprof spec only uses a tiny fraction
of the features. Uint8Arrays rather than Node.js buffers so it can work in the
browser. Carefully tuned to be as fast as possible.

## Install

```sh
npm install pprof-format
```

## Usage

```js
import {
  Function,
  Label,
  Line,
  Location,
  Mapping,
  Profile,
  Sample,
  ValueType,
  StringTable
} from 'pprof-format'

const stringTable = new StringTable()

const periodType = new ValueType({
  type: stringTable.dedup('cpu'),
  unit: stringTable.dedup('nanoseconds')
})

const fun = new Function({
  id: 1,
  name: stringTable.dedup('name'),
  systemName: stringTable.dedup('system name'),
  filename: stringTable.dedup('filename'),
  startLine: 123
})

const mapping = new Mapping({
  id: 1
})

const location = new Location({
  id: 1,
  mappingId: mapping.id,
  address: 123,
  line: [
    new Line({
      functionId: fun.id,
      line: 1234
    })
  ]
})

const profile = new Profile({
  sampleType: [
    new ValueType({
      type: stringTable.dedup('sample'),
      unit: stringTable.dedup('count')
    }),
    periodType
  ],
  sample: [
    new Sample({
      locationId: [location.id],
      value: [123, 456],
      label: [
        new Label({
          key: stringTable.dedup('label key'),
          str: stringTable.dedup('label str')
        }),
        new Label({
          key: stringTable.dedup('label key'),
          num: 12345,
          numUnit: stringTable.dedup('label num unit')
        })
      ]
    })
  ],
  mapping: [mapping],
  location: [location],
  'function': [fun],
  stringTable,
  timeNanos: BigInt(Date.now()) * 1_000_000n,
  durationNanos: 1234,
  periodType,
  period: 1234 / 2,
  comment: [
    stringTable.dedup('some comment')
  ]
})

// Encode to Uint8Array
console.log(profile.encode())

// Decode from Uint8Array
const copied = Profile.decode(profile.encode())

// Should match the structure of the original profile object
console.log(copied)
```

---
_Source: https://npm.io/package/pprof-format · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
