Skip to content

Commit

Permalink
Add some interoperability tests with protobufjs (#13)
Browse files Browse the repository at this point in the history
Check that profiles encoded with pprof-format can be decoded by
protobufjs and that pprof-format can decode profiles encoded with
protobufjs.
  • Loading branch information
nsavoire committed Feb 24, 2023
1 parent eb0f369 commit 76ea22d
Show file tree
Hide file tree
Showing 8 changed files with 4,459 additions and 1 deletion.
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.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
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

0 comments on commit 76ea22d

Please sign in to comment.