Change list kernel events to list tracepoints
[lttng-tools.git] / liblttngctl / liblttngctl.c
index e693123b9c1c384b5d18f8f9eaa1d64984fe991d..17bb4105ae0f9045907ca492565c579962278d5b 100644 (file)
@@ -1,19 +1,23 @@
 /*
+ * liblttngctl.c
+ *
+ * Linux Trace Toolkit Control Library
+ *
  * 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; either version 2
- * of the License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #define _GNU_SOURCE
@@ -204,6 +208,14 @@ static int disconnect_sessiond(void)
        return ret;
 }
 
+/*
+ * Reset the session message structure.
+ */
+static void reset_session_msg(void)
+{
+       memset(&lsm, 0, sizeof(struct lttcomm_session_msg));
+}
+
 /*
  *  ask_sessiond
  *
@@ -262,9 +274,30 @@ static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf)
 
 end:
        disconnect_sessiond();
+       reset_session_msg();
        return ret;
 }
 
+/*
+ * Copy domain to lttcomm_session_msg domain.
+ *
+ * Return -1 if the domain is unkown.
+ */
+static int copy_lttng_domain(struct lttng_domain *dom)
+{
+       switch (dom->type) {
+       case LTTNG_DOMAIN_KERNEL:
+       case LTTNG_DOMAIN_UST:
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
+       case LTTNG_DOMAIN_UST_PID:
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+               memcpy(&lsm.domain, dom, sizeof(struct lttng_domain));
+               return 0;
+       default:
+               return -1;
+       }
+}
+
 /*
  *  Start tracing for all trace of the session.
  */
@@ -435,18 +468,24 @@ int lttng_disable_channel(struct lttng_domain *domain, const char *name)
 }
 
 /*
- * List all available events in the kernel.
+ * List all available tracepoints of domain.
  *
- * Return the size (bytes) of the list and set the event_list array.
+ * Return the size (bytes) of the list and set the events array.
  * On error, return negative value.
  */
-int lttng_list_events(struct lttng_domain *domain, char **event_list)
+int lttng_list_tracepoints(struct lttng_domain *domain,
+               struct lttng_event **events)
 {
        int ret;
 
+       ret = copy_lttng_domain(domain);
+       if (ret < 0) {
+               return -LTTCOMM_UNKNOWN_DOMAIN;
+       }
+
        switch (domain->type) {
                case LTTNG_DOMAIN_KERNEL:
-                       ret = ask_sessiond(LTTNG_KERNEL_LIST_EVENTS, (void **) event_list);
+                       ret = ask_sessiond(LTTNG_KERNEL_LIST_EVENTS, (void **) events);
                        break;
                case LTTNG_DOMAIN_UST:
                        ret = LTTCOMM_NOT_IMPLEMENTED;
@@ -456,7 +495,7 @@ int lttng_list_events(struct lttng_domain *domain, char **event_list)
                        break;
        };
 
-       return ret;
+       return ret / sizeof(struct lttng_event);
 }
 
 /*
@@ -508,6 +547,68 @@ int lttng_list_sessions(struct lttng_session **sessions)
        return ret / sizeof(struct lttng_session);
 }
 
+/*
+ * List domain of a session.
+ */
+int lttng_list_domains(const char *session_name, struct lttng_domain **domains)
+{
+       int ret;
+
+       strncpy(lsm.session_name, session_name, NAME_MAX);
+       ret = ask_sessiond(LTTNG_LIST_DOMAINS, (void**) domains);
+       if (ret < 0) {
+               return ret;
+       }
+
+       return ret / sizeof(struct lttng_domain);
+}
+
+/*
+ * List channels of a session
+ */
+int lttng_list_channels(struct lttng_domain *domain,
+               const char *session_name, struct lttng_channel **channels)
+{
+       int ret;
+
+       strncpy(lsm.session_name, session_name, NAME_MAX);
+       ret = copy_lttng_domain(domain);
+       if (ret < 0) {
+               return -LTTCOMM_UNKNOWN_DOMAIN;
+       }
+
+       ret = ask_sessiond(LTTNG_LIST_CHANNELS, (void**) channels);
+       if (ret < 0) {
+               return ret;
+       }
+
+       return ret / sizeof(struct lttng_channel);
+}
+
+/*
+ * List events of a session channel.
+ */
+int lttng_list_events(struct lttng_domain *domain,
+               const char *session_name, const char *channel_name,
+               struct lttng_event **events)
+{
+       int ret;
+
+       strncpy(lsm.session_name, session_name, NAME_MAX);
+       strncpy(lsm.u.list.channel_name, channel_name, NAME_MAX);
+       ret = copy_lttng_domain(domain);
+       if (ret < 0) {
+               return -LTTCOMM_UNKNOWN_DOMAIN;
+       }
+
+       ret = ask_sessiond(LTTNG_LIST_EVENTS, (void**) events);
+       if (ret < 0) {
+               return ret;
+       }
+
+       return ret / sizeof(struct lttng_event);
+}
+
 /*
  * Set session name for the current lsm.
  */
This page took 0.028678 seconds and 5 git commands to generate.