Make "systemd-analyze dot" output only lines with units matching given glob(7) patterns. Add --from-pattern and --to-pattern options. Without any patterns all relationships are printed as before.
A relationship must match the follwing expression: (isempty(from-pattern) || from-pattern) && (isempty(to-pattern) || to-pattern) && (isempty(P) || P[0] || P[1] || ... || P[n]) where P[N] are additional patterns provided after the "dot" subcommand. --- This is almost the same as v3 but with a shorter list of parameters for the dot() function. man/systemd-analyze.xml | 23 ++++++++++++++++++++- src/analyze/systemd-analyze.c | 48 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/man/systemd-analyze.xml b/man/systemd-analyze.xml index 533bc42..371c245 100644 --- a/man/systemd-analyze.xml +++ b/man/systemd-analyze.xml @@ -58,7 +58,7 @@ <command>systemd-analyze <arg choice="opt" rep="repeat">OPTIONS</arg> plot <arg choice="opt">> file.svg</arg></command> </cmdsynopsis> <cmdsynopsis> - <command>systemd-analyze <arg choice="opt" rep="repeat">OPTIONS</arg> dot </command> + <command>systemd-analyze <arg choice="opt" rep="repeat">OPTIONS</arg> dot <arg choice="opt">pattern...</arg> </command> </cmdsynopsis> </refsynopsisdiv> @@ -104,6 +104,10 @@ is passed the generated graph will show both ordering and requirement dependencies.</para> + <para>Optional patterns may be given at the end. The + relationship is printet if any of these matches either + lefthend or righthand node.</para> + <para>If no command is passed <command>systemd-analyze time</command> is implied.</para> @@ -156,6 +160,23 @@ dependencies of all these types.</para></listitem> </varlistentry> + + <varlistentry> + <term><option>--from-pattern=</option></term> + <term><option>--to-pattern=</option></term> + + <listitem><para>When used in + conjunction with the + <command>dot</command> command (see + above), selects which relationships + are shown in the dependency graph. + They both require + <citerefentry><refentrytitle>glob</refentrytitle><manvolnum>7</manvolnum></citerefentry> + patterns as arguments, which are + matched against lefthand and + righthand, respectively, nodes of a + relationship.</para></listitem> + </varlistentry> </variablelist> </refsect1> diff --git a/src/analyze/systemd-analyze.c b/src/analyze/systemd-analyze.c index 01bf55e..559d588 100644 --- a/src/analyze/systemd-analyze.c +++ b/src/analyze/systemd-analyze.c @@ -25,6 +25,7 @@ #include <getopt.h> #include <locale.h> #include <sys/utsname.h> +#include <fnmatch.h> #include "install.h" #include "log.h" @@ -60,6 +61,8 @@ static enum dot { DEP_ORDER, DEP_REQUIRE } arg_dot = DEP_ALL; +static char* arg_from_pattern=NULL; +static char* arg_to_pattern=NULL; struct boot_times { usec_t firmware_time; @@ -578,7 +581,7 @@ static int analyze_time(DBusConnection *bus) { return 0; } -static int graph_one_property(const char *name, const char *prop, DBusMessageIter *iter) { +static int graph_one_property(const char *name, const char *prop, DBusMessageIter *iter, char* patterns[]) { static const char * const colors[] = { "Requires", "[color=\"black\"]", @@ -621,9 +624,28 @@ static int graph_one_property(const char *name, const char *prop, DBusMessageIte dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID; dbus_message_iter_next(&sub)) { const char *s; + char **p; assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING); dbus_message_iter_get_basic(&sub, &s); + + if (arg_from_pattern != NULL && fnmatch(arg_from_pattern, name, 0) != 0) + continue; + + if (arg_to_pattern != NULL && fnmatch(arg_to_pattern, s, 0) != 0) + continue; + + if (*patterns == NULL) { + goto print; + } + + for (p=patterns; *p != NULL; p++) { + if (fnmatch(*p, name, 0) == 0 || fnmatch(*p, s, 0) == 0) + goto print; + } + continue; + + print: printf("\t\"%s\"->\"%s\" %s;\n", name, s, c); } } @@ -631,7 +653,7 @@ static int graph_one_property(const char *name, const char *prop, DBusMessageIte return 0; } -static int graph_one(DBusConnection *bus, const struct unit_info *u) { +static int graph_one(DBusConnection *bus, const struct unit_info *u, char *patterns[]) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; const char *interface = "org.freedesktop.systemd1.Unit"; int r; @@ -675,7 +697,7 @@ static int graph_one(DBusConnection *bus, const struct unit_info *u) { } dbus_message_iter_recurse(&sub2, &sub3); - r = graph_one_property(u->id, prop, &sub3); + r = graph_one_property(u->id, prop, &sub3, patterns); if (r < 0) return r; } @@ -683,7 +705,7 @@ static int graph_one(DBusConnection *bus, const struct unit_info *u) { return 0; } -static int dot(DBusConnection *bus) { +static int dot(DBusConnection *bus, char* patterns[]) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; DBusMessageIter iter, sub; int r; @@ -718,7 +740,7 @@ static int dot(DBusConnection *bus) { if (r < 0) return -EIO; - r = graph_one(bus, &u); + r = graph_one(bus, &u, patterns); if (r < 0) return r; } @@ -763,7 +785,9 @@ static int parse_argv(int argc, char *argv[]) ARG_ORDER, ARG_REQUIRE, ARG_USER, - ARG_SYSTEM + ARG_SYSTEM, + ARG_FROM_PATTERN, + ARG_TO_PATTERN }; static const struct option options[] = { @@ -773,6 +797,8 @@ static int parse_argv(int argc, char *argv[]) { "require", no_argument, NULL, ARG_REQUIRE }, { "user", no_argument, NULL, ARG_USER }, { "system", no_argument, NULL, ARG_SYSTEM }, + { "from-pattern", required_argument, NULL, ARG_FROM_PATTERN}, + { "to-pattern", required_argument, NULL, ARG_TO_PATTERN }, { NULL, 0, NULL, 0 } }; @@ -806,6 +832,14 @@ static int parse_argv(int argc, char *argv[]) arg_dot = DEP_REQUIRE; break; + case ARG_FROM_PATTERN: + arg_from_pattern=optarg; + break; + + case ARG_TO_PATTERN: + arg_to_pattern=optarg; + break; + case -1: return 1; @@ -844,7 +878,7 @@ int main(int argc, char *argv[]) { else if (streq(argv[optind], "plot")) r = analyze_plot(bus); else if (streq(argv[optind], "dot")) - r = dot(bus); + r = dot(bus, argv+optind+1); else log_error("Unknown operation '%s'.", argv[optind]); -- 1.8.1.5 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel