]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: skip SVG-only plot metadata for text output
authordongshengyuan <545258830@qq.com>
Thu, 6 Aug 2026 03:41:10 +0000 (11:41 +0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 6 Aug 2026 16:19:12 +0000 (01:19 +0900)
pretty_boot_time() and acquire_host_info() only feed the SVG header.
Do not query them when plot output is rendered as table or JSON.

Follow-up for ff46b2f97c42d73401ca3ffaaef54a017dc23923.

src/analyze/analyze-plot.c

index 3a3f07d2e36d802c5750a0e5721ff1ec6be5a0eb..909f714d583a3c683cd4c534004ba04f95239844 100644 (file)
@@ -473,10 +473,8 @@ static int produce_plot_as_text(UnitTimes *times, const BootTimes *boot) {
 }
 
 int verb_plot(int argc, char *argv[], uintptr_t _data, void *userdata) {
-        _cleanup_(free_host_infop) HostInfo *host = NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
         _cleanup_(unit_times_free_arrayp) UnitTimes *times = NULL;
-        _cleanup_free_ char *pretty_times = NULL;
         bool use_full_bus = arg_runtime_scope == RUNTIME_SCOPE_SYSTEM;
         BootTimes *boot;
         int n, r;
@@ -489,16 +487,6 @@ int verb_plot(int argc, char *argv[], uintptr_t _data, void *userdata) {
         if (n < 0)
                 return n;
 
-        n = pretty_boot_time(bus, &pretty_times);
-        if (n < 0)
-                return n;
-
-        if (use_full_bus || arg_runtime_scope != RUNTIME_SCOPE_SYSTEM) {
-                n = acquire_host_info(bus, &host);
-                if (n < 0)
-                        return n;
-        }
-
         n = acquire_time_data(bus, /* require_finished= */ true, &times);
         if (n <= 0)
                 return n;
@@ -507,8 +495,22 @@ int verb_plot(int argc, char *argv[], uintptr_t _data, void *userdata) {
 
         if (sd_json_format_enabled(arg_json_format_flags) || arg_table)
                 r = produce_plot_as_text(times, boot);
-        else
+        else {
+                _cleanup_(free_host_infop) HostInfo *host = NULL;
+                _cleanup_free_ char *pretty_times = NULL;
+
+                r = pretty_boot_time(bus, &pretty_times);
+                if (r < 0)
+                        return r;
+
+                if (use_full_bus || arg_runtime_scope != RUNTIME_SCOPE_SYSTEM) {
+                        r = acquire_host_info(bus, &host);
+                        if (r < 0)
+                                return r;
+                }
+
                 r = produce_plot_as_svg(times, host, boot, pretty_times);
+        }
         if (r < 0)
                 return r;