ust: cleanups and functionality
[ust.git] / libmarkers / marker.c
index 568cfb93848ac670ab2fd27372c2325b289e7657..198650b32d41846e0b8180c865ab5177e54119d7 100644 (file)
 #include "usterr.h"
 #include "channels.h"
 #include "tracercore.h"
+#include "tracer.h"
 
-extern struct marker __start___markers[];
-extern struct marker __stop___markers[];
+extern struct marker __start___markers[] __attribute__((visibility("hidden")));
+extern struct marker __stop___markers[] __attribute__((visibility("hidden")));
 
 /* Set to 1 to enable marker debug output */
 static const int marker_debug;
@@ -677,6 +678,20 @@ void marker_update_probe_range(struct marker *begin,
                        /*
                         * ignore error, continue
                         */
+
+                       /* This is added for UST. We emit a core_marker_id event
+                        * for markers that are already registered to a probe
+                        * upon library load. Otherwise, no core_marker_id will
+                        * be generated for these markers. Is this the right thing
+                        * to do?
+                        */
+                       trace_mark(metadata, core_marker_id,
+                                  "channel %s name %s event_id %hu "
+                                  "int #1u%zu long #1u%zu pointer #1u%zu "
+                                  "size_t #1u%zu alignment #1u%u",
+                                  iter->channel, iter->name, mark_entry->event_id,
+                                  sizeof(int), sizeof(long), sizeof(void *),
+                                  sizeof(size_t), ltt_get_alignment());
                } else {
                        disable_marker(iter);
                }
@@ -704,10 +719,11 @@ void marker_update_probe_range(struct marker *begin,
 static void marker_update_probes(void)
 {
        /* Core kernel markers */
-       marker_update_probe_range(__start___markers, __stop___markers);
+//ust//        marker_update_probe_range(__start___markers, __stop___markers);
        /* Markers in modules. */
 //ust//        module_update_markers();
-       tracepoint_probe_update_all();
+       lib_update_markers();
+//ust//        tracepoint_probe_update_all();
        /* Update immediate values */
        core_imv_update();
 //ust//        module_imv_update();
@@ -1031,7 +1047,7 @@ void *marker_get_private_data(const char *channel, const char *name,
 //ust//        }
 //ust// }
 
-#ifdef CONFIG_MODULES
+//ust//#ifdef CONFIG_MODULES
 
 /**
  * marker_get_iter_range - Get a next marker iterator given a range.
@@ -1060,14 +1076,15 @@ static void marker_get_iter(struct marker_iter *iter)
        int found = 0;
 
        /* Core kernel markers */
-       if (!iter->module) {
+       if (!iter->lib) {
+               /* ust FIXME: how come we cannot disable the following line? we shouldn't need core stuff */
                found = marker_get_iter_range(&iter->marker,
                                __start___markers, __stop___markers);
                if (found)
                        goto end;
        }
        /* Markers in modules. */
-       found = module_get_iter_markers(iter);
+       found = lib_get_iter_markers(iter);
 end:
        if (!found)
                marker_iter_reset(iter);
@@ -1098,7 +1115,7 @@ void marker_iter_stop(struct marker_iter *iter)
 
 void marker_iter_reset(struct marker_iter *iter)
 {
-       iter->module = NULL;
+       iter->lib = NULL;
        iter->marker = NULL;
 }
 //ust// EXPORT_SYMBOL_GPL(marker_iter_reset);
@@ -1338,7 +1355,7 @@ int is_marker_enabled(const char *channel, const char *name)
 
        return entry && !!entry->refcount;
 }
-#endif
+//ust// #endif
 
 int marker_module_notify(struct notifier_block *self,
                         unsigned long val, void *data)
@@ -1372,42 +1389,113 @@ struct notifier_block marker_module_nb = {
 
 #endif /* CONFIG_MODULES */
 
-//ust// void ltt_dump_marker_state(struct ltt_trace_struct *trace)
-//ust// {
-//ust//        struct marker_iter iter;
-//ust//        struct ltt_probe_private_data call_data;
-//ust//        const char *channel;
-//ust// 
-//ust//        call_data.trace = trace;
-//ust//        call_data.serializer = NULL;
-//ust// 
-//ust//        marker_iter_reset(&iter);
-//ust//        marker_iter_start(&iter);
-//ust//        for (; iter.marker != NULL; marker_iter_next(&iter)) {
-//ust//                if (!_imv_read(iter.marker->state))
-//ust//                        continue;
-//ust//                channel = ltt_channels_get_name_from_index(
-//ust//                                iter.marker->channel_id);
-//ust//                __trace_mark(0, metadata, core_marker_id,
-//ust//                        &call_data,
-//ust//                        "channel %s name %s event_id %hu "
-//ust//                        "int #1u%zu long #1u%zu pointer #1u%zu "
-//ust//                        "size_t #1u%zu alignment #1u%u",
-//ust//                        channel,
-//ust//                        iter.marker->name,
-//ust//                        iter.marker->event_id,
-//ust//                        sizeof(int), sizeof(long),
-//ust//                        sizeof(void *), sizeof(size_t),
-//ust//                        ltt_get_alignment());
-//ust//                if (iter.marker->format)
-//ust//                        __trace_mark(0, metadata,
-//ust//                                core_marker_format,
-//ust//                                &call_data,
-//ust//                                "channel %s name %s format %s",
-//ust//                                channel,
-//ust//                                iter.marker->name,
-//ust//                                iter.marker->format);
-//ust//        }
-//ust//        marker_iter_stop(&iter);
-//ust// }
+void ltt_dump_marker_state(struct ltt_trace_struct *trace)
+{
+       struct marker_iter iter;
+       struct ltt_probe_private_data call_data;
+       const char *channel;
+
+       call_data.trace = trace;
+       call_data.serializer = NULL;
+
+       marker_iter_reset(&iter);
+       marker_iter_start(&iter);
+       for (; iter.marker != NULL; marker_iter_next(&iter)) {
+               if (!_imv_read(iter.marker->state))
+                       continue;
+               channel = ltt_channels_get_name_from_index(
+                               iter.marker->channel_id);
+               __trace_mark(0, metadata, core_marker_id,
+                       &call_data,
+                       "channel %s name %s event_id %hu "
+                       "int #1u%zu long #1u%zu pointer #1u%zu "
+                       "size_t #1u%zu alignment #1u%u",
+                       channel,
+                       iter.marker->name,
+                       iter.marker->event_id,
+                       sizeof(int), sizeof(long),
+                       sizeof(void *), sizeof(size_t),
+                       ltt_get_alignment());
+               if (iter.marker->format)
+                       __trace_mark(0, metadata,
+                               core_marker_format,
+                               &call_data,
+                               "channel %s name %s format %s",
+                               channel,
+                               iter.marker->name,
+                               iter.marker->format);
+       }
+       marker_iter_stop(&iter);
+}
 //ust// EXPORT_SYMBOL_GPL(ltt_dump_marker_state);
+
+
+static LIST_HEAD(libs);
+
+/*
+ * Returns 0 if current not found.
+ * Returns 1 if current found.
+ */
+int lib_get_iter_markers(struct marker_iter *iter)
+{
+       struct lib *iter_lib;
+       int found = 0;
+
+//ust//        mutex_lock(&module_mutex);
+       list_for_each_entry(iter_lib, &libs, list) {
+               if (iter_lib < iter->lib)
+                       continue;
+               else if (iter_lib > iter->lib)
+                       iter->marker = NULL;
+               found = marker_get_iter_range(&iter->marker,
+                       iter_lib->markers_start,
+                       iter_lib->markers_start + iter_lib->markers_count);
+               if (found) {
+                       iter->lib = iter_lib;
+                       break;
+               }
+       }
+//ust//        mutex_unlock(&module_mutex);
+       return found;
+}
+
+void lib_update_markers(void)
+{
+       struct lib *lib;
+
+//ust//        mutex_lock(&module_mutex);
+       list_for_each_entry(lib, &libs, list)
+               marker_update_probe_range(lib->markers_start,
+                               lib->markers_start + lib->markers_count);
+//ust//        mutex_unlock(&module_mutex);
+}
+
+int marker_register_lib(struct marker *markers_start, int markers_count)
+{
+       struct lib *pl;
+
+       pl = (struct lib *) malloc(sizeof(struct lib));
+
+       pl->markers_start = markers_start;
+       pl->markers_count = markers_count;
+
+       list_add(&pl->list, &libs);
+
+       /* FIXME: update just the loaded lib */
+       lib_update_markers();
+
+       printf("just registered a markers section from %p and having %d markers\n", markers_start, markers_count);
+       
+       return 0;
+}
+
+static int initialized = 0;
+
+void __attribute__((constructor)) init_markers(void)
+{
+       if(!initialized) {
+               marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));
+               printf("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers);
+               initialized = 1;
+       }
+}
This page took 0.027538 seconds and 4 git commands to generate.