Skip to content

Commit 6e374db

Browse files
committed
Merge pull request #24 from SteveGuo/master
fixed the bug#23
2 parents 186d27e + cec1210 commit 6e374db

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ https://launchpad.net/indicator-sysmonitor
1111

1212
Current fork maintainer: fossfreedom <[email protected]>
1313

14+
v0.6.3: SteveGuo <[email protected]>
15+
https://github.com/SteveGuo
16+
1417
----
1518

16-
Installation - v0.6.2 stable
19+
Installation - v0.6.3 stable
1720

1821
on Ubuntu and derivatives - manual installation
1922

@@ -39,6 +42,7 @@ To install via PPA:
3942

4043
Changelog
4144

45+
- v0.6.3 - fixed the bug when display multiple CPU cores it always display the later ones as 0%
4246
- v0.6.2 - bug fix to stop crash for custom sensors
4347
- v0.6.1 - fix the debian packaging
4448
- v0.6 - stable release - reworked to be easier to maintain

preferences.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from sensors import ISMError
2222

2323

24-
VERSION = '0.6.2~stable'
24+
VERSION = '0.6.3~stable'
2525

2626

2727
def raise_dialog(parent, flags, type_, buttons, msg, title):

sensors.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626

2727
B_UNITS = ['', 'KB', 'MB', 'GB', 'TB']
28+
cpu_load = []
2829

2930
def bytes_to_human(bytes_):
3031
unit = 0
@@ -75,8 +76,6 @@ def __init__(self):
7576
self.settings['sensors'][sensor.name] = (sensor.desc, sensor.cmd)
7677

7778
#self.update_regex()
78-
79-
self.last = ps.cpu_times()
8079
self._last_net_usage = [0, 0] # (up, down)
8180

8281
#@staticmethod
@@ -255,11 +254,18 @@ def get_results(self):
255254
res = {}
256255
from preferences import Preferences
257256

257+
global cpu_load
258+
cpu_checked = False
259+
cpus = re.compile("\Acpu\d*\Z")
260+
258261
#print (self.settings["custom_text"]) custom_text is the full visible string seen in Preferences edit field
259262
for sensor in Preferences.sensors_regex.findall(
260263
self.settings["custom_text"]):
261264

262265
sensor = sensor[1:-1]
266+
if cpus.match(sensor) and cpu_checked == False:
267+
cpu_load = ps.cpu_percent(interval = 0, percpu = True) # We call this only once per update
268+
cpu_checked = True
263269

264270
instance = self.get(sensor)
265271

@@ -354,31 +360,15 @@ def get_value(self, sensor):
354360

355361
def _fetch_cpu(self, percpu=False):
356362
if percpu:
357-
return ps.cpu_percent(interval=0, percpu=True)
358-
359-
last = self.last
360-
current = ps.cpu_times()
361-
if not last:
362-
last = current
363-
364-
total_time_passed = sum(
365-
[v - last.__dict__[k]
366-
if not isinstance(v, list)
367-
else 0
368-
for k, v in current.__dict__.items()])
369-
370-
sys_time = current.system - last.system
371-
usr_time = current.user - last.user
363+
return cpu_load
372364

373-
self.last = current
365+
r = 0.0;
366+
for i in cpu_load:
367+
r += i
374368

375-
if total_time_passed > 0:
376-
sys_percent = 100 * sys_time / total_time_passed
377-
usr_percent = 100 * usr_time / total_time_passed
378-
return sys_percent + usr_percent
379-
else:
380-
return 0
369+
r /= ps.NUM_CPUS
381370

371+
return r
382372

383373
class MemSensor(BaseSensor):
384374
name = 'mem'
@@ -547,4 +537,4 @@ def run(self):
547537
while self._parent.alive.isSet():
548538
data = self.fetch()
549539
self._parent.update(data)
550-
time.sleep(self.mgr.get_interval())
540+
time.sleep(self.mgr.get_interval())

0 commit comments

Comments
 (0)