New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cpu-timer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cpu-timer - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

42

cpu-timer.js

@@ -25,3 +25,3 @@ const os = require( 'os' ) // for cpu average

var total = 0
var used = 0
var idle = 0

@@ -32,14 +32,8 @@

var sum = (
times.user +
times.nice +
times.sys +
times.idle +
times.irq
)
var sum = 0
for ( type in cpu.times ) {
total += cpu.times[ type ]
sum += cpu.times[ type ]
}
used += sum - times.idle
idle += times.idle

@@ -50,4 +44,4 @@ })

timestamp: Date.now(),
idle: ( idle / cpus.length ),
total: ( total / cpus.length )
idle: ( idle ),
used: ( used )
}

@@ -71,11 +65,11 @@

var idleDiff = ( avg.idle - _lastCpuAverage.idle )
var totalDiff = ( avg.total / _lastCpuAverage.total )
var diff = ( idleDiff / totalDiff )
var idleDiff = ( avg.idle - _lastCpuAverage.idle ) + 1
var usedDiff = ( avg.used - _lastCpuAverage.used ) + 0.1
var delta = ( now - _lastCpuUsageTime )
var limit = ( delta ) // milliseconds
var pct = (
String( 100 * ( usedDiff / ( usedDiff + idleDiff ) ) )
.trim()
.slice( 0, 6 )
)
var pct = String( 100 * ( 1 - ( diff / limit ) ) ).trim().slice( 0, 6 )
_lastCpuAverage = avg

@@ -92,8 +86,12 @@ _lastCpuAverageTime = now

var total = ( cpuUsage.user + cpuUsage.system )
var diff = ( total - prevTotal )
var diff = ( total - prevTotal ) + 0.01
var delta = ( now - _lastCpuUsageTime )
var limit = ( delta * 1000 ) // microseconds
var limit = ( delta * 1000 ) + 0.1 // microseconds to milliseconds
var pct = String( 100 * ( diff / limit ) ).trim().slice( 0, 6 )
var pct = (
String( 100 * ( diff / limit ) )
.trim()
.slice( 0, 6 )
)

@@ -100,0 +98,0 @@ _lastCpuUsage = cpuUsage

{
"name": "cpu-timer",
"version": "0.0.2",
"version": "0.0.3",
"description": "TODO",

@@ -12,2 +12,5 @@ "main": "cpu-timer.js",

],
"files": [
"cpu-timer.js"
],
"author": "talmobi <talmo.christian@gmail.com>",

@@ -14,0 +17,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc