From 4466912fc280873b6432973b287a48bf9c959b6c Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 23 Jan 2012 18:08:42 -0500 Subject: [PATCH] Implement UST calibrate and change default Calibrate now works for UST (even if ust does not implement it now). Only --function is exposed since it's the only one implemented and also becomes the default. Signed-off-by: David Goulet --- src/bin/lttng-sessiond/main.c | 13 +++- src/bin/lttng-sessiond/ust-app.c | 43 +++++++++++++ src/bin/lttng-sessiond/ust-app.h | 6 ++ src/bin/lttng/commands/calibrate.c | 82 +++++++++++++----------- src/common/sessiond-comm/sessiond-comm.c | 1 + src/common/sessiond-comm/sessiond-comm.h | 1 + 6 files changed, 106 insertions(+), 40 deletions(-) diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 023ad48b9..ca8812e72 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2924,8 +2924,19 @@ static int cmd_calibrate(int domain, struct lttng_calibrate *calibrate) } break; } + case LTTNG_DOMAIN_UST: + { + struct lttng_ust_calibrate ucalibrate; + + ucalibrate.type = calibrate->type; + ret = ust_app_calibrate_glb(&ucalibrate); + if (ret < 0) { + ret = LTTCOMM_UST_CALIBRATE_FAIL; + goto error; + } + break; + } default: - /* TODO: Userspace tracing */ ret = LTTCOMM_UND; goto error; } diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 62816cecb..a82207140 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -2538,3 +2538,46 @@ error: rcu_read_unlock(); return -1; } + +/* + * Calibrate registered applications. + */ +int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate) +{ + int ret = 0; + struct lttng_ht_iter iter; + struct ust_app *app; + + rcu_read_lock(); + + cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { + if (!app->compatible) { + /* + * TODO: In time, we should notice the caller of this error by + * telling him that this is a version error. + */ + continue; + } + + ret = ustctl_calibrate(app->key.sock, calibrate); + if (ret < 0) { + switch (ret) { + case -ENOSYS: + /* Means that it's not implemented on the tracer side. */ + ret = 0; + break; + default: + /* TODO: Report error to user */ + DBG2("Calibrate app PID %d returned with error %d", + app->key.pid, ret); + break; + } + } + } + + DBG("UST app global domain calibration finished"); + + rcu_read_unlock(); + + return ret; +} diff --git a/src/bin/lttng-sessiond/ust-app.h b/src/bin/lttng-sessiond/ust-app.h index 67c09692f..0fb854fbe 100644 --- a/src/bin/lttng-sessiond/ust-app.h +++ b/src/bin/lttng-sessiond/ust-app.h @@ -173,6 +173,7 @@ void ust_app_ht_alloc(void); struct lttng_ht *ust_app_get_ht(void); struct ust_app *ust_app_find_by_pid(pid_t pid); int ust_app_validate_version(int sock); +int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate); #else /* HAVE_LIBLTTNG_UST_CTL */ @@ -333,6 +334,11 @@ int ust_app_validate_version(int sock) { return 0; } +static inline +int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate) +{ + return 0; +} #endif /* HAVE_LIBLTTNG_UST_CTL */ diff --git a/src/bin/lttng/commands/calibrate.c b/src/bin/lttng/commands/calibrate.c index 485cae135..a0e852f8b 100644 --- a/src/bin/lttng/commands/calibrate.c +++ b/src/bin/lttng/commands/calibrate.c @@ -60,13 +60,13 @@ static struct poptOption long_options[] = { /* Not implemented yet */ {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, -#else - {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, -#endif {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0}, {"marker", 0, POPT_ARG_NONE, 0, OPT_MARKER, 0, 0}, {"probe", 0, POPT_ARG_NONE, 0, OPT_PROBE, 0, 0}, +#else + {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, {"function", 0, POPT_ARG_NONE, 0, OPT_FUNCTION, 0, 0}, +#endif #if 0 /* * Removed from options to discourage its use. Not in kernel @@ -97,17 +97,19 @@ static void usage(FILE *ofp) #endif fprintf(ofp, "\n"); fprintf(ofp, "Calibrate options:\n"); +#if 0 fprintf(ofp, " --tracepoint Tracepoint event (default)\n"); fprintf(ofp, " --probe\n"); fprintf(ofp, " Dynamic probe.\n"); - fprintf(ofp, " --function\n"); - fprintf(ofp, " Dynamic function entry/return probe.\n"); #if 0 fprintf(ofp, " --function:entry symbol\n"); fprintf(ofp, " Function tracer event\n"); #endif fprintf(ofp, " --syscall System call eventl\n"); fprintf(ofp, " --marker User-space marker (deprecated)\n"); +#else + fprintf(ofp, " --function Dynamic function entry/return probe (default)\n"); +#endif fprintf(ofp, "\n"); } @@ -125,46 +127,48 @@ static int calibrate_lttng(void) /* Create lttng domain */ if (opt_kernel) { dom.type = LTTNG_DOMAIN_KERNEL; + } else if (opt_userspace) { + dom.type = LTTNG_DOMAIN_UST; + } else { + ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); + ret = CMD_UNDEFINED; + goto error; } handle = lttng_create_handle(NULL, &dom); if (handle == NULL) { ret = -1; - goto end; + goto error; } - /* Kernel tracer action */ - if (opt_kernel) { - switch (opt_event_type) { - case LTTNG_EVENT_TRACEPOINT: - DBG("Calibrating kernel tracepoints"); - break; - case LTTNG_EVENT_PROBE: - DBG("Calibrating kernel probes"); - break; - case LTTNG_EVENT_FUNCTION: - DBG("Calibrating kernel functions"); - calibrate.type = LTTNG_CALIBRATE_FUNCTION; - ret = lttng_calibrate(handle, &calibrate); - break; - case LTTNG_EVENT_FUNCTION_ENTRY: - DBG("Calibrating kernel function entry"); - break; - case LTTNG_EVENT_SYSCALL: - DBG("Calibrating kernel syscall"); - break; - default: - ret = CMD_UNDEFINED; - goto end; + switch (opt_event_type) { + case LTTNG_EVENT_TRACEPOINT: + DBG("Calibrating kernel tracepoints"); + break; + case LTTNG_EVENT_PROBE: + DBG("Calibrating kernel probes"); + break; + case LTTNG_EVENT_FUNCTION: + DBG("Calibrating kernel functions"); + calibrate.type = LTTNG_CALIBRATE_FUNCTION; + ret = lttng_calibrate(handle, &calibrate); + if (ret < 0) { + goto error; } - } else if (opt_userspace) { /* User-space tracer action */ + MSG("%s calibration done", opt_kernel ? "Kernel" : "UST"); + break; + case LTTNG_EVENT_FUNCTION_ENTRY: + DBG("Calibrating kernel function entry"); + break; + case LTTNG_EVENT_SYSCALL: + DBG("Calibrating kernel syscall"); + break; + default: ret = CMD_UNDEFINED; - goto end; - } else { - ERR("Please specify a tracer (--kernel or --userspace)"); - goto end; + goto error; } -end: + +error: lttng_destroy_handle(handle); return ret; @@ -184,7 +188,7 @@ int cmd_calibrate(int argc, const char **argv) poptReadDefaultConfig(pc, 0); /* Default event type */ - opt_event_type = LTTNG_EVENT_TRACEPOINT; + opt_event_type = LTTNG_EVENT_FUNCTION; while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { @@ -194,7 +198,7 @@ int cmd_calibrate(int argc, const char **argv) goto end; case OPT_TRACEPOINT: ret = CMD_UNDEFINED; - break; + goto end; case OPT_MARKER: ret = CMD_UNDEFINED; goto end; @@ -206,10 +210,10 @@ int cmd_calibrate(int argc, const char **argv) break; case OPT_FUNCTION_ENTRY: ret = CMD_UNDEFINED; - break; + goto end; case OPT_SYSCALL: ret = CMD_UNDEFINED; - break; + goto end; case OPT_USERSPACE: opt_userspace = 1; break; diff --git a/src/common/sessiond-comm/sessiond-comm.c b/src/common/sessiond-comm/sessiond-comm.c index 03e89314f..3b7a2a2ad 100644 --- a/src/common/sessiond-comm/sessiond-comm.c +++ b/src/common/sessiond-comm/sessiond-comm.c @@ -76,6 +76,7 @@ static const char *lttcomm_readable_code[] = { [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_DIR_EXIST) ] = "Kernel trace directory already exist", [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_NO_SESSION) ] = "No kernel session found", [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_LIST_FAIL) ] = "Listing kernel events failed", + [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_CALIBRATE_FAIL) ] = "UST calibration failed", [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_VERSION) ] = "UST tracer version is not compatible", [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_SESS_FAIL) ] = "UST create session failed", [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_CHAN_FAIL) ] = "UST create channel failed", diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index 694ee2e4e..d8d27063d 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -111,6 +111,7 @@ enum lttcomm_return_code { LTTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */ LTTCOMM_KERN_NO_SESSION, /* No kernel session found */ LTTCOMM_KERN_LIST_FAIL, /* Kernel listing events failed */ + LTTCOMM_UST_CALIBRATE_FAIL, /* UST calibration failed */ LTTCOMM_UST_VERSION, /* UST tracer version is not compatible */ LTTCOMM_UST_SESS_FAIL, /* UST create session failed */ LTTCOMM_UST_CHAN_EXIST, /* UST channel already exist */ -- 2.34.1