Last active
December 29, 2022 08:19
-
-
Save wataash/aba98b18f5fc86d604bfe3ef087fb63e to your computer and use it in GitHub Desktop.
systemd-analyze dot (only the top 30 units with the most appearances)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "set" | |
unless ARGV.length == 1 | |
warn("usage: systemd-analyze dot | systemd-analyze-dot-only-n N") | |
exit(1) | |
end | |
n = ARGV.shift.to_i(10) | |
txt = ARGF.read | |
pairs_unit_count = Hash.new(0) | |
txt.scan(/^\t"(.+?)"->"(.+?)" \[color="\w+"\];$/) do |left, right| | |
pairs_unit_count[left] += 1 | |
pairs_unit_count[right] += 1 | |
end | |
n_units = pairs_unit_count.sort_by { |_unit, count| -count }.first(n).map { |unit, _count| unit }.to_set | |
# n_units.add("postfix.service") | |
# n_units.delete("shutdown.target") | |
txt.split(/\r?\n/) do |line| | |
unless line.start_with?("\t") | |
puts(line) | |
next | |
end | |
match_data = /^\t"(.+?)"->"(.+?)" \[color="\w+"\];$/.match(line) | |
if match_data.nil? | |
warn("unexpected line: #{line}") | |
next | |
end | |
next unless n_units.include?(match_data[1]) && n_units.include?(match_data[2]) | |
puts(line) | |
end |
Author
wataash
commented
Dec 29, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment