Skip to content

Commit

Permalink
Looks beter after the last commit ! Some TODO to do in the glances_re…
Browse files Browse the repository at this point in the history
…stful_api.py files...
  • Loading branch information
nicolargo committed Dec 10, 2023
1 parent cbb2fac commit 1f1622a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 6 additions & 2 deletions glances/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# SPDX-License-Identifier: LGPL-3.0-only
#

from collections import Counter

# from glances.logger import logger

# This constant defines the list of available processes sort key
Expand Down Expand Up @@ -35,14 +37,15 @@ def create_program_dict(p):
'status': p['status'],
}


def update_program_dict(program, p):
"""Update an existing entry in the dict (existing program)"""
# some values can be None, e.g. macOS system processes
program['num_threads'] += p['num_threads'] or 0
program['cpu_percent'] += p['cpu_percent'] or 0
program['memory_percent'] += p['memory_percent'] or 0
program['cpu_times'] += p['cpu_times'] or ()
program['memory_info'] += p['memory_info'] or ()
program['cpu_times'] = dict(Counter(program['cpu_times']) + Counter(p['cpu_times']))
program['memory_info'] = dict(Counter(program['memory_info']) + Counter(p['memory_info']))

program['io_counters'] += p['io_counters']
program['childrens'].append(p['pid'])
Expand All @@ -51,6 +54,7 @@ def update_program_dict(program, p):
program['nice'] = p['nice'] if p['nice'] == program['nice'] else '_'
program['status'] = p['status'] if p['status'] == program['status'] else '_'


def processes_to_programs(processes):
"""Convert a list of processes to a list of programs."""
# Start to build a dict of programs (key is program name)
Expand Down
6 changes: 2 additions & 4 deletions unitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,8 @@ def test_017_programs(self):
# stats_to_check = [ ]
print('INFO: [TEST_017] Check PROGRAM stats')
stats_grab = processes_to_programs(stats.get_plugin('processlist').get_raw())
self.assertTrue(type(stats_grab) is list, msg='Programs stats is not a list')
print('INFO: PROGRAM list stats: %s items in the list' % len(stats_grab))
# Check if number of processes in the list equal counter
# self.assertEqual(total, len(stats_grab))
self.assertIsInstance(stats_grab, list, msg='Programs stats list is not a list')
self.assertIsInstance(stats_grab[0], dict, msg='First item should be a dict')

def test_018_string_value_to_float(self):
"""Check string_value_to_float function"""
Expand Down

0 comments on commit 1f1622a

Please sign in to comment.