/*
* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _GNU_SOURCE
static int opt_kernel;
static char *opt_channel;
static int opt_domain;
+static int opt_fields;
#if 0
/* Not implemented yet */
static char *opt_cmd_name;
#endif
{"channel", 'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
{"domain", 'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
+ {"fields", 'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0},
{"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
{0, 0, 0, 0, 0, 0, 0}
};
fprintf(ofp, " --list-options Simple listing of options\n");
fprintf(ofp, " -k, --kernel Select kernel domain\n");
fprintf(ofp, " -u, --userspace Select user-space domain.\n");
+ fprintf(ofp, " -f, --fields List event fields.\n");
#if 0
fprintf(ofp, " -p, --pid PID List user-space events by PID\n");
#endif
}
static
-const char *loglevel_string_pre(int loglevel)
+const char *filter_string(int value)
{
- if (loglevel == -1) {
- return "";
- } else {
- return " (loglevel: ";
- }
-}
-
-static
-const char *loglevel_string_post(int loglevel)
-{
- if (loglevel == -1) {
- return "";
- } else {
- return ")";
+ switch (value) {
+ case 1: return " [with filter]";
+ default: 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_PROGRAM";
- case 9: return "TRACE_PROCESS";
- case 10: return "TRACE_MODULE";
- case 11: return "TRACE_UNIT";
- case 12: return "TRACE_FUNCTION";
- case 13: return "TRACE_DEFAULT";
- case 14: return "TRACE_VERBOSE";
- case 15: return "TRACE_DEBUG";
- default: return "<<UNKNOWN>>";
+ case -1:
+ return "";
+ case LTTNG_LOGLEVEL_EMERG:
+ return "TRACE_EMERG";
+ case LTTNG_LOGLEVEL_ALERT:
+ return "TRACE_ALERT";
+ case LTTNG_LOGLEVEL_CRIT:
+ return "TRACE_CRIT";
+ case LTTNG_LOGLEVEL_ERR:
+ return "TRACE_ERR";
+ case LTTNG_LOGLEVEL_WARNING:
+ return "TRACE_WARNING";
+ case LTTNG_LOGLEVEL_NOTICE:
+ return "TRACE_NOTICE";
+ case LTTNG_LOGLEVEL_INFO:
+ return "TRACE_INFO";
+ case LTTNG_LOGLEVEL_DEBUG_SYSTEM:
+ return "TRACE_DEBUG_SYSTEM";
+ case LTTNG_LOGLEVEL_DEBUG_PROGRAM:
+ return "TRACE_DEBUG_PROGRAM";
+ case LTTNG_LOGLEVEL_DEBUG_PROCESS:
+ return "TRACE_DEBUG_PROCESS";
+ case LTTNG_LOGLEVEL_DEBUG_MODULE:
+ return "TRACE_DEBUG_MODULE";
+ case LTTNG_LOGLEVEL_DEBUG_UNIT:
+ return "TRACE_DEBUG_UNIT";
+ case LTTNG_LOGLEVEL_DEBUG_FUNCTION:
+ return "TRACE_DEBUG_FUNCTION";
+ case LTTNG_LOGLEVEL_DEBUG_LINE:
+ return "TRACE_DEBUG_LINE";
+ case LTTNG_LOGLEVEL_DEBUG:
+ return "TRACE_DEBUG";
+ default:
+ return "<<UNKNOWN>>";
}
}
switch (event->type) {
case LTTNG_EVENT_TRACEPOINT:
{
- MSG("%s%s%s%s%s (type: tracepoint)%s", indent6,
+ if (event->loglevel != -1) {
+ MSG("%s%s (loglevel: %s (%d)) (type: tracepoint)%s%s",
+ indent6,
event->name,
- loglevel_string_pre(event->loglevel),
loglevel_string(event->loglevel),
- loglevel_string_post(event->loglevel),
- enabled_string(event->enabled));
+ event->loglevel,
+ enabled_string(event->enabled),
+ filter_string(event->filter));
+ } else {
+ MSG("%s%s (type: tracepoint)%s%s",
+ indent6,
+ event->name,
+ enabled_string(event->enabled),
+ filter_string(event->filter));
+ }
break;
}
+ case LTTNG_EVENT_FUNCTION:
+ MSG("%s%s (type: function)%s%s", indent6,
+ event->name, enabled_string(event->enabled),
+ filter_string(event->filter));
+ if (event->attr.probe.addr != 0) {
+ MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
+ } else {
+ MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
+ MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
+ }
+ break;
case LTTNG_EVENT_PROBE:
- MSG("%s%s (type: probe)%s", indent6,
- event->name, enabled_string(event->enabled));
+ MSG("%s%s (type: probe)%s%s", indent6,
+ event->name, enabled_string(event->enabled),
+ filter_string(event->filter));
if (event->attr.probe.addr != 0) {
MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
} else {
MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
}
break;
- case LTTNG_EVENT_FUNCTION:
case LTTNG_EVENT_FUNCTION_ENTRY:
- MSG("%s%s (type: function)%s", indent6,
- event->name, enabled_string(event->enabled));
+ MSG("%s%s (type: function)%s%s", indent6,
+ event->name, enabled_string(event->enabled),
+ filter_string(event->filter));
MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name);
break;
case LTTNG_EVENT_SYSCALL:
- MSG("%s (type: syscall)%s", indent6,
- enabled_string(event->enabled));
+ MSG("%ssyscalls (type: syscall)%s%s", indent6,
+ enabled_string(event->enabled),
+ filter_string(event->filter));
break;
case LTTNG_EVENT_NOOP:
- MSG("%s (type: noop)%s", indent6,
- enabled_string(event->enabled));
+ MSG("%s (type: noop)%s%s", indent6,
+ enabled_string(event->enabled),
+ filter_string(event->filter));
break;
case LTTNG_EVENT_ALL:
/* We should never have "all" events in list. */
}
}
+static const char *field_type(struct lttng_event_field *field)
+{
+ switch(field->type) {
+ case LTTNG_EVENT_FIELD_INTEGER:
+ return "integer";
+ case LTTNG_EVENT_FIELD_ENUM:
+ return "enum";
+ case LTTNG_EVENT_FIELD_FLOAT:
+ return "float";
+ case LTTNG_EVENT_FIELD_STRING:
+ return "string";
+ case LTTNG_EVENT_FIELD_OTHER:
+ default: /* fall-through */
+ return "unknown";
+ }
+}
+
+/*
+ * Pretty print single event fields.
+ */
+static void print_event_field(struct lttng_event_field *field)
+{
+ if (!field->field_name[0]) {
+ return;
+ }
+ MSG("%sfield: %s (%s)%s", indent8, field->field_name,
+ field_type(field), field->nowrite ? " [no write]" : "");
+}
+
/*
* Ask session daemon for all user space tracepoints available.
*/
struct lttng_handle *handle;
struct lttng_event *event_list;
pid_t cur_pid = 0;
+ char *cmdline = NULL;
memset(&domain, 0, sizeof(domain));
size = lttng_list_tracepoints(handle, &event_list);
if (size < 0) {
ERR("Unable to list UST events");
+ lttng_destroy_handle(handle);
return size;
}
for (i = 0; i < size; i++) {
if (cur_pid != event_list[i].pid) {
cur_pid = event_list[i].pid;
- MSG("\nPID: %d - Name: %s", cur_pid, get_cmdline_by_pid(cur_pid));
+ cmdline = get_cmdline_by_pid(cur_pid);
+ MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
+ free(cmdline);
}
print_events(&event_list[i]);
}
MSG("");
free(event_list);
+ lttng_destroy_handle(handle);
+
+ return CMD_SUCCESS;
+
+error:
+ lttng_destroy_handle(handle);
+ return -1;
+}
+
+/*
+ * Ask session daemon for all user space tracepoint fields available.
+ */
+static int list_ust_event_fields(void)
+{
+ int i, size;
+ struct lttng_domain domain;
+ struct lttng_handle *handle;
+ struct lttng_event_field *event_field_list;
+ pid_t cur_pid = 0;
+ char *cmdline = NULL;
+
+ struct lttng_event cur_event;
+
+ memset(&domain, 0, sizeof(domain));
+ memset(&cur_event, 0, sizeof(cur_event));
+
+ DBG("Getting UST tracing event fields");
+
+ domain.type = LTTNG_DOMAIN_UST;
+
+ handle = lttng_create_handle(NULL, &domain);
+ if (handle == NULL) {
+ goto error;
+ }
+
+ size = lttng_list_tracepoint_fields(handle, &event_field_list);
+ if (size < 0) {
+ ERR("Unable to list UST event fields");
+ lttng_destroy_handle(handle);
+ return size;
+ }
+
+ MSG("UST events:\n-------------");
+
+ if (size == 0) {
+ MSG("None");
+ }
+
+ for (i = 0; i < size; i++) {
+ if (cur_pid != event_field_list[i].event.pid) {
+ cur_pid = event_field_list[i].event.pid;
+ cmdline = get_cmdline_by_pid(cur_pid);
+ MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
+ free(cmdline);
+ }
+ if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
+ print_events(&event_field_list[i].event);
+ memcpy(&cur_event, &event_field_list[i].event,
+ sizeof(cur_event));
+ }
+ print_event_field(&event_field_list[i]);
+ }
+
+ MSG("");
+
+ free(event_field_list);
+ lttng_destroy_handle(handle);
return CMD_SUCCESS;
error:
+ lttng_destroy_handle(handle);
return -1;
}
size = lttng_list_tracepoints(handle, &event_list);
if (size < 0) {
ERR("Unable to list kernel events");
+ lttng_destroy_handle(handle);
return size;
}
free(event_list);
+ lttng_destroy_handle(handle);
return CMD_SUCCESS;
error:
+ lttng_destroy_handle(handle);
return -1;
}
MSG("");
end:
- if (events) {
- free(events);
- }
+ free(events);
ret = CMD_SUCCESS;
error:
count = lttng_list_channels(handle, &channels);
if (count < 0) {
- ret = count;
+ switch (-count) {
+ case LTTNG_ERR_KERN_CHAN_NOT_FOUND:
+ ret = CMD_SUCCESS;
+ WARN("No kernel channel");
+ break;
+ default:
+ /* We had a real error */
+ ret = count;
+ ERR("%s", lttng_strerror(ret));
+ }
goto error_channels;
- } else if (count == 0) {
- ERR("Channel %s not found", channel_name);
- goto error;
}
if (channel_name == NULL) {
DBG("Session count %d", count);
if (count < 0) {
ret = count;
+ ERR("%s", lttng_strerror(ret));
goto error;
+ } else if (count == 0) {
+ MSG("Currently no available tracing session");
+ goto end;
}
if (session_name == NULL) {
MSG("\nUse lttng list <session_name> for more details");
}
+end:
return CMD_SUCCESS;
error:
*/
int cmd_list(int argc, const char **argv)
{
- int opt, i, ret = CMD_SUCCESS;
- int nb_domain;
+ int opt, ret = CMD_SUCCESS;
const char *session_name;
static poptContext pc;
struct lttng_domain domain;
domain.type = LTTNG_DOMAIN_UST;
}
- handle = lttng_create_handle(session_name, &domain);
- if (handle == NULL) {
- ret = CMD_FATAL;
- goto end;
+ if (opt_kernel || opt_userspace) {
+ handle = lttng_create_handle(session_name, &domain);
+ if (handle == NULL) {
+ ret = CMD_FATAL;
+ goto end;
+ }
}
if (session_name == NULL) {
if (opt_kernel) {
ret = list_kernel_events();
if (ret < 0) {
+ ret = CMD_ERROR;
goto end;
}
}
if (opt_userspace) {
- ret = list_ust_events();
+ if (opt_fields) {
+ ret = list_ust_event_fields();
+ } else {
+ ret = list_ust_events();
+ }
if (ret < 0) {
+ ret = CMD_ERROR;
goto end;
}
}
goto end;
}
} else {
+ int i, nb_domain;
+
/* We want all domain(s) */
nb_domain = lttng_list_domains(session_name, &domains);
if (nb_domain < 0) {
}
/* Clean handle before creating a new one */
- lttng_destroy_handle(handle);
+ if (handle) {
+ lttng_destroy_handle(handle);
+ }
handle = lttng_create_handle(session_name, &domains[i]);
if (handle == NULL) {
}
end:
- if (domains) {
- free(domains);
+ free(domains);
+ if (handle) {
+ lttng_destroy_handle(handle);
}
- lttng_destroy_handle(handle);
poptFreeContext(pc);
return ret;