#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <syscall.h>
+#include <features.h>
+#include <pthread.h>
+#include <malloc.h>
+#include <string.h>
+#include <asm/atomic.h>
#include "lttng_usertrace.h"
+#define MAX_TRACES 16
+
+struct ltt_buf {
+ void *start;
+ atomic_t offset;
+ atomic_t reserve_count;
+ atomic_t commit_count;
+
+ atomic_t events_lost;
+};
+
+struct lttng_trace_info {
+ struct lttng_trace_info *next;
+ int active:1;
+ struct {
+ struct ltt_buf facilities;
+ struct ltt_buf cpu;
+ } channel;
+};
+
+
+/* TLS for the trace info */
+static __thread struct lttng_trace_info *test;
+static __thread struct lttng_trace_info lttng_trace_info[MAX_TRACES];
+
+
/* signal handler */
void __lttng_sig_trace_handler(int signo)
{
+ int ret;
+ sigset_t set, oldset;
+
printf("LTTng Sig handler : pid : %lu\n", getpid());
+
+ /* Disable signals */
+ ret = sigfillset(&set);
+ if(ret) {
+ printf("Error in sigfillset\n");
+ exit(1);
+ }
+
+ ret = sigprocmask(SIG_BLOCK, &set, &oldset);
+ if(ret) {
+ printf("Error in sigprocmask\n");
+ exit(1);
+ }
+
+ /* Get all the new traces */
+#if 0
+ do {
+ /* FIXME : allocate the trace structure somewhere : thread private */
+ ret = ltt_update(addr, &active, &filter);
+
+ if(ret) {
+ printf("Error in ltt_update system call\n");
+ exit(1);
+ }
+ } while(addr);
+
+#endif //0
+ /* Enable signals */
+ ret = sigprocmask(SIG_SETMASK, &oldset, NULL);
+ if(ret) {
+ printf("Error in sigprocmask\n");
+ exit(1);
+ }
+
}
+void __lttng_init_trace_info(void)
+{
+ memset(<tng_trace_info, 0, MAX_TRACES*sizeof(struct lttng_trace_info));
+}
void __attribute__((constructor)) __lttng_user_init(void)
{
printf("LTTng user init\n");
+ /* Init trace info */
+ __lttng_init_trace_info();
+
/* Activate the signal */
act.sa_handler = __lttng_sig_trace_handler;
err = sigemptyset(&(act.sa_mask));
err = sigaction(SIGRTMIN+3, &act, NULL);
if(err) perror("Error with sigaction");
+ /* TEST */
+ err = ltt_switch((unsigned long)NULL);
+ if(err) {
+ printf("Error in ltt_switch system call\n");
+ exit(1);
+ }
+
/* Make the first ltt_update system call */
err = ltt_update(1, NULL, NULL);
if(err) {
printf("Error in ltt_update system call\n");
exit(1);
}
+
+ /* Make some ltt_switch syscalls */
+ err = ltt_switch((unsigned long)NULL);
+ if(err) {
+ printf("Error in ltt_switch system call\n");
+ exit(1);
+ }
+
+
+
}
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
#include "lttng_usertrace.h"
+
+
+void *thr1(void *arg)
+{
+ printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+
+ while(1) {}
+
+ return ((void*)1);
+
+}
+
+void *thr2(void *arg)
+{
+ while(1) {
+ printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
+ sleep(2);
+ }
+ return ((void*)2);
+}
+
+
int main()
{
+ int err;
+ pthread_t tid1, tid2;
+ void *tret;
+
+ err = pthread_create(&tid1, NULL, thr1, NULL);
+ if(err!=0) exit(1);
+
+ err = pthread_create(&tid2, NULL, thr2, NULL);
+ if(err!=0) exit(1);
while(1)
{
}
+
+ err = pthread_join(tid1, &tret);
+ if(err!= 0) exit(1);
+
+ err = pthread_join(tid2, &tret);
+ if(err!= 0) exit(1);
return 0;
}