Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0.7 proposal #14

Merged
merged 3 commits into from
Feb 27, 2023
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
2 changes: 2 additions & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ dev,@types/tap,MIT,Copyright 2022 zkldi
dev,@typescript-eslint/eslint-plugin,MIT,Copyright 2022 TypeScript ESLint Authors
dev,@typescript-eslint/parser,MIT,Copyright 2022 TypeScript ESLint Authors
dev,eslint,MIT,Copyright 2022 Nicholas C. Zakas <nicholas+npm@nczconsulting.com>
dev,protobufjs,BSD-3-Clause,Copyright 2016 Daniel Wirtz
dev,tap,ISC,Copyright 2022 Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)
dev,typescript,Apache-2.0,Copyright 2022 Microsoft Corp.
file,profile.proto,Apache license 2.0,Copyright 2016 Google Inc.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pprof-format",
"version": "2.0.6",
"version": "2.0.7",
"description": "Pure JavaScript pprof encoder and decoder",
"author": "Datadog Inc. <info@datadoghq.com>",
"license": "MIT",
Expand All @@ -18,7 +18,8 @@
"lint": "eslint src",
"prepublishOnly": "yarn build",
"pretest": "yarn build",
"test": "node dist/index.test.js"
"test": "node dist/index.test.js",
"proto": "mkdir -p proto && pbjs -t static-module -w commonjs -o testing/proto/profile.js testing/proto/profile.proto && pbts -o testing/proto/profile.d.ts testing/proto/profile.js"
},
"homepage": "https://github.com/DataDog/pprof-format#readme",
"repository": {
Expand All @@ -39,6 +40,8 @@
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"eslint": "^8.25.0",
"protobufjs": "^7.2.2",
"protobufjs-cli": "^1.1.1",
"tap": "^16.3.0",
"typescript": "^4.8.4"
}
Expand Down
28 changes: 28 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

import tap from 'tap'
import type Tap from 'tap'
import {perftools} from '../testing/proto/profile';
import { gunzipSync } from 'zlib';
import * as fs from 'fs';

const {decode, toObject} = perftools.profiles.Profile

import {
Function,
Expand Down Expand Up @@ -366,3 +371,26 @@ tap.test('StringTable', (t: TestSuite) => {

t.end()
})

function profileToObject(profile: any): Object {
profile.stringTable = profile.stringTable.strings
return profile
}

tap.test('Protobufjs compat', (t: TestSuite) => {
t.test('encodes correctly', (t: TestSuite) => {
const profile = new Profile(profileData)
const encodedProfile = profile.encode()
const decodedProfile = decode(encodedProfile)
t.same(profileToObject(profile), toObject(decodedProfile, {longs: String, defaults: true}))
t.end()
})

t.test('decodes correctly', (t: TestSuite) => {
const buf = gunzipSync(fs.readFileSync('./testing/test.pprof'))
t.same(profileToObject(Profile.decode(buf)), toObject(decode(buf), {longs: String, defaults: true}))
t.end()
})

t.end()
})
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ function decodeNumbers(buffer: Uint8Array): Array<Numeric> {
}

function push<T>(value: T, list?: Array<T>): Array<T> {
return Array.isArray(list) ? list.concat(value) : [value]
if (list == null) {
return [value]
}
list.push(value)
return list
}

function measureNumber(number: Numeric): number {
Expand Down
12 changes: 12 additions & 0 deletions testing/proto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Files in this directory are generated files. Do not edit.

To regenerate, use the `proto` run script in package.json.

URL: https://github.com/google/pprof/tree/c70cbc2c12c3c07c76269944233837844e7dcb29
Version: 272c2bb11d7e48683b20ad8c82e50bf40e2fe802
License: Apache 2.0
License File: # LICENSE
Description:
pprof is a tool for visualization and analysis of profiling data.
Local Modifications:
All code except the profile.proto file has been removed.
Loading
Loading