From b48cfc207a34bae5bdfa278c78f9020831964c9c Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Wed, 23 Aug 2017 09:05:01 +0200 Subject: [PATCH] fixed cpu().speed windows / AMD, updated docs --- CHANGELOG.md | 1 + README.md | 12 ++++++------ lib/cpu.js | 18 +++++++++++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bdad7f..64367fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.26.1 | 2017-08-23 | fixed `cpu().speed` windows / AMD, updated docs | | 3.26.0 | 2017-08-21 | extended `getDynamicData()` (windows), updated docs | | 3.25.1 | 2017-08-07 | updated docs | | 3.25.0 | 2017-08-07 | improved windows support `networkStats()`, `cpuCache()`, bug fix `getStaticData()` | diff --git a/README.md b/README.md index f30cc60..e9a0334 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Simple system and OS information library for [node.js][nodejs-url] ## Quick Start -Collection of 35+ functions to retrieve detailed hardware, system and OS information (Linux, OSX and partial Windows support) +Lightweight collection of 35+ functions to retrieve detailed hardware, system and OS information (Linux, OSX and partial Windows support) - no npm dependencies. ### Installation @@ -50,7 +50,7 @@ async function cpu() { ## News and Changes ### Latest Activity -- Version 3.26.0: extended `getDynamicData()` (windows), updated docs +- Version 3.26.0: improved windows support `getDynamicData()`, updated docs - Version 3.25.0: improved windows support `networkStats()`, `cpuCache()`, bug fix `getStaticData()` - Version 3.24.0: extended windows support `networkStats()`, `networkConnections()` - Version 3.23.0: added `memLayout`, `diskLayout`, extended windows support (`inetChecksite`) @@ -200,7 +200,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | maxcapacity | X | X | X | max capacity of battery | | | currentcapacity | X | X | X | current capacity of battery | | | percent | X | X | X | charging level in percent | -| si.graphics(cb) | {...} | X | X | | arrays of graphics controllers and displays | +| si.graphics(cb) | {...} | X | X | X | arrays of graphics controllers and displays | | | controllers[0].model | X | X | X | graphics controller model | | | controllers[0].vendor | X | X | X | e.g. ATI | | | controllers[0].bus | X | X | X| on which bus (e.g. PCIe) | @@ -413,7 +413,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( ### cb: Asynchronous Function Calls (callback) -Remember: all functions (except `version` and `time`) are implemented as asynchronous functions! There are now two ways to consume them: +Remember: all functions (except `version` and `time`) are implemented as asynchronous functions! There are now three ways to consume them: **Callback Style** @@ -456,7 +456,7 @@ si.networkStats('eth1') **Using async / await** (available since node v7.6) -Since node 7.6 you can ylso use the `async` / `await pattern. The example would then loog like this: +Since node v7.6 you can also use the `async` / `await` pattern. The example would then look like this: ```js const si = require('systeminformation'); @@ -550,7 +550,7 @@ OSX Temperature: Credits here are going to: Linux is a registered trademark of Linus Torvalds, OS X is a registered trademark of Apple Inc., Windows is a registered trademark of Microsoft Corporation. Node.js is a trademark of Joyent Inc., -Intel is a trademark of Intel Corporation, Raspberry Pi is a trademark of the Raspberry Pi Foundation, +Intel is a trademark of Intel Corporation, AMD is a trademark of Advanced Micro Devices Inc., Raspberry Pi is a trademark of the Raspberry Pi Foundation, Debian is a trademark of the Debian Project, Ubuntu is a trademark of Canonical Ltd., Docker is a trademark of Docker, Inc. All other trademarks are the property of their respective owners. diff --git a/lib/cpu.js b/lib/cpu.js index 6074b51..0e68a94 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -161,10 +161,15 @@ function getCpu() { if (!error) { let lines = stdout.split('\r\n'); let name = getValue(lines, 'name', '=') || ''; - result.brand = name.split('@')[0].trim(); - result.speed = name.split('@')[1].trim(); - result.speed = parseFloat(result.speed.replace(/GHz+/g, "").trim()).toFixed(2); - _cpu_speed = result.speed; + if (name.indexOf('@') >= 0) { + result.brand = name.split('@')[0].trim(); + result.speed = name.split('@')[1].trim(); + result.speed = parseFloat(result.speed.replace(/GHz+/g, "").trim()).toFixed(2); + _cpu_speed = result.speed; + } else { + result.brand = name.split('@')[0].trim(); + result.speed = 0; + } result = cpuBrandManufacturer(result); result.revision = getValue(lines, 'revision', '='); result.cache.l1d = 0; @@ -175,7 +180,10 @@ function getCpu() { if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * 1024} result.vendor = getValue(lines, 'manufacturer', '='); result.speedmax = Math.round(parseFloat(getValue(lines, 'maxclockspeed', '=').replace(/,/g, '.')) / 10.0) / 100; - result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : '' + result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : ''; + if (!result.speed) { + result.speed = result.speedmax + } let description = getValue(lines, 'description', '=').split(' '); for (let i = 0; i < description.length; i++) {