From: rajmohan r Date: Mon, 29 Jul 2024 12:10:58 +0000 (+0530) Subject: systemd-analyze: Add svg scaling options X-Git-Tag: v257-rc1~735 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1592d2f900c25251ece2670c71d957806f48216b;p=thirdparty%2Fsystemd.git systemd-analyze: Add svg scaling options + 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 --- diff --git a/man/systemd-analyze.xml b/man/systemd-analyze.xml index 91e7e1eda5c..1d20574cee6 100644 --- a/man/systemd-analyze.xml +++ b/man/systemd-analyze.xml @@ -1601,6 +1601,24 @@ io.systemd.credential:vmm.notify_socket=vsock-stream:2:254570042 + + + + When used with the plot command, the x-axis of the plot + can be stretched by FACTOR (default: 1.0). + + + + + + + + When used with the plot command, activation timestamps + details can be seen in SVG plot. + + + + diff --git a/shell-completion/bash/systemd-analyze b/shell-completion/bash/systemd-analyze index 91c46b256bd..9bb50a37b2c 100644 --- a/shell-completion/bash/systemd-analyze +++ b/shell-completion/bash/systemd-analyze @@ -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 diff --git a/src/analyze/analyze-plot.c b/src/analyze/analyze-plot.c index 0b4725e0179..d14c40de60f 100644 --- a/src/analyze/analyze-plot.c +++ b/src/analyze/analyze-plot.c @@ -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("\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++) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index c9675d42586..a7acc35f4f9 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -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; diff --git a/src/analyze/analyze.h b/src/analyze/analyze.h index a93603243c3..246a880b627 100644 --- a/src/analyze/analyze.h +++ b/src/analyze/analyze.h @@ -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; diff --git a/test/units/TEST-65-ANALYZE.sh b/test/units/TEST-65-ANALYZE.sh index 236c27e33b5..83abc0ac1a0 100755 --- a/test/units/TEST-65-ANALYZE.sh +++ b/test/units/TEST-65-ANALYZE.sh @@ -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