Dan Kenigsberg has posted comments on this change.
Change subject: make misc.pgrep for general usage ......................................................................
Patch Set 1: I would prefer that you didn't submit this
(3 inline comments)
.................................................... File vdsm/storage/misc.py Line 1108: pid = os.path.basename(path) Line 1109: yield int(pid) Line 1110: Line 1111: Line 1112: def pgrep(statValue, statKey='name'): I prefer (value, field) and a little doctring explaining that the fields are from /proc/[pid]/stats/ Line 1113: res = [] Line 1114: statMap = {'name': 1, 'state': 2, 'ppid': 3} Line 1115: statIndex = statMap.get(statKey, 1) Line 1116: for pid in iteratePids():
Line 1111: Line 1112: def pgrep(statValue, statKey='name'): Line 1113: res = [] Line 1114: statMap = {'name': 1, 'state': 2, 'ppid': 3} Line 1115: statIndex = statMap.get(statKey, 1) if someone gave an illegal field name, we should die, not assume that he meant "name". Line 1116: for pid in iteratePids(): Line 1117: try: Line 1118: pid = int(pid) Line 1119: except ValueError:
Line 1119: except ValueError: Line 1120: continue Line 1121: Line 1122: try: Line 1123: watchedStat = utils.pidStat(pid)[statIndex] I think it would be much nicer to have pidStat return a namedtuple, with fieldnames taken from proc(5). It would make other usages of pidStat nicer, too.
pid comm state ppid pgrp session tty_nr tpgid flags minflt cminflt majflt cmajflt utime stime cutime cstime priority nice num_threads itrealvalue starttime vsize rss rsslim startcode endcode startstack kstkesp kstkeip signal blocked sigignore sigcatch wchan nswap cnswap exit_signal processor rt_priority policy delayacct_blkio_ticks guest_time cguest_time Line 1124: if watchedStat == statValue: Line 1125: res.append(pid) Line 1126: except (OSError, IOError): Line 1127: continue
-- To view, visit http://gerrit.ovirt.org/11033 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I2034b04a4787d2f222cb98dfe3ffcdbb2a94ebb8 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Royce Lv lvroyce@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: oVirt Jenkins CI Server