add func instrumentation
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Mon, 6 Mar 2006 23:44:42 +0000 (23:44 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Mon, 6 Mar 2006 23:44:42 +0000 (23:44 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@1590 04897980-b3bd-0310-b5e0-8ef037075253

usertrace-generic/Makefile
usertrace-generic/README
usertrace-generic/ltt-facility-loader-user_generic.h
usertrace-generic/ltt-instrument-functions.c [new file with mode: 0644]
usertrace-generic/ltt/ltt-facility-id-user_generic.h
usertrace-generic/ltt/ltt-facility-user_generic.h
usertrace-generic/ltt/ltt-generic.h
usertrace-generic/sample-instrument-fct.c [new file with mode: 0644]
usertrace-generic/user_generic.xml

index f3e52e1aeb85ce0cd3da6436f3253dd931b20530..e4cab2f648ebe19c25714e6a2c1dab951f62a603 100644 (file)
@@ -2,7 +2,7 @@
 CC=gcc
 INCLUDE_DIR=/usr/include
 
-all: sample-thread sample sample-highspeed sample-printf
+all: sample-thread sample sample-highspeed sample-printf sample-instrument-fct
 
 sample-thread: sample-thread.c ltt-facility-loader-user_generic.c
        $(CC) $(CFLAGS) -lpthread -o $@ $^
@@ -16,6 +16,10 @@ sample-highspeed: sample-highspeed.c ltt-facility-loader-user_generic.c
 sample-printf: sample-printf.c ltt-facility-loader-user_generic.c
        $(CC) $(CFLAGS) -o $@ $^
 
+sample-instrument-fct: sample-instrument-fct.c ltt-facility-loader-user_generic.c ltt-instrument-functions.c
+       $(CC) $(CFLAGS) -g -finstrument-functions -o $@ $^
+       
+
 .PHONY : clean install
 
 install:
@@ -23,5 +27,5 @@ install:
        cp -f ltt/*.h $(INCLUDE_DIR)/ltt
 
 clean:
-       rm -fr *.o *~ sample-thread sample sample-highspeed sample-printf
+       rm -fr *.o *~ sample-thread sample sample-highspeed sample-printf sample-instrument-fct
 
index b8c23018bc2f66fed0d23b0ae5ae52cf1aa33fce..9d471ebe6de7c5ef5687ff478d92177010ef4037 100644 (file)
@@ -161,4 +161,36 @@ It will show, for example :
 user_myfacility.myevent: 39507.805584526 (/cpu_1), 15829, 15736,  SYSCALL { "myapp.c", "main", 8, 1234, 0xf0f0f0f0 }
 
 
+* Fun feature : function instrumentation
+
+Here is how to generate a full trace of you program function calls.
+See the sample-instrument-fct.c example program.
+
+- Compile your application with at least these parameters to gcc (it is splitted
+  on two lines, joined by a "\") :
+gcc -g -I /usr/src/usertrace-generic -o myapp myapp.c \
+  /usr/src/usertrace-generic/ltt-facility-loader-user_myfacility.c \
+       /usr/src/usertrace-generic/ltt-instrument-functions.c
+
+To see what the final result looks like :
+- Start tracing
+- Start your application
+- Stop tracing
+Then, to see only the function_entry and function_exit events :
+lttv -m textDump -t /tmp/trace1 -e "event.facility=user_generic & (event.name=function_entry & event.name=function_exit)"
+
+It will show, for example :
+user_generic.function_entry: 59329.709939111 (/cpu_0), 19250, 18581,  SYSCALL { 
+0x8048454, 0x80484c2 }
+user_generic.function_exit: 59329.709944613 (/cpu_0), 19250, 18581,  SYSCALL { 0
+x8048454, 0x80484c2 }
+
+you can then use (from the binutils package)
+addr2line -e sample-instrument-fct -i -f 0x8048454
+Which shows :
+test_function
+/usr/src/usertrace-generic/sample-instrument-fct.c:12
+
+The lookup in LTTV through libbfd has not been implemented yet.
+
 
index 9c6b6fc5f557e3bd573dac0a216c71e2fa26dfa9..1f93d1e3caea1748be89f8671d509ebf1ce6123b 100644 (file)
@@ -5,11 +5,11 @@
 #include <ltt/ltt-facility-id-user_generic.h>
 
 ltt_facility_t ltt_facility_user_generic;
-ltt_facility_t ltt_facility_user_generic_FB850A80;
+ltt_facility_t ltt_facility_user_generic_F583779E;
 
 #define LTT_FACILITY_SYMBOL                                                    ltt_facility_user_generic
-#define LTT_FACILITY_CHECKSUM_SYMBOL           ltt_facility_user_generic_FB850A80
-#define LTT_FACILITY_CHECKSUM                                          0xFB850A80
+#define LTT_FACILITY_CHECKSUM_SYMBOL           ltt_facility_user_generic_F583779E
+#define LTT_FACILITY_CHECKSUM                                          0xF583779E
 #define LTT_FACILITY_NAME                                                              "user_generic"
 #define LTT_FACILITY_NUM_EVENTS                                        facility_user_generic_num_events
 
diff --git a/usertrace-generic/ltt-instrument-functions.c b/usertrace-generic/ltt-instrument-functions.c
new file mode 100644 (file)
index 0000000..5d1b276
--- /dev/null
@@ -0,0 +1,28 @@
+/****************************************************************************
+ * ltt-instrument-functions.c
+ *
+ * Mathieu Desnoyers
+ * March 2006
+ */
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+
+
+void __attribute__((no_instrument_function)) __cyg_profile_func_enter (
+               void *this_fn,
+               void *call_site)
+{
+       /* don't care about the return value */
+       trace_user_generic_function_entry(this_fn, call_site);
+}
+
+void __attribute__((no_instrument_function)) __cyg_profile_func_exit (
+               void *this_fn,
+               void *call_site)
+{
+       /* don't care about the return value */
+       trace_user_generic_function_exit(this_fn, call_site);
+}
+
index 4b42a0e54fe6d3d6d73509e108337ac87f29805a..87205eb3612cd2cd640fb60be40e83b844e4d9ef 100644 (file)
@@ -6,7 +6,7 @@
 
 /****  facility handle  ****/
 
-extern ltt_facility_t ltt_facility_user_generic_FB850A80;
+extern ltt_facility_t ltt_facility_user_generic_F583779E;
 extern ltt_facility_t ltt_facility_user_generic;
 
 
@@ -16,6 +16,8 @@ enum user_generic_event {
        event_user_generic_string,
        event_user_generic_string_pointer,
        event_user_generic_slow_printf,
+       event_user_generic_function_entry,
+       event_user_generic_function_exit,
        facility_user_generic_num_events
 };
 
index b793559ace18247b4332bf902bb93ffb82b4bd66..ca890b66f10cbb512a04e32a091167e79cb36e52 100644 (file)
@@ -97,7 +97,7 @@ static inline int trace_user_generic_string(
                        *len = 0;
                }
 
-               ret = ltt_trace_generic(ltt_facility_user_generic_FB850A80, event_user_generic_string, buffer, reserve_size, LTT_BLOCKING);
+               ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_string, buffer, reserve_size, LTT_BLOCKING);
        }
 
        return ret;
@@ -226,7 +226,7 @@ static inline int trace_user_generic_string_pointer(
                        *len = 0;
                }
 
-               ret = ltt_trace_generic(ltt_facility_user_generic_FB850A80, event_user_generic_string_pointer, buffer, reserve_size, LTT_BLOCKING);
+               ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_string_pointer, buffer, reserve_size, LTT_BLOCKING);
        }
 
        return ret;
@@ -289,9 +289,213 @@ static inline int trace_user_generic_slow_printf_param_buffer(
 #else
 {
        int ret = 0;
-       reserve_size += ltt_align(reserve_size, sizeof(void *));
+       reserve_size = ltt_align(reserve_size, sizeof(void *));
        {
-               ret = ltt_trace_generic(ltt_facility_user_generic_FB850A80, event_user_generic_slow_printf, buffer, reserve_size, LTT_BLOCKING);
+               ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_slow_printf, buffer, reserve_size, LTT_BLOCKING);
+       }
+
+       return ret;
+
+}
+#endif //LTT_TRACE
+
+/* Event function_entry structures */
+
+/* Event function_entry logging function */
+static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
+               const void * lttng_param_this_fn,
+               const void * lttng_param_call_site)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+       int ret = 0;
+       void *buffer = NULL;
+       size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+       size_t *to_base = &real_to_base;
+       size_t real_to = 0;
+       size_t *to = &real_to;
+       size_t real_len = 0;
+       size_t *len = &real_len;
+       size_t reserve_size;
+       size_t slot_size;
+       size_t align;
+       const void *real_from;
+       const void **from = &real_from;
+               /* For each field, calculate the field size. */
+       /* size = *to_base + *to + *len */
+       /* Assume that the padding for alignment starts at a
+        * sizeof(void *) address. */
+
+       *from = &lttng_param_this_fn;
+       align = sizeof(const void *);
+
+       if(*len == 0) {
+               *to += ltt_align(*to, align); /* align output */
+       } else {
+               *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+       }
+
+       *len += sizeof(const void *);
+
+       *from = &lttng_param_call_site;
+       align = sizeof(const void *);
+
+       if(*len == 0) {
+               *to += ltt_align(*to, align); /* align output */
+       } else {
+               *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+       }
+
+       *len += sizeof(const void *);
+
+       reserve_size = *to_base + *to + *len;
+       {
+               char stack_buffer[reserve_size];
+               buffer = stack_buffer;
+
+               *to_base = *to = *len = 0;
+
+               *from = &lttng_param_this_fn;
+               align = sizeof(const void *);
+
+               if(*len == 0) {
+                       *to += ltt_align(*to, align); /* align output */
+               } else {
+                       *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+               }
+
+               *len += sizeof(const void *);
+
+               /* Flush pending memcpy */
+               if(*len != 0) {
+                       memcpy(buffer+*to_base+*to, *from, *len);
+                       *to += *len;
+                       *len = 0;
+               }
+
+               *from = &lttng_param_call_site;
+               align = sizeof(const void *);
+
+               if(*len == 0) {
+                       *to += ltt_align(*to, align); /* align output */
+               } else {
+                       *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+               }
+
+               *len += sizeof(const void *);
+
+               /* Flush pending memcpy */
+               if(*len != 0) {
+                       memcpy(buffer+*to_base+*to, *from, *len);
+                       *to += *len;
+                       *len = 0;
+               }
+
+               ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_function_entry, buffer, reserve_size, LTT_BLOCKING);
+       }
+
+       return ret;
+
+}
+#endif //LTT_TRACE
+
+/* Event function_exit structures */
+
+/* Event function_exit logging function */
+static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
+               const void * lttng_param_this_fn,
+               const void * lttng_param_call_site)
+#ifndef LTT_TRACE
+{
+}
+#else
+{
+       int ret = 0;
+       void *buffer = NULL;
+       size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
+       size_t *to_base = &real_to_base;
+       size_t real_to = 0;
+       size_t *to = &real_to;
+       size_t real_len = 0;
+       size_t *len = &real_len;
+       size_t reserve_size;
+       size_t slot_size;
+       size_t align;
+       const void *real_from;
+       const void **from = &real_from;
+               /* For each field, calculate the field size. */
+       /* size = *to_base + *to + *len */
+       /* Assume that the padding for alignment starts at a
+        * sizeof(void *) address. */
+
+       *from = &lttng_param_this_fn;
+       align = sizeof(const void *);
+
+       if(*len == 0) {
+               *to += ltt_align(*to, align); /* align output */
+       } else {
+               *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+       }
+
+       *len += sizeof(const void *);
+
+       *from = &lttng_param_call_site;
+       align = sizeof(const void *);
+
+       if(*len == 0) {
+               *to += ltt_align(*to, align); /* align output */
+       } else {
+               *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+       }
+
+       *len += sizeof(const void *);
+
+       reserve_size = *to_base + *to + *len;
+       {
+               char stack_buffer[reserve_size];
+               buffer = stack_buffer;
+
+               *to_base = *to = *len = 0;
+
+               *from = &lttng_param_this_fn;
+               align = sizeof(const void *);
+
+               if(*len == 0) {
+                       *to += ltt_align(*to, align); /* align output */
+               } else {
+                       *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+               }
+
+               *len += sizeof(const void *);
+
+               /* Flush pending memcpy */
+               if(*len != 0) {
+                       memcpy(buffer+*to_base+*to, *from, *len);
+                       *to += *len;
+                       *len = 0;
+               }
+
+               *from = &lttng_param_call_site;
+               align = sizeof(const void *);
+
+               if(*len == 0) {
+                       *to += ltt_align(*to, align); /* align output */
+               } else {
+                       *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
+               }
+
+               *len += sizeof(const void *);
+
+               /* Flush pending memcpy */
+               if(*len != 0) {
+                       memcpy(buffer+*to_base+*to, *from, *len);
+                       *to += *len;
+                       *len = 0;
+               }
+
+               ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_function_exit, buffer, reserve_size, LTT_BLOCKING);
        }
 
        return ret;
index efa338c3ce8f7c702df02910445a8377f4fcde94..5f5010c671bb2a54d1b47e083de1bb47d5228fbb 100644 (file)
@@ -57,22 +57,27 @@ struct user_facility_info {
   size_t size_t_size;
 };
 
-static inline _syscall5(int, ltt_trace_generic, unsigned int, facility_id,
-               unsigned int, event_id, void *, data, size_t, data_size, int, blocking)
-static inline _syscall2(int, ltt_register_generic, unsigned int *, facility_id, const struct user_facility_info *, info)
+static inline __attribute__((no_instrument_function)) 
+_syscall5(int, ltt_trace_generic, unsigned int, facility_id,
+       unsigned int, event_id, void *, data, size_t, data_size, int, blocking)
+static inline __attribute__((no_instrument_function))
+_syscall2(int, ltt_register_generic, unsigned int *, facility_id,
+       const struct user_facility_info *, info)
 
 #ifndef LTT_PACK
 /* Calculate the offset needed to align the type */
-static inline unsigned int ltt_align(size_t align_drift,
-                                     size_t size_of_type)
+static inline unsigned int __attribute__((no_instrument_function))
+                                                                                                               ltt_align(size_t align_drift,
+                                      size_t size_of_type)
 {
   size_t alignment = min(sizeof(void*), size_of_type);
 
   return ((alignment - align_drift) & (alignment-1));
 }
 #else
-static inline unsigned int ltt_align(size_t align_drift,
-                                     size_t size_of_type)
+static inline unsigned int __attribute__((no_instrument_function))
+                                                                                                               ltt_align(size_t align_drift,
+                                      size_t size_of_type)
 {
   return 0;
 }
diff --git a/usertrace-generic/sample-instrument-fct.c b/usertrace-generic/sample-instrument-fct.c
new file mode 100644 (file)
index 0000000..37140da
--- /dev/null
@@ -0,0 +1,26 @@
+
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+
+
+void test_function(void)
+{
+       printf("we are in a test function\n");
+}
+
+
+int main(int argc, char **argv)
+{
+       while(1) {
+               test_function();
+               sleep(1);
+       }
+       
+       return 0;
+}
+
index a700028541dccaa6c62ce8fe83eb313dc11b3137..6e555bbcde7624f81deefe7b46cf8d8efca5aaa5 100644 (file)
                <field name="string"><string/></field>
   </event>
        
+       <event name=function_entry no_instrument_function>
+               <description>Entry in a function</description>
+               <field name="this_fn"><pointer/></field>
+               <field name="call_site"><pointer/></field>
+       </event>
+
+       <event name=function_exit no_instrument_function>
+               <description>Exit from a function</description>
+               <field name="this_fn"><pointer/></field>
+               <field name="call_site"><pointer/></field>
+       </event>
+
 </facility>
This page took 0.029981 seconds and 4 git commands to generate.