From 8b30e7bcf2fe4ab9afecf8012c180aa7d4424a34 Mon Sep 17 00:00:00 2001 From: compudj Date: Wed, 8 Mar 2006 18:29:31 +0000 Subject: [PATCH] work in prog git-svn-id: http://ltt.polymtl.ca/svn@1619 04897980-b3bd-0310-b5e0-8ef037075253 --- usertrace-fast/Makefile | 26 +++++++++- .../ltt-facility-loader-user_generic.c | 49 +++++++++++++++++++ .../ltt-facility-loader-user_generic.h | 16 ++++++ usertrace-fast/ltt-instrument-functions.c | 28 +++++++++++ usertrace-fast/ltt-usertrace-fast.c | 4 ++ usertrace-fast/ltt-usertrace-fast.h | 41 +++------------- usertrace-fast/sample-instrument-fct.c | 26 ++++++++++ 7 files changed, 154 insertions(+), 36 deletions(-) create mode 100644 usertrace-fast/ltt-facility-loader-user_generic.c create mode 100644 usertrace-fast/ltt-facility-loader-user_generic.h create mode 100644 usertrace-fast/ltt-instrument-functions.c create mode 100644 usertrace-fast/sample-instrument-fct.c diff --git a/usertrace-fast/Makefile b/usertrace-fast/Makefile index 6cfaec6a..ced8f6fb 100644 --- a/usertrace-fast/Makefile +++ b/usertrace-fast/Makefile @@ -1,11 +1,33 @@ +RANLIB=ranlib CC=gcc +all: test sample-instrument-fct libltt-instrument-functions.a libltt-instrument-functions.so.0 + test: test.c ltt-usertrace-fast.c $(CC) $(CFLAGS) -lpthread -o $@ $^ -.PHONY : clean + +sample-instrument-fct: sample-instrument-fct.c + $(CC) $(CFLAGS) -L. -g -finstrument-functions -lltt-instrument-functions -o $@ $^ + +libltt-instrument-functions.a: ltt-instrument-functions.o ltt-facility-loader-user_generic.o + @rm -f libltt-instrument-functions.a + $(AR) rc $@ $^ + $(RANLIB) $@ + +libltt-instrument-functions.so.0: ltt-instrument-functions.o ltt-facility-loader-user_generic.o + @rm -f libltt-instrument-functions.so libltt-instrument-functions.so.0 + $(CC) $(CFLAGS) -shared -Wl,-soname,libltt-instrument-functions.so -o $@ $^ + ln -s libltt-instrument-functions.so.0 libltt-instrument-functions.so + +install: + if [ ! -e "$(INCLUDE_DIR)/ltt" ] ; then mkdir $(INCLUDE_DIR)/ltt ; fi + cp -f ltt/*.h $(INCLUDE_DIR)/ltt + cp -df libltt-instrument-functions.so* libltt-instrument-functions.a $(LIB_DIR) + +.PHONY : clean install clean: - rm -fr *.o *~ test + rm -fr *.o *~ test sample-instrument-fct libltt-instrument-functions.a libltt-instrument-functions.so* diff --git a/usertrace-fast/ltt-facility-loader-user_generic.c b/usertrace-fast/ltt-facility-loader-user_generic.c new file mode 100644 index 00000000..8cdb0760 --- /dev/null +++ b/usertrace-fast/ltt-facility-loader-user_generic.c @@ -0,0 +1,49 @@ +/* + * ltt-facility-loader-user_generic.c + * + * (C) Copyright 2005 - + * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca) + * + * Contains the LTT user space facility loader. + * + */ + + +#define LTT_TRACE +#include +#include +#include +#include "ltt-facility-loader-user_generic.h" + +static struct user_facility_info facility = { + .name = LTT_FACILITY_NAME, + .num_events = LTT_FACILITY_NUM_EVENTS, +#ifndef LTT_PACK + .alignment = sizeof(void*), +#else + .alignment = 0, +#endif //LTT_PACK + .checksum = LTT_FACILITY_CHECKSUM, + .int_size = sizeof(int), + .long_size = sizeof(long), + .pointer_size = sizeof(void*), + .size_t_size = sizeof(size_t) +}; + +static void __attribute__((constructor)) __ltt_user_init(void) +{ + int err; +#ifdef LTT_SHOW_DEBUG + printf("LTT : ltt-facility-user_generic init in userspace\n"); +#endif //LTT_SHOW_DEBUG + + err = ltt_register_generic(<T_FACILITY_SYMBOL, &facility); + LTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL; + + if(err) { +#ifdef LTT_SHOW_DEBUG + perror("Error in ltt_register_generic"); +#endif //LTT_SHOW_DEBUG + } +} + diff --git a/usertrace-fast/ltt-facility-loader-user_generic.h b/usertrace-fast/ltt-facility-loader-user_generic.h new file mode 100644 index 00000000..1f93d1e3 --- /dev/null +++ b/usertrace-fast/ltt-facility-loader-user_generic.h @@ -0,0 +1,16 @@ +#ifndef _LTT_FACILITY_LOADER_USER_GENERIC_H_ +#define _LTT_FACILITY_LOADER_USER_GENERIC_H_ + +#include +#include + +ltt_facility_t ltt_facility_user_generic; +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_F583779E +#define LTT_FACILITY_CHECKSUM 0xF583779E +#define LTT_FACILITY_NAME "user_generic" +#define LTT_FACILITY_NUM_EVENTS facility_user_generic_num_events + +#endif //_LTT_FACILITY_LOADER_USER_GENERIC_H_ diff --git a/usertrace-fast/ltt-instrument-functions.c b/usertrace-fast/ltt-instrument-functions.c new file mode 100644 index 00000000..28c7c8e1 --- /dev/null +++ b/usertrace-fast/ltt-instrument-functions.c @@ -0,0 +1,28 @@ +/**************************************************************************** + * ltt-instrument-functions.c + * + * Mathieu Desnoyers + * March 2006 + */ + +#define LTT_TRACE +#define LTT_TRACE_FAST +#include "ltt-usertrace-fast.h" +#include + +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); +} + diff --git a/usertrace-fast/ltt-usertrace-fast.c b/usertrace-fast/ltt-usertrace-fast.c index b56e3b52..55ba880a 100644 --- a/usertrace-fast/ltt-usertrace-fast.c +++ b/usertrace-fast/ltt-usertrace-fast.c @@ -42,6 +42,7 @@ */ #define _GNU_SOURCE +#define LTT_TRACE #include #include #include @@ -60,10 +61,13 @@ #include #include #include +#include #include #include //for get_cycles() +_syscall0(pid_t,gettid) + #include "ltt-usertrace-fast.h" enum force_switch_mode { FORCE_ACTIVE, FORCE_FLUSH }; diff --git a/usertrace-fast/ltt-usertrace-fast.h b/usertrace-fast/ltt-usertrace-fast.h index 5f791530..e4930d73 100644 --- a/usertrace-fast/ltt-usertrace-fast.h +++ b/usertrace-fast/ltt-usertrace-fast.h @@ -8,6 +8,8 @@ #ifndef _LTT_USERTRACE_FAST_H #define _LTT_USERTRACE_FAST_H +#ifdef LTT_TRACE + #include #include #include @@ -15,6 +17,9 @@ #include #include +#include +#include + #ifndef futex static inline __attribute__((no_instrument_function)) _syscall6(long, futex, unsigned long, uaddr, int, op, int, val, @@ -121,7 +126,7 @@ struct ltt_trace_info { int init; int filter; pid_t daemon_id; - atomic_t nesting; + int nesting; struct { struct ltt_buf facilities; struct ltt_buf cpu; @@ -145,27 +150,6 @@ void ltt_thread_init(void); void __attribute__((no_instrument_function)) ltt_usertrace_fast_buffer_switch(void); -#ifndef LTT_PACK -/* Calculate the offset needed to align the 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)); -} -#define LTT_ALIGN -#else -static inline unsigned int __attribute__((no_instrument_function)) - ltt_align(size_t align_drift, - size_t size_of_type) -{ - return 0; -} -#define LTT_ALIGN __attribute__((packed)) -#endif //LTT_PACK - /* Get the offset of the channel in the ltt_trace_struct */ #define GET_CHANNEL_INDEX(chan) \ (unsigned int)&((struct ltt_trace_info*)NULL)->channel.chan @@ -186,17 +170,6 @@ static inline unsigned int __attribute__((no_instrument_function)) ltt_get_index_from_facility(ltt_facility_t fID, uint8_t eID) { - - if(fID == ltt_facility_core) { - switch(eID) { - case event_core_facility_load: - case event_core_facility_unload: - case event_core_state_dump_facility_load: - return GET_CHANNEL_INDEX(facilities); - default: - return GET_CHANNEL_INDEX(cpu); - } - } return GET_CHANNEL_INDEX(cpu); } @@ -658,7 +631,7 @@ static inline void __attribute__((no_instrument_function)) ltt_commit_slot( } - +#endif //LTT_TRACE #endif //_LTT_USERTRACE_FAST_H diff --git a/usertrace-fast/sample-instrument-fct.c b/usertrace-fast/sample-instrument-fct.c new file mode 100644 index 00000000..37140da8 --- /dev/null +++ b/usertrace-fast/sample-instrument-fct.c @@ -0,0 +1,26 @@ + + +#include +#include + +#define LTT_TRACE +#define LTT_BLOCKING 1 +#include + + +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; +} + -- 2.34.1