{"library":"pprof-format","title":"PProf Format Encoder/Decoder","description":"pprof-format is a pure JavaScript library for encoding and decoding PProf (Profiling Protobuf) profiles. It distinguishes itself by providing a zero-dependency implementation that avoids the full Protobuf runtime, instead focusing on the subset of the PProf specification required for profiling data. This design choice contributes to a smaller bundle size and faster execution, making it highly suitable for both Node.js and browser environments. The library explicitly uses Uint8Arrays over Node.js Buffers to ensure universal compatibility. Currently at version 2.2.1, its release cadence is typically driven by new features or specification updates rather than a fixed schedule. Key differentiators include its browser-friendliness, lack of external dependencies, and performance optimizations. It ships with TypeScript types for enhanced developer experience.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pprof-format"],"cli":null},"imports":["import { Profile } from 'pprof-format'","import { StringTable } from 'pprof-format'","import { Location } from 'pprof-format'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import {\n  Function,\n  Label,\n  Line,\n  Location,\n  Mapping,\n  Profile,\n  Sample,\n  ValueType,\n  StringTable\n} from 'pprof-format'\n\nconst stringTable = new StringTable()\n\nconst periodType = new ValueType({\n  type: stringTable.dedup('cpu'),\n  unit: stringTable.dedup('nanoseconds')\n})\n\nconst fun = new Function({\n  id: 1,\n  name: stringTable.dedup('main'),\n  systemName: stringTable.dedup('main'),\n  filename: stringTable.dedup('app.js'),\n  startLine: 1\n})\n\nconst mapping = new Mapping({\n  id: 1,\n  memoryStart: 0n,\n  memoryLimit: 1000n,\n  fileOffset: 0n,\n  filename: stringTable.dedup('app.js')\n})\n\nconst location = new Location({\n  id: 1,\n  mappingId: mapping.id,\n  address: 123n, // Addresses are BigInt\n  line: [\n    new Line({\n      functionId: fun.id,\n      line: 1\n    })\n  ]\n})\n\nconst profile = new Profile({\n  sampleType: [\n    new ValueType({\n      type: stringTable.dedup('samples'),\n      unit: stringTable.dedup('count')\n    })\n  ],\n  sample: [\n    new Sample({\n      locationId: [location.id],\n      value: [1000n] // Values are BigInt\n    })\n  ],\n  mapping: [mapping],\n  location: [location],\n  'function': [fun],\n  stringTable,\n  timeNanos: BigInt(Date.now()) * 1_000_000n,\n  durationNanos: 500_000_000n, // 500ms\n  periodType,\n  period: 1_000_000n, // 1ms period for CPU samples\n  comment: [\n    stringTable.dedup('Example PProf profile')\n  ]\n})\n\n// Encode to Uint8Array\nconst encodedProfile = profile.encode()\nconsole.log('Encoded profile length:', encodedProfile.length)\n\n// Decode from Uint8Array\nconst copied = Profile.decode(encodedProfile)\nconsole.log('Decoded profile sample count:', copied.sample.length)\n\n// Verify string table content\nconsole.log('Decoded string table entry 1:', copied.stringTable.at(1))","lang":"typescript","description":"This quickstart demonstrates how to construct a basic PProf profile programmatically, including defining functions, locations, and samples, utilizing the mandatory StringTable for string deduplication, and handling BigInt for time and address values. It then shows how to encode the profile into a Uint8Array and subsequently decode it, verifying the integrity of the data.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}