Skip to content

Commit

Permalink
fix PressureObserver script
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed May 30, 2024
1 parent a780575 commit adc356c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions scripts/pressure-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ window.collectCpuPressure = () => {
return cpuPressure.mean()
}

if ('PressureObserver' in window) {
const STATES = {
nominal: 0,
fair: 1,
serious: 2,
critical: 3,
document.addEventListener('DOMContentLoaded', async () => {
if ('PressureObserver' in window) {
const STATES = {
nominal: 0,
fair: 1,
serious: 2,
critical: 3,
}
const observer = new window.PressureObserver(records => {
const lastRecord = records[records.length - 1]
// log(`Current CPU pressure: ${lastRecord.state}`)
cpuPressure.push(Date.now(), STATES[lastRecord.state])
})
observer.observe('cpu', { sampleInterval: 1000 }).catch(error => {
log(`Pressure observer error: ${error}`)
})
}
const observer = new window.PressureObserver(records => {
const lastRecord = records[records.length - 1]
// log(`Current CPU pressure: ${lastRecord.state}`)
cpuPressure.push(Date.now(), STATES[lastRecord.state])
})
observer.observe('cpu', { sampleInterval: 1000 }).catch(error => {
log(`Pressure observer error: ${error}`)
})
}
})

0 comments on commit adc356c

Please sign in to comment.