Skip to content

Commit

Permalink
WIP: dump: added new command
Browse files Browse the repository at this point in the history
The dump command dumps active profile. It's good for debugging, because
the output is flattened, i.e. it shows the resulting profile after
inheritance (profiles merging) is processed.

It keeps naming conventions - for tuned-adm it's named 'dump' action,
for API it's named 'dump_profile' method.

The 'priority' value is not output, but output is ordered according to
it.

The 'cpuinfo_regex' and 'uname_regex' are not output, but output is
rendered according to it.

Variables are not expanded.

Signed-off-by: Jaroslav Škarvada <[email protected]>
  • Loading branch information
yarda committed May 23, 2024
1 parent 1fb7c80 commit d1a63c7
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 0 deletions.
10 changes: 10 additions & 0 deletions com.redhat.tuned.policy
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@
</defaults>
</action>

<action id="com.redhat.tuned.dump_profile">
<description>Dump TuneD profile</description>
<message>Authentication is required to dump TuneD profile</message>
<defaults>
<allow_any>yes</allow_any>
<allow_inactive>yes</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>

<action id="com.redhat.tuned.verify_profile_ignore_missing">
<description>Verify TuneD profile, ignore missing values</description>
<message>Authentication is required to verify TuneD profile</message>
Expand Down
3 changes: 3 additions & 0 deletions tuned-adm.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def check_log_level(value):
parser_verify.set_defaults(action="verify_profile")
parser_verify.add_argument("--ignore-missing", "-i", action="store_true", help="do not treat missing/non-supported tunings as errors")

parser_dump = subparsers.add_parser("dump", help="dump current profile")
parser_dump.set_defaults(action="dump")

parser_auto_profile = subparsers.add_parser("auto_profile", help="enable automatic profile selection mode, switch to the recommended profile")
parser_auto_profile.set_defaults(action="auto_profile")

Expand Down
12 changes: 12 additions & 0 deletions tuned/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,18 @@ def _action_verify_profile(self, ignore_missing):
print("Not supported in no_daemon mode.")
return False

def _action_dbus_dump(self):
(ret, msg) = self._controller.dump()
if ret:
print(msg)
else:
self._error("Unable to dump profile: '%s'" % msg)
return self._controller.exit(ret)

def _action_dump(self):
print("Not supported in no_daemon mode.")
return False

def _action_dbus_off(self):
# 25 seconds default DBus timeout + 5 secs safety margin
timeout = 25 + 5
Expand Down
3 changes: 3 additions & 0 deletions tuned/admin/dbus_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def recommend_profile(self):
def verify_profile(self):
return self._call("verify_profile")

def dump(self):
return self._call("dump_profile")

def verify_profile_ignore_missing(self):
return self._call("verify_profile_ignore_missing")

Expand Down
6 changes: 6 additions & 0 deletions tuned/daemon/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ def verify_profile_ignore_missing(self, caller = None):
return False
return self._daemon.verify_profile(ignore_missing = True)

@exports.export("", "(bs)")
def dump_profile(self, caller = None):
if caller == "":
return False
return self._daemon.dump_profile()

@exports.export("", "a{sa{ss}}")
def get_all_plugins(self, caller = None):
"""Return dictionary with accesible plugins
Expand Down
24 changes: 24 additions & 0 deletions tuned/daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,30 @@ def verify_profile(self, ignore_missing):
self._not_used.set()
return ret

def dump_profile(self):
if not self.is_running():
s = "TuneD is not running"
log.error(s)
return (False, s)

if self._profile is None:
s = "no profile is set"
log.error(s)
return (False, s)

if not self._profile_applied.is_set():
s = "profile is not applied"
log.error(s)
return (False, s)

# using daemon, the main loop mustn't exit before our completion
self._not_used.clear()
log.info("dumping profile(s): %s" % self._profile.name)
s = self._unit_manager.dump_tuning()
# main loop is allowed to exit
self._not_used.set()
return (True, s)

# profile_switch is helper telling plugins whether the stop is due to profile switch
def stop(self, profile_switch = False):
if not self.is_running():
Expand Down
21 changes: 21 additions & 0 deletions tuned/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,27 @@ def instance_verify_tuning(self, instance, ignore_missing):
else:
return None

def instance_dump_tuning(self, instance):
"""
Dump tuning if the plugin instance is active.
"""
if not instance.active:
return ""

s = "[%s]\n" % instance.name
s += "type = %s\n" % self.name
if instance._devices_expression:
s += "devices = %s\n" % instance._devices_expression
if instance._devices_udev_regex:
s += "devices_udev_regex = %s\n" % instance._devices_udev_regex
if instance._script_pre:
s += "script_pre = %s\n" % instance._script_pre
if instance._script_post:
s += "script_post = %s\n" % instance._script_post
for option, val in instance._options.items():
s += "%s = %s\n" % (option, val)
return s

def instance_update_tuning(self, instance):
"""
Apply dynamic tuning if the plugin instance is active.
Expand Down
3 changes: 3 additions & 0 deletions tuned/plugins/instance/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def apply_tuning(self):
def verify_tuning(self, ignore_missing):
return self._plugin.instance_verify_tuning(self, ignore_missing)

def dump_tuning(self):
return self._plugin.instance_dump_tuning(self)

def update_tuning(self):
self._plugin.instance_update_tuning(self)

Expand Down
7 changes: 7 additions & 0 deletions tuned/units/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ def verify_tuning(self, ignore_missing):
ret = False
return ret

def dump_tuning(self):
s = ""
for instance in self._instances:
s += self._try_call("dump_tuning", None,
instance.dump_tuning) + "\n"
return s[:-1]

def update_tuning(self):
for instance in self._instances:
self._try_call("update_tuning", None,
Expand Down

0 comments on commit d1a63c7

Please sign in to comment.