Skip to content

Instantly share code, notes, and snippets.

@rjdp
Created February 5, 2023 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjdp/59e1f8fce057724907ee7b5e1401e650 to your computer and use it in GitHub Desktop.
Save rjdp/59e1f8fce057724907ee7b5e1401e650 to your computer and use it in GitHub Desktop.
Sample express app with pprof endpoint instrumentation using Pyroscope
const express = require('express')
const app = express()
const port = 3002
const Pyroscope= require('@pyroscope/nodejs');
Pyroscope.init({ tags: { region: 'us-east-1' } })
app.use(Pyroscope.expressMiddleware())
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.get('/primes', (req, res) => {
let to = req.query.to ? Number(req.query.to) : 100;
res.send(prime_number_from_1_to(to))
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
function divisible(i, j){
return i % j == 0
}
function prime_number_from_1_to(to=100){
let prime_numbers = []
for (let i=1; i<to; i++) {
if (i > 1) {
let not_div = true;
for (let j=2; j<i; j++) {
if (divisible(i, j)){
not_div = false;
break;
}
}
if (not_div) {
prime_numbers.push(i)
}
}
}
return prime_numbers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment