Skip to content

Commit

Permalink
recommend: added support for matching of processes
Browse files Browse the repository at this point in the history
E.g.:

[myprofile]
process=myprocess1
process2=myprocess2.*

The myprofile will be recommended if there are 'myprocess1' and
'myprocess2.*' (e.g. myprocess2, myprocess21, myprocess2_whatever)
running.

Resolves: rhbz#1461838

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
  • Loading branch information
yarda committed Jun 15, 2017
1 parent c315f62 commit 5a2ea01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
25 changes: 17 additions & 8 deletions recommend.conf
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# Tuned rules for recommend_profile.
#
# The 'virt' RE matches virt-what output.
# The 'system' RE matches content of /etc/system-release-cpe.
# Syntax:
# [PROFILE1]
# KEYWORD11=RE11
# KEYWORD21=RE12
#
# If the parameter starts with '/' it means path to file which content is
# checked, e.g.:
# /etc/passwd=.+
# If file doesn't exist, its RE will not match.
#
# Al 'virt', 'system' and files have to match for profile to match.
# [PROFILE2]
# KEYWORD21=RE21
# KEYWORD22=RE22

# KEYWORD can be:
# virt - for RE to match output of virt-what
# system - for RE to match content of /etc/system-release-cpe
# process - for RE to match running processes. It can have arbitrary suffix, all
# process* lines have to match for the PROFILE to match (i.e. the AND operator)
# /FILE - for RE to match content of the FILE, e.g.: '/etc/passwd=.+'. If file doesn't
exist, its RE will not match.

# All REs for all KEYWORDs have to match for PROFILE to match (i.e. the AND operator).
# If 'virt' or 'system' is not specified, it matches for every string.
# If 'virt' or 'system' is empty, i.e. 'virt=', it matches only empty string (alias for '^$').
# If several profiles matched, the first match is taken.
Expand Down
6 changes: 6 additions & 0 deletions tuned/utils/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tuned.consts as consts
from configobj import ConfigObj, ConfigObjError
import re
import procfs
from subprocess import *

log = tuned.logs.get()
Expand Down Expand Up @@ -387,6 +388,11 @@ def recommend_profile(self, hardcoded = False):
elif option[0] == "/":
if not os.path.exists(option) or not re.match(value, self.read_file(option), re.S):
match = False
elif option[0:7] == "process":
ps = procfs.pidstats()
ps.reload_threads()
if len(ps.find_by_regex(re.compile(value))) == 0:
match = False
if match:
# remove the ",.*" suffix
profile = r.sub("", section)
Expand Down

1 comment on commit 5a2ea01

@jmencak
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested and works. Thanks!

Please sign in to comment.