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 }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"coverage": "pnpm tsx scripts/coverage.ts",
"docs": "typedoc",
"e2e-test": "pnpm exec playwright test --fail-on-flaky-tests",
"flamegraph": "./scripts/flamegraph.sh",
"flamegraph": "pnpm tsx packages/object/tests/hashgraph.flamegraph.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"postinstall": "pnpm build:packages",
Expand Down
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