MI: Implement event context schema change
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 2 Mar 2016 18:27:59 +0000 (13:27 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 3 Mar 2016 22:19:42 +0000 (17:19 -0500)
src/common/mi-lttng.c
src/common/mi-lttng.h

index f77b6b648c30b541817c237cf0cfdb59f2f2afb0..e2a5917e9c6a22fd09ddba5ba75c282c05112ff4 100644 (file)
@@ -86,13 +86,8 @@ const char * const mi_lttng_element_version_web = "url";
 const char * const mi_lttng_element_event_field = "event_field";
 const char * const mi_lttng_element_event_fields = "event_fields";
 
-/* String related to lttng_event_context */
-const char * const mi_lttng_context_type_perf_counter = "PERF_COUNTER";
-const char * const mi_lttng_context_type_perf_cpu_counter = "PERF_CPU_COUNTER";
-const char * const mi_lttng_context_type_perf_thread_counter = "PERF_THREAD_COUNTER";
-
 /* String related to lttng_event_perf_counter_ctx */
-const char * const mi_lttng_element_perf_counter_context = "perf_counter_context";
+const char * const mi_lttng_element_perf_counter_context = "perf";
 
 /* Strings related to pid */
 const char * const mi_lttng_element_pid_id = "id";
@@ -342,18 +337,12 @@ const char *mi_lttng_eventtype_string(enum lttng_event_type value)
        }
 }
 
-LTTNG_HIDDEN
+static
 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val)
 {
        switch (val) {
        case LTTNG_EVENT_CONTEXT_PID:
                return config_event_context_pid;
-       case LTTNG_EVENT_CONTEXT_PERF_COUNTER:
-               return mi_lttng_context_type_perf_counter;
-       case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER:
-               return mi_lttng_context_type_perf_thread_counter;
-       case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER:
-               return mi_lttng_context_type_perf_cpu_counter;
        case LTTNG_EVENT_CONTEXT_PROCNAME:
                return config_event_context_procname;
        case LTTNG_EVENT_CONTEXT_PRIO:
@@ -1383,89 +1372,137 @@ end:
 }
 
 LTTNG_HIDDEN
-int mi_lttng_context(struct mi_writer *writer,
-               struct lttng_event_context *context, int is_open)
+int mi_lttng_perf_counter_context(struct mi_writer *writer,
+               struct lttng_event_perf_counter_ctx  *perf_context)
 {
        int ret;
-       const char *type_string;
-       struct lttng_event_perf_counter_ctx *perf_context;
-       /* Open context */
-       ret = mi_lttng_writer_open_element(writer , config_element_context);
+
+       /* Open perf_counter_context */
+       ret = mi_lttng_writer_open_element(writer,
+                       mi_lttng_element_perf_counter_context);
        if (ret) {
                goto end;
        }
 
-       type_string = mi_lttng_event_contexttype_string(context->ctx);
-       if (!type_string) {
-               ret = -LTTNG_ERR_INVALID;
+       /* Type */
+       ret = mi_lttng_writer_write_element_unsigned_int(writer,
+                       config_element_type, perf_context->type);
+       if (ret) {
                goto end;
        }
 
-       /* Print context type */
-       ret = mi_lttng_writer_write_element_string(writer, config_element_type,
-                       type_string);
-
-       /* Special case for PERF_*_COUNTER
-        * print the lttng_event_perf_counter_ctx*/
-       switch (context->ctx) {
-       case LTTNG_EVENT_CONTEXT_PERF_COUNTER:
-       case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER:
-       case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER:
-               perf_context = &context->u.perf_counter;
-               ret =  mi_lttng_perf_counter_context(writer, perf_context);
-               if (ret) {
-                       goto end;
-               }
-               break;
-       default:
-               break;
+       /* Config */
+       ret = mi_lttng_writer_write_element_unsigned_int(writer,
+                       config_element_config, perf_context->config);
+       if (ret) {
+               goto end;
        }
 
-       /* Close context */
-       if (!is_open) {
-               ret = mi_lttng_writer_close_element(writer);
+       /* Name of the perf counter */
+       ret = mi_lttng_writer_write_element_string(writer,
+                       config_element_name, perf_context->name);
+       if (ret) {
+               goto end;
        }
 
+       /* Close perf_counter_context */
+       ret = mi_lttng_writer_close_element(writer);
 end:
        return ret;
 }
 
-LTTNG_HIDDEN
-int mi_lttng_perf_counter_context(struct mi_writer *writer,
-               struct lttng_event_perf_counter_ctx  *perf_context)
+static
+int mi_lttng_app_context(struct mi_writer *writer,
+               const char *provider_name, const char *ctx_name)
 {
        int ret;
 
-       /* Open perf_counter_context */
+       /* Open app */
        ret = mi_lttng_writer_open_element(writer,
-                       mi_lttng_element_perf_counter_context);
+                       config_element_context_app);
        if (ret) {
                goto end;
        }
 
-       /* Type */
-       ret = mi_lttng_writer_write_element_unsigned_int(writer,
-                       config_element_type, perf_context->type);
+       /* provider_name */
+       ret = mi_lttng_writer_write_element_string(writer,
+                       config_element_context_app_provider_name,
+                       provider_name);
        if (ret) {
                goto end;
        }
 
-       /* Config */
-       ret = mi_lttng_writer_write_element_unsigned_int(writer,
-                       config_element_config, perf_context->config);
+       /* ctx_name */
+       ret = mi_lttng_writer_write_element_string(writer,
+                       config_element_context_app_ctx_name, ctx_name);
        if (ret) {
                goto end;
        }
 
-       /* Name of the perf counter */
-       ret = mi_lttng_writer_write_element_string(writer,
-                       config_element_name, perf_context->name);
+       /* Close app */
+       ret = mi_lttng_writer_close_element(writer);
+end:
+       return ret;
+}
+
+LTTNG_HIDDEN
+int mi_lttng_context(struct mi_writer *writer,
+               struct lttng_event_context *context, int is_open)
+{
+       int ret;
+
+       /* Open context */
+       ret = mi_lttng_writer_open_element(writer , config_element_context);
        if (ret) {
                goto end;
        }
 
-       /* Close perf_counter_context */
-       ret = mi_lttng_writer_close_element(writer);
+       /* Special case for PERF_*_COUNTER
+        * print the lttng_event_perf_counter_ctx*/
+       switch (context->ctx) {
+       case LTTNG_EVENT_CONTEXT_PERF_COUNTER:
+       case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER:
+       case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER:
+       {
+               struct lttng_event_perf_counter_ctx *perf_context =
+                               &context->u.perf_counter;
+               ret =  mi_lttng_perf_counter_context(writer, perf_context);
+               if (ret) {
+                       goto end;
+               }
+               break;
+       }
+       case LTTNG_EVENT_CONTEXT_APP_CONTEXT:
+       {
+               ret = mi_lttng_app_context(writer,
+                               context->u.app_ctx.provider_name,
+                               context->u.app_ctx.ctx_name);
+               if (ret) {
+                       goto end;
+               }
+               break;
+       }
+       default:
+       {
+               const char *type_string = mi_lttng_event_contexttype_string(
+                               context->ctx);
+               if (!type_string) {
+                       ret = -LTTNG_ERR_INVALID;
+                       goto end;
+               }
+
+               /* Print context type */
+               ret = mi_lttng_writer_write_element_string(writer,
+                               config_element_type, type_string);
+               break;
+       }
+       }
+
+       /* Close context */
+       if (!is_open) {
+               ret = mi_lttng_writer_close_element(writer);
+       }
+
 end:
        return ret;
 }
index ccf397141d5c7efc5677bb44a9f1dbb4a965394f..192f31804d5a177c45983fe292529d9682603e1a 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
  *                    - Olivier Cotte <olivier.cotte@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * 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
@@ -92,11 +93,6 @@ extern const char * const mi_lttng_element_version_web;
 extern const char * const mi_lttng_element_event_field;
 extern const char * const mi_lttng_element_event_fields;
 
-/* String related to lttng_event_context */
-extern const char * const mi_lttng_context_type_perf_counter;
-extern const char * const mi_lttng_context_type_perf_cpu_counter;
-extern const char * const mi_lttng_context_type_perf_thread_counter;
-
 /* String related to lttng_event_perf_counter_ctx */
 extern const char * const mi_lttng_element_perf_counter_context;
 
@@ -185,6 +181,9 @@ extern const char * const mi_lttng_element_snapshot_n_ptr;
 extern const char * const mi_lttng_element_snapshot_session_name;
 extern const char * const mi_lttng_element_snapshots;
 
+/* String related to track/untrack command */
+const char * const mi_lttng_element_track_untrack_all_wildcard;
+
 /* Utility string function  */
 const char *mi_lttng_loglevel_string(int value, enum lttng_domain_type domain);
 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value);
@@ -193,9 +192,6 @@ const char *mi_lttng_domaintype_string(enum lttng_domain_type value);
 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value);
 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val);
 
-/* String related to track/untrack command */
-const char * const mi_lttng_element_track_untrack_all_wildcard;
-
 /*
  * Create an instance of a machine interface writer.
  *
This page took 0.029622 seconds and 4 git commands to generate.