Browse Source

[IMP] count all child processes' resources

pull/302/head
Holger Brunn 9 years ago
parent
commit
b91d4848b1
  1. 14
      dead_mans_switch_client/models/dead_mans_switch_client.py

14
dead_mans_switch_client/models/dead_mans_switch_client.py

@ -26,15 +26,21 @@ class DeadMansSwitchClient(models.AbstractModel):
if psutil:
process = psutil.Process(os.getpid())
# psutil changed its api through versions
processes = [process]
if process.parent:
if hasattr(process.parent, '__call__'):
process = process.parent()
else:
process = process.parent
if hasattr(process, 'memory_percent'):
ram = process.memory_percent()
if hasattr(process, 'cpu_percent'):
cpu = process.cpu_percent()
if hasattr(process, 'children'):
processes += process.children(True)
elif hasattr(process, 'get_children'):
processes += process.get_children(True)
for process in processes:
if hasattr(process, 'memory_percent'):
ram += process.memory_percent()
if hasattr(process, 'cpu_percent'):
cpu += process.cpu_percent()
user_count = 0
if 'im_chat.presence' in self.env.registry:
user_count = len(self.env['im_chat.presence'].search([

Loading…
Cancel
Save