]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemd-analyze: Add svg scaling options
authorrajmohan r <rajmohan.r@kpit.com>
Mon, 29 Jul 2024 12:10:58 +0000 (17:40 +0530)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 5 Aug 2024 13:23:44 +0000 (15:23 +0200)
+ Scale the x-axis of the resulting plot by a factor (default 1.0)
+ Add activation timestamps to each bar

Signed-off-by: rajmohan r <rajmohan.r@kpit.com>
man/systemd-analyze.xml
shell-completion/bash/systemd-analyze
src/analyze/analyze-plot.c
src/analyze/analyze.c
src/analyze/analyze.h
test/units/TEST-65-ANALYZE.sh

index 91e7e1eda5c8ce174c1c4c7d51106edeb2ab5fbd..1d20574cee67229a130a730b50696d52693445b2 100644 (file)
@@ -1601,6 +1601,24 @@ io.systemd.credential:vmm.notify_socket=vsock-stream:2:254570042
         <xi:include href="version-info.xml" xpointer="v255"/></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--scale-svg=<replaceable>FACTOR</replaceable></option></term>
+
+        <listitem><para>When used with the <command>plot</command> command, the x-axis of the plot
+        can be stretched by FACTOR (default: 1.0).</para>
+
+        <xi:include href="version-info.xml" xpointer="v257"/></listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><option>--detailed</option></term>
+
+        <listitem><para>When used with the <command>plot</command> command, activation timestamps
+        details can be seen in SVG plot.</para>
+
+        <xi:include href="version-info.xml" xpointer="v257"/></listitem>
+      </varlistentry>
+
       <xi:include href="standard-options.xml" xpointer="help" />
       <xi:include href="standard-options.xml" xpointer="version" />
       <xi:include href="standard-options.xml" xpointer="no-pager" />
index 91c46b256bdcd208df507830e6ce6cb63033121c..9bb50a37b2c14f78209f79dc5c3bb98f4e730c2e 100644 (file)
@@ -204,7 +204,7 @@ _systemd_analyze() {
 
     elif __contains_word "$verb" ${VERBS[PLOT]}; then
         if [[ $cur = -* ]]; then
-            comps='--help --version --system --user --global --no-pager --json=off --json=pretty --json=short --table --no-legend'
+            comps='--help --version --system --user --global --no-pager --json=off --json=pretty --json=short --table --no-legend --scale-svg --detailed'
         fi
 
     elif __contains_word "$verb" ${VERBS[ARCHITECTURES]}; then
index 0b4725e0179b5fa3e0ae3f8f585b855cfa537cf1..d14c40de60f7301a54193686778342796b75af4c 100644 (file)
@@ -12,7 +12,7 @@
 #include "unit-def.h"
 #include "version.h"
 
-#define SCALE_X (0.1 / 1000.0) /* pixels per us */
+#define SCALE_X (0.1 * arg_svg_timescale / 1000.0) /* pixels per us */
 #define SCALE_Y (20.0)
 
 #define svg(...) printf(__VA_ARGS__)
@@ -30,6 +30,9 @@
                 svg("</text>\n");                                       \
         } while (false)
 
+#define svg_timestamp(b, t, y) \
+        svg_text(b, t, y, "%u.%03us", (unsigned)((t) / USEC_PER_SEC), (unsigned)(((t) % USEC_PER_SEC) / USEC_PER_MSEC))
+
 
 typedef struct HostInfo {
         char *hostname;
@@ -366,6 +369,8 @@ static int produce_plot_as_svg(
         svg_bar("generators", boot->generators_start_time, boot->generators_finish_time, y);
         svg_bar("unitsload", boot->unitsload_start_time, boot->unitsload_finish_time, y);
         svg_text(true, boot->userspace_time, y, "systemd");
+        if (arg_detailed_svg)
+                svg_timestamp(false, boot->userspace_time, y);
         y++;
 
         for (; u->has_data; u++)
index c9675d42586f865aee4711bc7236363a11809fb7..a7acc35f4f9462310afdbb7893697f84fb2895e0 100644 (file)
@@ -102,6 +102,8 @@ RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
 RecursiveErrors arg_recursive_errors = _RECURSIVE_ERRORS_INVALID;
 bool arg_man = true;
 bool arg_generators = false;
+double arg_svg_timescale = 1.0;
+bool arg_detailed_svg = false;
 char *arg_root = NULL;
 static char *arg_image = NULL;
 char *arg_security_policy = NULL;
@@ -277,6 +279,9 @@ static int help(int argc, char *argv[], void *userdata) {
                "                             security review of the unit(s)\n"
                "     --unit=UNIT             Evaluate conditions and asserts of unit\n"
                "     --table                 Output plot's raw time data as a table\n"
+               "     --scale-svg=FACTOR      Stretch x-axis of plot by FACTOR (default: 1.0)\n"
+               "     --detailed              Add more details to SVG plot,\n"
+               "                             e.g. show activation timestamps\n"
                "  -h --help                  Show this help\n"
                "     --version               Show package version\n"
                "  -q --quiet                 Do not emit hints\n"
@@ -325,6 +330,8 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_TABLE,
                 ARG_NO_LEGEND,
                 ARG_TLDR,
+                ARG_SCALE_FACTOR_SVG,
+                ARG_DETAILED_SVG,
         };
 
         static const struct option options[] = {
@@ -360,6 +367,8 @@ static int parse_argv(int argc, char *argv[]) {
                 { "no-legend",        optional_argument, NULL, ARG_NO_LEGEND        },
                 { "tldr",             no_argument,       NULL, ARG_TLDR             },
                 { "mask",             no_argument,       NULL, 'm'                  },
+                { "scale-svg",        required_argument, NULL, ARG_SCALE_FACTOR_SVG },
+                { "detailed",         no_argument,       NULL, ARG_DETAILED_SVG     },
                 {}
         };
 
@@ -557,6 +566,14 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_capability = CAPABILITY_MASK;
                         break;
 
+                case ARG_SCALE_FACTOR_SVG:
+                        arg_svg_timescale = strtod(optarg, NULL);
+                        break;
+
+                case ARG_DETAILED_SVG:
+                        arg_detailed_svg = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
index a93603243c35a389b1d75d22d22389ab41e5e236..246a880b62796333a9e39f3445332914eaac6799 100644 (file)
@@ -35,6 +35,8 @@ extern RuntimeScope arg_runtime_scope;
 extern RecursiveErrors arg_recursive_errors;
 extern bool arg_man;
 extern bool arg_generators;
+extern double arg_svg_timescale;
+extern bool arg_detailed_svg;
 extern char *arg_root;
 extern char *arg_security_policy;
 extern bool arg_offline;
index 236c27e33b5e61787f4db762c4d5e5e1ce2acf0b..83abc0ac1a0d133393e90f671ca7e8da9de328f4 100755 (executable)
@@ -31,6 +31,8 @@ systemd-analyze plot --json=short --no-legend >/dev/null || :
 systemd-analyze plot --json=off --no-legend >/dev/null || :
 systemd-analyze plot --table >/dev/null || :
 systemd-analyze plot --table --no-legend >/dev/null || :
+systemd-analyze plot --scale-svg=1.0 >/dev/null || :
+systemd-analyze plot --scale-svg=1.0 --detailed >/dev/null || :
 (! systemd-analyze plot --global)
 # legacy/deprecated options (moved to systemctl, but still usable from analyze)
 systemd-analyze log-level