From: Mathieu Desnoyers Date: Thu, 2 Feb 2012 00:24:47 +0000 (-0500) Subject: ABI update: only send loglevel value to UST: fixed loglevels X-Git-Tag: v2.0-pre19~13 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8005f29ac9f079b844b3e6bb0261e19a76ccd4da;p=lttng-tools.git ABI update: only send loglevel value to UST: fixed loglevels Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/lttng.h b/include/lttng/lttng.h index c83f98325..f4c7cb97a 100644 --- a/include/lttng/lttng.h +++ b/include/lttng/lttng.h @@ -71,8 +71,9 @@ enum lttng_event_type { * Loglevel information. */ enum lttng_loglevel_type { - LTTNG_EVENT_LOGLEVEL = 0, - LTTNG_EVENT_LOGLEVEL_ONLY = 1, + LTTNG_EVENT_LOGLEVEL_ALL = 0, + LTTNG_EVENT_LOGLEVEL_RANGE = 1, + LTTNG_EVENT_LOGLEVEL_SINGLE = 2, }; /* @@ -152,9 +153,8 @@ struct lttng_event { char name[LTTNG_SYMBOL_NAME_LEN]; enum lttng_loglevel_type loglevel_type; - char loglevel[LTTNG_SYMBOL_NAME_LEN]; /* '\0' for all loglevels */ + int loglevel; - int64_t loglevel_value; /* for printing */ uint32_t enabled; pid_t pid; /* Per event type configuration */ diff --git a/src/bin/lttng-sessiond/lttng-ust-abi.h b/src/bin/lttng-sessiond/lttng-ust-abi.h index 28962aaf7..bd83c00ff 100644 --- a/src/bin/lttng-sessiond/lttng-ust-abi.h +++ b/src/bin/lttng-sessiond/lttng-ust-abi.h @@ -25,8 +25,9 @@ enum lttng_ust_instrumentation { }; enum lttng_ust_loglevel_type { - LTTNG_UST_LOGLEVEL = 0, - LTTNG_UST_LOGLEVEL_ONLY = 1, + LTTNG_UST_LOGLEVEL_ALL = 0, + LTTNG_UST_LOGLEVEL_RANGE = 1, + LTTNG_UST_LOGLEVEL_SINGLE = 2, }; enum lttng_ust_output { @@ -53,7 +54,7 @@ struct lttng_ust_event { char name[LTTNG_UST_SYM_NAME_LEN]; /* event name */ enum lttng_ust_loglevel_type loglevel_type; - char loglevel[LTTNG_UST_SYM_NAME_LEN]; /* loglevel name */ + int loglevel; /* value, -1: all */ /* Per instrumentation type configuration */ union { @@ -87,8 +88,7 @@ struct lttng_ust_channel_attr { struct lttng_ust_tracepoint_iter { char name[LTTNG_UST_SYM_NAME_LEN]; /* provider:name */ - char loglevel[LTTNG_UST_SYM_NAME_LEN]; /* loglevel */ - int64_t loglevel_value; + int loglevel; }; struct lttng_ust_object_data { diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index e990c3484..61a762803 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2032,14 +2032,16 @@ static int list_lttng_ust_global_events(char *channel_name, tmp[i].type = LTTNG_EVENT_FUNCTION; break; } - strncpy(tmp[i].loglevel, uevent->attr.loglevel, LTTNG_SYMBOL_NAME_LEN); - tmp[i].loglevel[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; + tmp[i].loglevel = uevent->attr.loglevel; switch (uevent->attr.loglevel_type) { - case LTTNG_UST_LOGLEVEL: - tmp[i].type = LTTNG_EVENT_LOGLEVEL; + case LTTNG_UST_LOGLEVEL_ALL: + tmp[i].type = LTTNG_EVENT_LOGLEVEL_ALL; break; - case LTTNG_UST_LOGLEVEL_ONLY: - tmp[i].type = LTTNG_EVENT_LOGLEVEL_ONLY; + case LTTNG_UST_LOGLEVEL_RANGE: + tmp[i].type = LTTNG_EVENT_LOGLEVEL_RANGE; + break; + case LTTNG_UST_LOGLEVEL_SINGLE: + tmp[i].type = LTTNG_EVENT_LOGLEVEL_SINGLE; break; } i++; diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index 0a90cac0e..7f422a99e 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -223,20 +223,22 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev) lue->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; switch (ev->loglevel_type) { - case LTTNG_EVENT_LOGLEVEL: - lue->attr.loglevel_type = LTTNG_UST_LOGLEVEL; + case LTTNG_EVENT_LOGLEVEL_ALL: + lue->attr.loglevel_type = LTTNG_UST_LOGLEVEL_ALL; break; - case LTTNG_EVENT_LOGLEVEL_ONLY: - lue->attr.loglevel_type = LTTNG_UST_LOGLEVEL_ONLY; + case LTTNG_EVENT_LOGLEVEL_RANGE: + lue->attr.loglevel_type = LTTNG_UST_LOGLEVEL_RANGE; + break; + case LTTNG_EVENT_LOGLEVEL_SINGLE: + lue->attr.loglevel_type = LTTNG_UST_LOGLEVEL_SINGLE; break; default: ERR("Unknown ust loglevel type (%d)", ev->type); goto error_free_event; } - /* Copy loglevel name */ - strncpy(lue->attr.loglevel, ev->loglevel, LTTNG_UST_SYM_NAME_LEN); - lue->attr.loglevel[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; + /* Copy loglevel */ + lue->attr.loglevel = ev->loglevel; /* Init node */ lttng_ht_node_init_str(&lue->node, lue->attr.name); diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 8e329a29f..778880487 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -1420,9 +1420,8 @@ int ust_app_list_events(struct lttng_event **events) } } memcpy(tmp[count].name, uiter.name, LTTNG_UST_SYM_NAME_LEN); - memcpy(tmp[count].loglevel, uiter.loglevel, LTTNG_UST_SYM_NAME_LEN); + tmp[count].loglevel = uiter.loglevel; tmp[count].type = LTTNG_UST_TRACEPOINT; - tmp[count].loglevel_value = uiter.loglevel_value; tmp[count].pid = app->key.pid; tmp[count].enabled = -1; count++; diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 449f20f47..6e912c116 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -209,6 +209,66 @@ end: return ret; } +/* + * Maps this from string to value + * + * TRACE_EMERG = 0, + * TRACE_ALERT = 1, + * TRACE_CRIT = 2, + * TRACE_ERR = 3, + * TRACE_WARNING = 4, + * TRACE_NOTICE = 5, + * TRACE_INFO = 6, + * TRACE_SYSTEM = 7, + * TRACE_PROCESS = 8, + * TRACE_MODULE = 9, + * TRACE_UNIT = 10, + * TRACE_CLASS = 11, + * TRACE_OBJECT = 12, + * TRACE_FUNCTION = 13, + * TRACE_PRINTF = 14, + * TRACE_DEBUG = 15, + */ +static +int loglevel_str_to_value(const char *str) +{ + if (!strcmp(str, "TRACE_EMERG")) { + return 0; + } else if (!strcmp(str, "TRACE_ALERT")) { + return 1; + } else if (!strcmp(str, "TRACE_CRIT")) { + return 2; + } else if (!strcmp(str, "TRACE_ERR")) { + return 3; + } else if (!strcmp(str, "TRACE_WARNING")) { + return 4; + } else if (!strcmp(str, "TRACE_NOTICE")) { + return 5; + } else if (!strcmp(str, "TRACE_INFO")) { + return 6; + } else if (!strcmp(str, "TRACE_SYSTEM")) { + return 7; + } else if (!strcmp(str, "TRACE_PROCESS")) { + return 8; + } else if (!strcmp(str, "TRACE_MODULE")) { + return 9; + } else if (!strcmp(str, "TRACE_UNIT")) { + return 10; + } else if (!strcmp(str, "TRACE_CLASS")) { + return 11; + } else if (!strcmp(str, "TRACE_OBJECT")) { + return 12; + } else if (!strcmp(str, "TRACE_FUNCTION")) { + return 13; + } else if (!strcmp(str, "TRACE_PRINTF")) { + return 14; + } else if (!strcmp(str, "TRACE_DEBUG")) { + return 15; + } else { + return -1; + } +} + /* * Enabling event using the lttng API. */ @@ -341,8 +401,7 @@ static int enable_events(char *session_name) } /* kernel loglevels not implemented */ - ev.loglevel_type = opt_loglevel_type; - ev.loglevel[0] = '\0'; + ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; } else if (opt_userspace) { /* User-space tracer action */ #if 0 if (opt_cmd_name != NULL || opt_pid) { @@ -376,10 +435,11 @@ static int enable_events(char *session_name) ev.loglevel_type = opt_loglevel_type; if (opt_loglevel) { - strncpy(ev.loglevel, opt_loglevel, LTTNG_SYMBOL_NAME_LEN); - ev.loglevel[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; - } else { - ev.loglevel[0] = '\0'; + ev.loglevel = loglevel_str_to_value(opt_loglevel); + if (ev.loglevel == -1) { + ERR("Unknown loglevel %s", opt_loglevel); + goto error; + } } } else { ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); @@ -452,11 +512,11 @@ int cmd_enable_events(int argc, const char **argv) opt_userspace = 1; break; case OPT_LOGLEVEL: - opt_loglevel_type = LTTNG_EVENT_LOGLEVEL; + opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE; opt_loglevel = poptGetOptArg(pc); break; case OPT_LOGLEVEL_ONLY: - opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_ONLY; + opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE; opt_loglevel = poptGetOptArg(pc); break; case OPT_LIST_OPTIONS: diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index ef1efc793..c22206952 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -145,9 +145,9 @@ const char *enabled_string(int value) } static -const char *loglevel_string_pre(const char *loglevel) +const char *loglevel_string_pre(int loglevel) { - if (loglevel[0] == '\0') { + if (loglevel == -1) { return ""; } else { return " (loglevel: "; @@ -155,15 +155,39 @@ const char *loglevel_string_pre(const char *loglevel) } static -const char *loglevel_string_post(const char *loglevel) +const char *loglevel_string_post(int loglevel) { - if (loglevel[0] == '\0') { + if (loglevel == -1) { return ""; } else { return ")"; } } +static const char *loglevel_string(int value) +{ + switch (value) { + case -1: return ""; + case 0: return "TRACE_EMERG"; + case 1: return "TRACE_ALERT"; + case 2: return "TRACE_CRIT"; + case 3: return "TRACE_ERR"; + case 4: return "TRACE_WARNING"; + case 5: return "TRACE_NOTICE"; + case 6: return "TRACE_INFO"; + case 7: return "TRACE_SYSTEM"; + case 8: return "TRACE_PROCESS"; + case 9: return "TRACE_MODULE"; + case 10: return "TRACE_UNIT"; + case 11: return "TRACE_CLASS"; + case 12: return "TRACE_OBJECT"; + case 13: return "TRACE_FUNCTION"; + case 14: return "TRACE_PRINTF"; + case 15: return "TRACE_DEBUG"; + default: return "<>"; + } +} + /* * Pretty print single event. */ @@ -172,22 +196,11 @@ static void print_events(struct lttng_event *event) switch (event->type) { case LTTNG_EVENT_TRACEPOINT: { - char ll_value[LTTNG_SYMBOL_NAME_LEN] = ""; - - if (event->loglevel[0] != '\0') { - int ret; - - ret = snprintf(ll_value, LTTNG_SYMBOL_NAME_LEN, - " (%lld)", (long long) event->loglevel_value); - if (ret < 0) { - ERR("snprintf error"); - } - } - MSG("%s%s%s%s%s%s (type: tracepoint)%s", indent6, + MSG("%s%s%s%s%d%s (type: tracepoint)%s", indent6, event->name, loglevel_string_pre(event->loglevel), + loglevel_string(event->loglevel), event->loglevel, - ll_value, loglevel_string_post(event->loglevel), enabled_string(event->enabled)); break; diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 438320d97..48658a42d 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -465,12 +465,14 @@ static int parse_args(int argc, char **argv) /* Spawn session daemon if needed */ if (opt_no_sessiond == 0 && check_args_no_sessiond(argc, argv) == 0 && (check_sessiond() < 0)) { + ret = 1; goto error; } /* No leftovers, print usage and quit */ if ((argc - optind) == 0) { usage(stderr); + ret = 1; goto error; } diff --git a/tests/lttng/ust_global_all_events_basic.c b/tests/lttng/ust_global_all_events_basic.c index b141057c6..56746a73f 100644 --- a/tests/lttng/ust_global_all_events_basic.c +++ b/tests/lttng/ust_global_all_events_basic.c @@ -42,8 +42,7 @@ int main(int argc, char **argv) memset(&event, 0, sizeof(struct lttng_event)); event.type = LTTNG_EVENT_TRACEPOINT; - event.loglevel[0] = '\0'; - event.loglevel_type = LTTNG_EVENT_LOGLEVEL; + event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; printf("\nTesting tracing all UST events:\n"); printf("-----------\n"); diff --git a/tests/lttng/ust_global_event_basic.c b/tests/lttng/ust_global_event_basic.c index ac0687daa..5a7af53e2 100644 --- a/tests/lttng/ust_global_event_basic.c +++ b/tests/lttng/ust_global_event_basic.c @@ -52,18 +52,15 @@ int main(int argc, char **argv) strcpy(ev1.name, "tp1"); ev1.type = LTTNG_EVENT_TRACEPOINT; - ev1.loglevel[0] = '\0'; - ev1.loglevel_type = LTTNG_EVENT_LOGLEVEL; + ev1.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; strcpy(ev2.name, "ev2"); ev2.type = LTTNG_EVENT_TRACEPOINT; - ev2.loglevel[0] = '\0'; - ev2.loglevel_type = LTTNG_EVENT_LOGLEVEL; + ev2.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; strcpy(ev3.name, "ev3"); ev3.type = LTTNG_EVENT_TRACEPOINT; - ev3.loglevel[0] = '\0'; - ev3.loglevel_type = LTTNG_EVENT_LOGLEVEL; + ev3.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; printf("\nTesting tracing UST events:\n"); printf("-----------\n");