Skip to content

Commit

Permalink
feat: flamegraph pprof (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnd350309 authored Feb 12, 2025
1 parent 1d2b0d7 commit f9f9c6c
Show file tree
Hide file tree
Showing 7 changed files with 425 additions and 26 deletions.
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

0 comments on commit f9f9c6c

Please sign in to comment.