}
}
+/*
+ * Create a list of JUL domain events.
+ *
+ * Return number of events in list on success or else a negative value.
+ */
+static int list_lttng_jul_events(struct jul_domain *dom,
+ struct lttng_event **events)
+{
+ int i = 0, ret = 0;
+ unsigned int nb_event = 0;
+ struct jul_event *event;
+ struct lttng_event *tmp_events;
+ struct lttng_ht_iter iter;
+
+ assert(dom);
+ assert(events);
+
+ DBG3("Listing JUL events");
+
+ nb_event = lttng_ht_get_count(dom->events);
+ if (nb_event == 0) {
+ ret = nb_event;
+ goto error;
+ }
+
+ tmp_events = zmalloc(nb_event * sizeof(*tmp_events));
+ if (!tmp_events) {
+ PERROR("zmalloc JUL events session");
+ ret = -LTTNG_ERR_FATAL;
+ goto error;
+ }
+
+ rcu_read_lock();
+ cds_lfht_for_each_entry(dom->events->ht, &iter.iter, event, node.node) {
+ strncpy(tmp_events[i].name, event->name, sizeof(tmp_events[i].name));
+ tmp_events[i].name[sizeof(tmp_events[i].name) - 1] = '\0';
+ tmp_events[i].enabled = event->enabled;
+ i++;
+ }
+ rcu_read_unlock();
+
+ *events = tmp_events;
+ ret = nb_event;
+
+error:
+ assert(nb_event == i);
+ return ret;
+}
+
/*
* Create a list of ust global domain events.
*/
goto error;
}
break;
+ case LTTNG_DOMAIN_JUL:
+ nb_events = jul_list_events(events);
+ if (nb_events < 0) {
+ ret = LTTNG_ERR_UST_LIST_FAIL;
+ goto error;
+ }
+ break;
default:
ret = LTTNG_ERR_UND;
goto error;
if (session->ust_session != NULL) {
DBG3("Listing domains found UST global domain");
nb_dom++;
+
+ if (session->ust_session->domain_jul.being_used) {
+ nb_dom++;
+ }
}
*domains = zmalloc(nb_dom * sizeof(struct lttng_domain));
(*domains)[index].type = LTTNG_DOMAIN_UST;
(*domains)[index].buf_type = session->ust_session->buffer_type;
index++;
+
+ if (session->ust_session->domain_jul.being_used) {
+ (*domains)[index].type = LTTNG_DOMAIN_JUL;
+ (*domains)[index].buf_type = session->ust_session->buffer_type;
+ index++;
+ }
}
return nb_dom;
}
break;
}
+ case LTTNG_DOMAIN_JUL:
+ if (session->ust_session) {
+ nb_event = list_lttng_jul_events(
+ &session->ust_session->domain_jul, events);
+ }
+ break;
default:
ret = LTTNG_ERR_UND;
goto error;
return ret;
}
+
+/*
+ * Internal call to list events on a given app. Populate events.
+ *
+ * Return number of element in the list or else a negative LTTNG_ERR* code.
+ */
+static ssize_t list_events(struct jul_app *app, struct lttng_event **events)
+{
+ int ret, i, len = 0, offset = 0;
+ uint32_t nb_event;
+ size_t data_size;
+ struct lttng_event *tmp_events = NULL;
+ struct lttcomm_jul_list_reply *reply = NULL;
+ struct lttcomm_jul_list_reply_hdr reply_hdr;
+
+ assert(app);
+ assert(app->sock);
+ assert(events);
+
+ DBG2("JUL listing events for app pid: %d and socket %d", app->pid,
+ app->sock->fd);
+
+ ret = send_header(app->sock, 0, JUL_CMD_LIST, 0);
+ if (ret < 0) {
+ goto error_io;
+ }
+
+ /* Get list header so we know how much we'll receive. */
+ ret = recv_reply(app->sock, &reply_hdr, sizeof(reply_hdr));
+ if (ret < 0) {
+ goto error_io;
+ }
+
+ switch (be32toh(reply_hdr.ret_code)) {
+ case JUL_RET_CODE_SUCCESS:
+ data_size = be32toh(reply_hdr.data_size) + sizeof(*reply);
+ break;
+ default:
+ ERR("Java agent returned an unknown code: %" PRIu32,
+ be32toh(reply_hdr.ret_code));
+ ret = LTTNG_ERR_FATAL;
+ goto error;
+ }
+
+ reply = zmalloc(data_size);
+ if (!reply) {
+ ret = LTTNG_ERR_NOMEM;
+ goto error;
+ }
+
+ /* Get the list with the appropriate data size. */
+ ret = recv_reply(app->sock, reply, data_size);
+ if (ret < 0) {
+ goto error_io;
+ }
+
+ nb_event = be32toh(reply->nb_event);
+ tmp_events = zmalloc(sizeof(*tmp_events) * nb_event);
+ if (!tmp_events) {
+ ret = LTTNG_ERR_NOMEM;
+ goto error;
+ }
+
+ for (i = 0; i < nb_event; i++) {
+ offset += len;
+ strncpy(tmp_events[i].name, reply->payload + offset,
+ sizeof(tmp_events[i].name));
+ tmp_events[i].pid = app->pid;
+ tmp_events[i].enabled = -1;
+ len = strlen(reply->payload + offset) + 1;
+ }
+
+ *events = tmp_events;
+
+ free(reply);
+ return nb_event;
+
+error_io:
+ ret = LTTNG_ERR_UST_LIST_FAIL;
+error:
+ free(reply);
+ free(tmp_events);
+ return -ret;
+
+}
+
/*
* Internal enable JUL event call on a JUL application. This function
* communicates with the Java agent to enable a given event (Logger name).
if (ret != LTTNG_OK) {
goto error;
}
- event->enabled = 1;
}
+ event->enabled = 1;
ret = LTTNG_OK;
error:
if (ret != LTTNG_OK) {
goto error;
}
- event->enabled = 0;
}
+ event->enabled = 0;
ret = LTTNG_OK;
error:
rcu_read_lock();
lttng_ht_add_unique_str(dom->events, &event->node);
rcu_read_unlock();
+ dom->being_used = 1;
}
/*
static int opt_userspace;
static int opt_kernel;
+static int opt_jul;
static char *opt_channel;
static int opt_domain;
static int opt_fields;
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
{"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
{"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
+ {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
#if 0
/* Not implemented yet */
{"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 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, " -j, --jul Apply for Java application using JUL\n");
fprintf(ofp, " -f, --fields List event fields.\n");
#if 0
fprintf(ofp, " -p, --pid PID List user-space events by PID\n");
field_type(field), field->nowrite ? " [no write]" : "");
}
+static int list_jul_events(void)
+{
+ int i, size;
+ struct lttng_domain domain;
+ struct lttng_handle *handle;
+ struct lttng_event *event_list;
+ pid_t cur_pid = 0;
+ char *cmdline = NULL;
+
+ DBG("Getting JUL tracing events");
+
+ memset(&domain, 0, sizeof(domain));
+ domain.type = LTTNG_DOMAIN_JUL;
+
+ handle = lttng_create_handle(NULL, &domain);
+ if (handle == NULL) {
+ goto error;
+ }
+
+ size = lttng_list_tracepoints(handle, &event_list);
+ if (size < 0) {
+ ERR("Unable to list JUL events: %s", lttng_strerror(size));
+ lttng_destroy_handle(handle);
+ return size;
+ }
+
+ MSG("JUL events (Logger name):\n-------------------------");
+
+ if (size == 0) {
+ MSG("None");
+ }
+
+ for (i = 0; i < size; i++) {
+ if (cur_pid != event_list[i].pid) {
+ cur_pid = event_list[i].pid;
+ cmdline = get_cmdline_by_pid(cur_pid);
+ MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
+ free(cmdline);
+ }
+ MSG("%s- %s", indent6, event_list[i].name);
+ }
+
+ 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 tracepoints available.
*/
return -1;
}
+/*
+ * List JUL events for a specific session using the handle.
+ *
+ * Return CMD_SUCCESS on success else a negative value.
+ */
+static int list_session_jul_events(void)
+{
+ int ret, count, i;
+ struct lttng_event *events = NULL;
+
+ count = lttng_list_events(handle, "", &events);
+ if (count < 0) {
+ ret = count;
+ ERR("%s", lttng_strerror(ret));
+ goto error;
+ }
+
+ MSG("Events (Logger name):\n---------------------");
+ if (count == 0) {
+ MSG("%sNone\n", indent6);
+ goto end;
+ }
+
+ for (i = 0; i < count; i++) {
+ MSG("%s- %s%s", indent4, events[i].name,
+ enabled_string(events[i].enabled));
+ }
+
+ MSG("");
+
+end:
+ free(events);
+ ret = CMD_SUCCESS;
+
+error:
+ return ret;
+}
+
/*
* List events of channel of session and domain.
*/
case LTTNG_DOMAIN_UST:
MSG(" - UST global");
break;
+ case LTTNG_DOMAIN_JUL:
+ MSG(" - JUL (Java Util Logging)");
+ break;
default:
break;
}
} else if (opt_userspace) {
DBG2("Listing userspace global domain");
domain.type = LTTNG_DOMAIN_UST;
+ } else if (opt_jul) {
+ DBG2("Listing JUL domain");
+ domain.type = LTTNG_DOMAIN_JUL;
}
- if (opt_kernel || opt_userspace) {
+ if (opt_kernel || opt_userspace || opt_jul) {
handle = lttng_create_handle(session_name, &domain);
if (handle == NULL) {
ret = CMD_FATAL;
}
if (session_name == NULL) {
- if (!opt_kernel && !opt_userspace) {
+ if (!opt_kernel && !opt_userspace && !opt_jul) {
ret = list_sessions(NULL);
if (ret != 0) {
goto end;
goto end;
}
}
+ if (opt_jul) {
+ ret = list_jul_events();
+ if (ret < 0) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+ }
} else {
/* List session attributes */
ret = list_sessions(session_name);
domains[i].buf_type ==
LTTNG_BUFFER_PER_PID ? "per PID" : "per UID");
break;
+ case LTTNG_DOMAIN_JUL:
+ MSG("=== Domain: JUL (Java Util Logging) ===\n");
+ break;
default:
MSG("=== Domain: Unimplemented ===\n");
break;
goto end;
}
+ if (domains[i].type == LTTNG_DOMAIN_JUL) {
+ ret = list_session_jul_events();
+ if (ret < 0) {
+ goto end;
+ }
+ continue;
+ }
+
ret = list_channels(opt_channel);
if (ret < 0) {
goto end;