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

feat: flamegraph pprof #453

Merged
merged 16 commits into from
Feb 12, 2025
36 changes: 36 additions & 0 deletions .github/workflows/flamegraph-upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Flamegraph Upload
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
flamegraph-upload:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
- uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"

- shell: bash
run: |
pnpm install --no-frozen-lockfile

- shell: bash
run: |
pnpm run flamegraph

- uses: pyroscope-io/flamegraph.com-github-action@main
with:
file: flamegraph.pprof
postInPR: false
token: ${{ secrets.GITHUB_TOKEN }}
162 changes: 81 additions & 81 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
{
"name": "ts-drp",
"description": "The official TypeScript implementation of DRP protocol",
"version": "0.7.0",
"license": "MIT",
"homepage": "https://topology.gg/",
"repository": {
"type": "git",
"url": "git+https://github.com/topology-foundation/ts-drp.git"
},
"bugs": {
"url": "https://github.com/topology-foundation/ts-drp/issues"
},
"workspaces": [
"packages/*",
"examples/*"
],
"type": "module",
"scripts": {
"bench": "vitest bench",
"build": "pnpm build:packages && pnpm build:examples",
"build:examples": "pnpm --filter 'ts-drp-example*' build",
"build:packages": "pnpm --filter '@ts-drp/*' build",
"clean": "pnpm --filter '@ts-drp/*' clean && rm -r node_modules/ docs/",
"cli": "tsx ./packages/node/src/run.ts",
"coverage": "pnpm tsx scripts/coverage.ts",
"docs": "typedoc",
"e2e-test": "pnpm exec playwright test --fail-on-flaky-tests",
"flamegraph": "./scripts/flamegraph.sh",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"postinstall": "pnpm build:packages",
"proto-gen": "pnpm proto-gen:object && pnpm proto-gen:network",
"proto-gen:network": "buf generate packages/network/src/proto -o packages/network/src/proto",
"proto-gen:object": "buf generate packages/object/src/proto -o packages/object/src/proto",
"release": "release-it",
"test": "vitest",
"watch": "pnpm --parallel --filter '@ts-drp/*' watch"
},
"devDependencies": {
"@playwright/test": "^1.49.1",
"@release-it-plugins/workspaces": "^4.2.0",
"@types/node": "^22.5.4",
"@typescript-eslint/parser": "^8.21.0",
"@vitest/coverage-v8": "3.0.5",
"assemblyscript": "^0.27.29",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-unused-imports": "^4.1.4",
"eslint-plugin-vitest": "^0.5.4",
"globals": "^15.14.0",
"release-it": "^17.6.0",
"ts-node": "^10.9.2",
"ts-proto": "^2.2.4",
"tsx": "4.19.1",
"typedoc": "^0.26.6",
"typescript": "^5.5.4",
"typescript-eslint": "^8.21.0",
"vite": "^6.0.9",
"vite-tsconfig-paths": "^5.0.1",
"vitest": "^3.0.5"
},
"private": true,
"release-it": {
"hooks": {
"after:bump": "pnpm lint --fix"
},
"plugins": {
"@release-it-plugins/workspaces": {
"publish": false
}
},
"npm": false,
"git": {
"commitMessage": "chore: release v${version}"
},
"github": {
"release": true
}
}
"name": "ts-drp",
"description": "The official TypeScript implementation of DRP protocol",
"version": "0.7.0",
"license": "MIT",
"homepage": "https://topology.gg/",
"repository": {
"type": "git",
"url": "git+https://github.com/topology-foundation/ts-drp.git"
},
"bugs": {
"url": "https://github.com/topology-foundation/ts-drp/issues"
},
"workspaces": [
"packages/*",
"examples/*"
],
"type": "module",
"scripts": {
"bench": "vitest bench",
"build": "pnpm build:packages && pnpm build:examples",
"build:examples": "pnpm --filter 'ts-drp-example*' build",
"build:packages": "pnpm --filter '@ts-drp/*' build",
"clean": "pnpm --filter '@ts-drp/*' clean && rm -r node_modules/ docs/",
"cli": "tsx ./packages/node/src/run.ts",
"coverage": "pnpm tsx scripts/coverage.ts",
"docs": "typedoc",
"e2e-test": "pnpm exec playwright test --fail-on-flaky-tests",
"flamegraph": "pnpm tsx packages/object/tests/hashgraph.flamegraph.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"postinstall": "pnpm build:packages",
"proto-gen": "pnpm proto-gen:object && pnpm proto-gen:network",
"proto-gen:network": "buf generate packages/network/src/proto -o packages/network/src/proto",
"proto-gen:object": "buf generate packages/object/src/proto -o packages/object/src/proto",
"release": "release-it",
"test": "vitest",
"watch": "pnpm --parallel --filter '@ts-drp/*' watch"
},
"devDependencies": {
"@playwright/test": "^1.49.1",
"@release-it-plugins/workspaces": "^4.2.0",
"@types/node": "^22.5.4",
"@typescript-eslint/parser": "^8.21.0",
"@vitest/coverage-v8": "3.0.5",
"assemblyscript": "^0.27.29",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-unused-imports": "^4.1.4",
"eslint-plugin-vitest": "^0.5.4",
"globals": "^15.14.0",
"release-it": "^17.6.0",
"ts-node": "^10.9.2",
"ts-proto": "^2.2.4",
"tsx": "4.19.1",
"typedoc": "^0.26.6",
"typescript": "^5.5.4",
"typescript-eslint": "^8.21.0",
"vite": "^6.0.9",
"vite-tsconfig-paths": "^5.0.1",
"vitest": "^3.0.5"
},
"private": true,
"release-it": {
"hooks": {
"after:bump": "pnpm lint --fix"
},
"plugins": {
"@release-it-plugins/workspaces": {
"publish": false
}
},
"npm": false,
"git": {
"commitMessage": "chore: release v${version}"
},
"github": {
"release": true
}
}
}
20 changes: 20 additions & 0 deletions packages/object/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,23 @@ For starting, you can install it using:
```bash
pnpm install @ts-drp/object
```

## Flamegraph

### Prerequisites

- `Golang` and `pprof` install

### How to run

```
pnpm run flamegraph
```

### Visualize Profile

```
pprof -http=:8080 flamegraph.pb.gz
```
and preview in browser at `http://localhost:8080`

1 change: 1 addition & 0 deletions packages/object/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"es-toolkit": "1.30.1",
"fast-deep-equal": "^3.1.3",
"fast-equals": "^5.2.2",
"pprof": "^4.0.0",
"uint8arrays": "^5.1.0"
}
}
20 changes: 20 additions & 0 deletions packages/object/tests/hashgraph.flamegraph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { SetDRP } from "@ts-drp/blueprints/src/index.js";
import fs from "fs";
import * as pprof from "pprof";

import { DRPObject, ObjectACL } from "../src/index.js";

Expand Down Expand Up @@ -63,4 +65,22 @@ function flamegraphForSetDRP(numDRPs: number, verticesPerDRP: number, mergeFn: b
}
}

async function pprofTime() {
console.log("start to profile >>>");
const profile = await pprof.time.profile({
durationMillis: 1000,
});

const buf = await pprof.encode(profile);
fs.writeFile("flamegraph.pprof", buf, (err) => {
if (err) {
throw err;
}
});

console.log("<<< finished to profile");
}

pprofTime().catch(console.error);

flamegraphForSetDRP(1, 1000, false);
Loading