Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ updates:
# Check the npm registry for updates once every week on a weekday
schedule:
interval: "weekly"
ignore:
# TypeScript 7 (the native port) is not yet supported by typescript-eslint,
# so major bumps break the lint job (and dependency resolution in CI).
# See https://github.com/typescript-eslint/typescript-eslint/issues/10940
# Re-enable once typescript-eslint ships TS >=7 support.
- dependency-name: "typescript"
update-types: ["version-update:semver-major"]
versioning-strategy: "increase"
labels:
- dependabot
Expand Down
288 changes: 73 additions & 215 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pprof-format",
"version": "2.2.3",
"version": "2.3.0",
"description": "Pure JavaScript pprof encoder and decoder",
"author": "Datadog Inc. <info@datadoghq.com>",
"license": "MIT",
Expand Down Expand Up @@ -58,11 +58,11 @@
"@eslint/eslintrc": "^3.3.6",
"@eslint/js": "^10.0.1",
"@types/node": "^26.1.1",
"@typescript-eslint/eslint-plugin": "^8.63.0",
"@typescript-eslint/eslint-plugin": "^8.65.0",
"@typescript-eslint/parser": "^8.37.0",
"eslint": "^10.7.0",
"protobufjs": "^8.7.0",
"protobufjs-cli": "^2.6.0",
"protobufjs": "^8.7.1",
"protobufjs-cli": "^2.6.1",
"tshy": "^4.1.3",
"typescript": "^6.0.3"
}
Expand Down
25 changes: 24 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ test('Label', async (t) => {

const lineData = {
functionId: 1234,
line: 5678
line: 5678,
column: 90
}

const lineEncodings = [
{ field: 'functionId', value: '08d209' },
{ field: 'line', value: '10ae2c' },
{ field: 'column', value: '185a' },
]

test('Line', async (t) => {
Expand Down Expand Up @@ -317,6 +319,27 @@ test('Profile', async (t) => {
})
})

test('Profile docUrl', async (t) => {
// doc_url is field 15, an int64 index into the string table: tag byte
// (15 << 3) | kTypeVarInt = 0x78, followed by the varint value.
await t.test('encodes docUrl', () => {
// emptyTableToken excludes the string table so only docUrl is encoded.
const profile = new Profile({
stringTable: new StringTable(emptyTableToken),
docUrl: 5,
})
assert.strictEqual(bufToHex(profile.encode()), '7805')
})

await t.test('decodes docUrl', () => {
assert.strictEqual(Number(Profile.decode(hexToBuf('7805')).docUrl), 5)
})

await t.test('defaults docUrl to 0 when absent', () => {
assert.strictEqual(Number(new Profile().docUrl), 0)
})
})

function encodeStringTable(strings: StringTable) {
return strings.strings.map(s => {
const buf = new TextEncoder().encode(s)
Expand Down
24 changes: 24 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,13 @@ export class Mapping {
export type LineInput = {
functionId?: Numeric
line?: Numeric
column?: Numeric
}

export class Line {
functionId: Numeric
line: Numeric
column: Numeric

static create(data: LineInput): Line {
return data instanceof Line ? data : new Line(data)
Expand All @@ -714,12 +716,14 @@ export class Line {
constructor(data: LineInput) {
this.functionId = data.functionId || 0
this.line = data.line || 0
this.column = data.column || 0
}

get length() {
let total = 0
total += measureNumberField(this.functionId)
total += measureNumberField(this.line)
total += measureNumberField(this.column)
return total
}

Expand All @@ -734,6 +738,11 @@ export class Line {
offset = encodeNumber(buffer, offset, this.line)
}

if (this.column) {
buffer[offset++] = 24 // (3 << 3) + kTypeVarInt
offset = encodeNumber(buffer, offset, this.column)
}

return offset
}

Expand All @@ -750,6 +759,9 @@ export class Line {
case 2:
data.line = decodeNumber(buffer)
break
case 3:
data.column = decodeNumber(buffer)
break
}
}

Expand Down Expand Up @@ -958,6 +970,7 @@ export type ProfileInput = {
period?: Numeric
comment?: Array<Numeric>
defaultSampleType?: Numeric
docUrl?: Numeric
}

export class Profile {
Expand All @@ -975,6 +988,7 @@ export class Profile {
period: Numeric
comment: Array<Numeric>
defaultSampleType: Numeric
docUrl: Numeric

constructor(data: ProfileInput = {}) {
this.sampleType = (data.sampleType || []).map(ValueType.create)
Expand All @@ -991,6 +1005,7 @@ export class Profile {
this.period = data.period || 0
this.comment = data.comment || []
this.defaultSampleType = data.defaultSampleType || 0
this.docUrl = data.docUrl || 0
}

get length() {
Expand All @@ -1009,6 +1024,7 @@ export class Profile {
total += measureNumberField(this.period)
total += measureNumberArrayField(this.comment)
total += measureNumberField(this.defaultSampleType)
total += measureNumberField(this.docUrl)
return total
}

Expand Down Expand Up @@ -1102,6 +1118,11 @@ export class Profile {
offset = encodeNumber(buffer, offset, this.defaultSampleType)
}

if (this.docUrl) {
buffer[offset++] = 120 // (15 << 3) + kTypeVarInt
offset = encodeNumber(buffer, offset, this.docUrl)
}

return offset
}

Expand Down Expand Up @@ -1197,6 +1218,9 @@ export class Profile {
case 14:
data.defaultSampleType = decodeNumber(buffer)
break
case 15:
data.docUrl = decodeNumber(buffer)
break
}
}

Expand Down
12 changes: 12 additions & 0 deletions testing/proto/profile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export namespace perftools {

/** Profile defaultSampleType */
defaultSampleType?: (number|Long|null);

/** Profile docUrl */
docUrl?: (number|Long|null);
}

/** Represents a Profile. */
Expand Down Expand Up @@ -103,6 +106,9 @@ export namespace perftools {
/** Profile defaultSampleType. */
public defaultSampleType: (number|Long);

/** Profile docUrl. */
public docUrl: (number|Long);

/**
* Creates a new Profile instance using the specified properties.
* @param [properties] Properties to set
Expand Down Expand Up @@ -788,6 +794,9 @@ export namespace perftools {

/** Line line */
line?: (number|Long|null);

/** Line column */
column?: (number|Long|null);
}

/** Represents a Line. */
Expand All @@ -805,6 +814,9 @@ export namespace perftools {
/** Line line. */
public line: (number|Long);

/** Line column. */
public column: (number|Long);

/**
* Creates a new Line instance using the specified properties.
* @param [properties] Properties to set
Expand Down
Loading
Loading