analyze.c revision 8901b40502670d1d153f92294ae93245f608adc8
383N/A along with systemd; If not, see <http://www.gnu.org/licenses/>.
383N/A#include "alloc-util.h"
383N/A#include "analyze-verify.h"
383N/A#include "bus-error.h"
383N/A#include "bus-util.h"
383N/A#include "glob-util.h"
383N/A#include "locale-util.h"
383N/A#include "parse-util.h"
383N/A#include "strxcpyx.h"
383N/A#include "terminal-util.h"
383N/A#include "unit-name.h"
383N/A svg(" <text class=\"%s\" x=\"%.03f\" y=\"%.03f\">", (b) ? "left" : "right", SCALE_X * (x) + (b ? 5.0 : -5.0), SCALE_Y * (y) + 14.0); \
383N/Astatic bool arg_no_pager = false;
383N/Astruct boot_times {
383N/Astruct unit_times {
383N/A char *kernel_name;
383N/A char *kernel_release;
383N/A char *kernel_version;
383N/A char *os_pretty_name;
383N/A char *virtualization;
383N/A char *architecture;
383N/Astatic void pager_open_if_enabled(void) {
383N/A if (arg_no_pager)
383N/A pager_open(false);
383N/Astatic int bus_get_uint64_property(sd_bus *bus, const char *path, const char *interface, const char *property, uint64_t *val) {
383N/A "org.freedesktop.systemd1",
383N/Astatic int bus_get_unit_property_strv(sd_bus *bus, const char *path, const char *property, char ***strv) {
383N/A "org.freedesktop.systemd1",
383N/A "org.freedesktop.systemd1.Unit",
383N/Astatic int compare_unit_time(const void *a, const void *b) {
383N/Astatic int compare_unit_start(const void *a, const void *b) {
383N/A struct unit_times *p;
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A return -EINPROGRESS;
383N/A times.firmware_time = times.loader_time = times.kernel_time = times.initrd_time = times.userspace_time = 0;
383N/A r = sd_bus_call_method(
383N/A "org.freedesktop.systemd1",
383N/A "/org/freedesktop/systemd1",
383N/A "org.freedesktop.systemd1.Manager",
383N/A struct unit_times *t;
383N/A t = unit_times+c;
383N/A "org.freedesktop.systemd1.Unit",
383N/A &t->activating) < 0 ||
383N/A "org.freedesktop.systemd1.Unit",
383N/A "org.freedesktop.systemd1.Unit",
383N/A &t->deactivating) < 0 ||
383N/A "org.freedesktop.systemd1.Unit",
383N/A &t->deactivated) < 0) {
383N/A if (t->activating == 0)
383N/A if (unit_times)
383N/A "org.freedesktop.hostname1",
383N/A log_debug_errno(r, "Failed to get host information from systemd-hostnamed: %s", bus_error_message(&error, r));
383N/A "org.freedesktop.systemd1",
383N/A "/org/freedesktop/systemd1",
383N/A return log_error_errno(r, "Failed to get host information from systemd: %s", bus_error_message(&error, r));
383N/A struct boot_times *t;
383N/A if (t->firmware_time)
383N/A size = strpcpyf(&ptr, size, "%s (firmware) + ", format_timespan(ts, sizeof(ts), t->firmware_time - t->loader_time, USEC_PER_MSEC));
383N/A if (t->loader_time)
383N/A size = strpcpyf(&ptr, size, "%s (loader) + ", format_timespan(ts, sizeof(ts), t->loader_time, USEC_PER_MSEC));
383N/A if (t->kernel_time)
383N/A size = strpcpyf(&ptr, size, "%s (kernel) + ", format_timespan(ts, sizeof(ts), t->kernel_done_time, USEC_PER_MSEC));
383N/A if (t->initrd_time > 0)
383N/A size = strpcpyf(&ptr, size, "%s (initrd) + ", format_timespan(ts, sizeof(ts), t->userspace_time - t->initrd_time, USEC_PER_MSEC));
383N/A size = strpcpyf(&ptr, size, "%s (userspace) ", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC));
383N/A strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC));
383N/A struct unit_times *u;
383N/A "xmlns=\"http://www.w3.org/2000/svg\">\n\n",
383N/Astatic int list_dependencies_print(const char *name, unsigned int level, unsigned int branches,
383N/A printf("%s", draw_special_char(branches & (1 << (i-1)) ? DRAW_TREE_VERTICAL : DRAW_TREE_SPACE));
383N/A printf("%s @%s", name, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC));
383N/Astatic int list_dependencies_one(sd_bus *bus, const char *name, unsigned int level, char ***units,
383N/A || service_longest == 0)) {
383N/A if (service_longest == 0 )
383N/A if (times && times->activated && times->activated <= boot->finish_time && (service_longest - times->activated) <= arg_fuzz)
383N/A "org.freedesktop.systemd1",
383N/A "org.freedesktop.systemd1.Unit",
383N/A return bus_log_parse_error(r);
383N/A printf("%s @%s\n", id, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC));
383N/A unit_times_hashmap = h;
383N/A hashmap_free(h);
383N/A printf("%16s %s\n", format_timespan(ts, sizeof(ts), times[i].time, USEC_PER_MSEC), times[i].name);
383N/Astatic int graph_one_property(sd_bus *bus, const UnitInfo *u, const char* prop, const char *color, char* patterns[], char* from_patterns[], char* to_patterns[]) {
383N/A bool match_patterns;
383N/A !match_patterns &&
383N/A bool match_patterns2;
383N/Astatic int graph_one(sd_bus *bus, const UnitInfo *u, char *patterns[], char *from_patterns[], char *to_patterns[]) {
383N/A r = graph_one_property(bus, u, "Requisite", "darkblue", patterns, from_patterns, to_patterns);
383N/A "org.freedesktop.systemd1",
383N/A "org.freedesktop.systemd1.Unit",
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
&reply,
return bus_log_parse_error(r);
return bus_log_parse_error(r);
if (on_tty())
"-- Try a shell pipeline like 'systemd-analyze dot | dot -Tsvg > systemd.svg'!\n");
return -E2BIG;
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
&reply,
return bus_log_parse_error(r);
return -E2BIG;
r = sd_bus_set_property(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
args[0]);
return -E2BIG;
r = sd_bus_set_property(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
args[0]);
static void help(void) {
* changes to shell-completion/bash/systemd-analyze and
* shell-completion/zsh/_systemd-analyze too. */
help();
case ARG_VERSION:
return version();
case ARG_USER:
arg_user = true;
case ARG_SYSTEM:
arg_user = false;
case ARG_ORDER:
case ARG_REQUIRE:
case ARG_DOT_FROM_PATTERN:
return log_oom();
case ARG_DOT_TO_PATTERN:
return log_oom();
case ARG_FUZZ:
case ARG_NO_PAGER:
arg_no_pager = true;
case ARG_MAN:
if (optarg) {
return -EINVAL;
arg_man = !!r;
arg_man = true;
return -EINVAL;
log_open();
goto finish;
arg_man);
goto finish;
pager_close();