Skip to content

Commit d1a63c7

Browse files
committed
WIP: dump: added new command
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]>
1 parent 1fb7c80 commit d1a63c7

File tree

9 files changed

+89
-0
lines changed

9 files changed

+89
-0
lines changed

com.redhat.tuned.policy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@
177177
</defaults>
178178
</action>
179179

180+
<action id="com.redhat.tuned.dump_profile">
181+
<description>Dump TuneD profile</description>
182+
<message>Authentication is required to dump TuneD profile</message>
183+
<defaults>
184+
<allow_any>yes</allow_any>
185+
<allow_inactive>yes</allow_inactive>
186+
<allow_active>yes</allow_active>
187+
</defaults>
188+
</action>
189+
180190
<action id="com.redhat.tuned.verify_profile_ignore_missing">
181191
<description>Verify TuneD profile, ignore missing values</description>
182192
<message>Authentication is required to verify TuneD profile</message>

tuned-adm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def check_log_level(value):
9191
parser_verify.set_defaults(action="verify_profile")
9292
parser_verify.add_argument("--ignore-missing", "-i", action="store_true", help="do not treat missing/non-supported tunings as errors")
9393

94+
parser_dump = subparsers.add_parser("dump", help="dump current profile")
95+
parser_dump.set_defaults(action="dump")
96+
9497
parser_auto_profile = subparsers.add_parser("auto_profile", help="enable automatic profile selection mode, switch to the recommended profile")
9598
parser_auto_profile.set_defaults(action="auto_profile")
9699

tuned/admin/admin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,18 @@ def _action_verify_profile(self, ignore_missing):
375375
print("Not supported in no_daemon mode.")
376376
return False
377377

378+
def _action_dbus_dump(self):
379+
(ret, msg) = self._controller.dump()
380+
if ret:
381+
print(msg)
382+
else:
383+
self._error("Unable to dump profile: '%s'" % msg)
384+
return self._controller.exit(ret)
385+
386+
def _action_dump(self):
387+
print("Not supported in no_daemon mode.")
388+
return False
389+
378390
def _action_dbus_off(self):
379391
# 25 seconds default DBus timeout + 5 secs safety margin
380392
timeout = 25 + 5

tuned/admin/dbus_controller.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def recommend_profile(self):
134134
def verify_profile(self):
135135
return self._call("verify_profile")
136136

137+
def dump(self):
138+
return self._call("dump_profile")
139+
137140
def verify_profile_ignore_missing(self):
138141
return self._call("verify_profile_ignore_missing")
139142

tuned/daemon/controller.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ def verify_profile_ignore_missing(self, caller = None):
279279
return False
280280
return self._daemon.verify_profile(ignore_missing = True)
281281

282+
@exports.export("", "(bs)")
283+
def dump_profile(self, caller = None):
284+
if caller == "":
285+
return False
286+
return self._daemon.dump_profile()
287+
282288
@exports.export("", "a{sa{ss}}")
283289
def get_all_plugins(self, caller = None):
284290
"""Return dictionary with accesible plugins

tuned/daemon/daemon.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,30 @@ def verify_profile(self, ignore_missing):
360360
self._not_used.set()
361361
return ret
362362

363+
def dump_profile(self):
364+
if not self.is_running():
365+
s = "TuneD is not running"
366+
log.error(s)
367+
return (False, s)
368+
369+
if self._profile is None:
370+
s = "no profile is set"
371+
log.error(s)
372+
return (False, s)
373+
374+
if not self._profile_applied.is_set():
375+
s = "profile is not applied"
376+
log.error(s)
377+
return (False, s)
378+
379+
# using daemon, the main loop mustn't exit before our completion
380+
self._not_used.clear()
381+
log.info("dumping profile(s): %s" % self._profile.name)
382+
s = self._unit_manager.dump_tuning()
383+
# main loop is allowed to exit
384+
self._not_used.set()
385+
return (True, s)
386+
363387
# profile_switch is helper telling plugins whether the stop is due to profile switch
364388
def stop(self, profile_switch = False):
365389
if not self.is_running():

tuned/plugins/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,27 @@ def instance_verify_tuning(self, instance, ignore_missing):
290290
else:
291291
return None
292292

293+
def instance_dump_tuning(self, instance):
294+
"""
295+
Dump tuning if the plugin instance is active.
296+
"""
297+
if not instance.active:
298+
return ""
299+
300+
s = "[%s]\n" % instance.name
301+
s += "type = %s\n" % self.name
302+
if instance._devices_expression:
303+
s += "devices = %s\n" % instance._devices_expression
304+
if instance._devices_udev_regex:
305+
s += "devices_udev_regex = %s\n" % instance._devices_udev_regex
306+
if instance._script_pre:
307+
s += "script_pre = %s\n" % instance._script_pre
308+
if instance._script_post:
309+
s += "script_post = %s\n" % instance._script_post
310+
for option, val in instance._options.items():
311+
s += "%s = %s\n" % (option, val)
312+
return s
313+
293314
def instance_update_tuning(self, instance):
294315
"""
295316
Apply dynamic tuning if the plugin instance is active.

tuned/plugins/instance/instance.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def apply_tuning(self):
8282
def verify_tuning(self, ignore_missing):
8383
return self._plugin.instance_verify_tuning(self, ignore_missing)
8484

85+
def dump_tuning(self):
86+
return self._plugin.instance_dump_tuning(self)
87+
8588
def update_tuning(self):
8689
self._plugin.instance_update_tuning(self)
8790

tuned/units/manager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ def verify_tuning(self, ignore_missing):
156156
ret = False
157157
return ret
158158

159+
def dump_tuning(self):
160+
s = ""
161+
for instance in self._instances:
162+
s += self._try_call("dump_tuning", None,
163+
instance.dump_tuning) + "\n"
164+
return s[:-1]
165+
159166
def update_tuning(self):
160167
for instance in self._instances:
161168
self._try_call("update_tuning", None,

0 commit comments

Comments
 (0)