67b9ef3a9f56f1455e2f43026d46e816d34ed792
9 #include "../libmarkers/marker.h"
12 #include "marker-control.h"
16 char consumer_stack
[10000];
18 #define CPRINTF(fmt, args...) safe_printf(fmt "\n", ## args)
20 int safe_printf(const char *fmt
, ...)
28 n
= vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
30 write(STDOUT_FILENO
, buf
, n
);
35 struct consumer_channel
{
37 struct ltt_channel_struct
*chan
;
40 int consumer(void *arg
)
44 char str
[] = "Hello, this is the consumer.\n";
45 struct ltt_trace_struct
*trace
;
46 struct consumer_channel
*consumer_channels
;
48 char trace_name
[] = "auto";
51 trace
= _ltt_trace_find(trace_name
);
55 CPRINTF("cannot find trace!");
59 consumer_channels
= (struct consumer_channel
*) malloc(trace
->nr_channels
* sizeof(struct consumer_channel
));
60 if(consumer_channels
== NULL
) {
61 ERR("malloc returned NULL");
65 CPRINTF("opening trace files");
66 for(i
=0; i
<trace
->nr_channels
; i
++) {
68 struct ltt_channel_struct
*chan
= &trace
->channels
[i
];
70 consumer_channels
[i
].chan
= chan
;
72 snprintf(tmp
, sizeof(tmp
), "trace/%s", chan
->channel_name
);
73 result
= consumer_channels
[i
].fd
= open(tmp
, O_WRONLY
| O_CREAT
| O_TRUNC
, 00644);
78 CPRINTF("\topened trace file %s", tmp
);
81 CPRINTF("done opening trace files");
86 for(i
=0; i
<trace
->nr_channels
; i
++) {
87 struct rchan
*rchan
= consumer_channels
[i
].chan
->trans_channel_data
;
88 struct rchan_buf
*rbuf
= rchan
->buf
;
89 struct ltt_channel_buf_struct
*lttbuf
= consumer_channels
[i
].chan
->buf
;
92 result
= ltt_do_get_subbuf(rbuf
, lttbuf
, &consumed_old
);
94 CPRINTF("ltt_do_get_subbuf: error: %s", strerror(-result
));
99 result
= write(consumer_channels
[i
].fd
, rbuf
->buf_data
+ (consumed_old
& (2 * 4096-1)), 4096);
100 ltt_do_put_subbuf(rbuf
, lttbuf
, consumed_old
);
107 // CPRINTF("consumer: got a trace: %s with %d channels\n", trace_name, trace->nr_channels);
109 // struct ltt_channel_struct *chan = &trace->channels[0];
111 // CPRINTF("channel 1 (%s) active=%u", chan->channel_name, chan->active & 1);
113 // struct rchan *rchan = chan->trans_channel_data;
114 // struct rchan_buf *rbuf = rchan->buf;
115 // struct ltt_channel_buf_struct *lttbuf = chan->buf;
116 // long consumed_old;
118 // result = fd = open("trace.out", O_WRONLY | O_CREAT | O_TRUNC, 00644);
119 // if(result == -1) {
125 // write(STDOUT_FILENO, str, sizeof(str));
127 // result = ltt_do_get_subbuf(rbuf, lttbuf, &consumed_old);
129 // CPRINTF("ltt_do_get_subbuf: error: %s", strerror(-result));
132 // CPRINTF("success!");
134 // result = write(fd, rbuf->buf_data + (consumed_old & (2 * 4096-1)), 4096);
135 // ltt_do_put_subbuf(rbuf, lttbuf, consumed_old);
138 // //CPRINTF("There seems to be %ld bytes available", SUBBUF_TRUNC(local_read(<tbuf->offset), rbuf->chan) - consumed_old);
139 // CPRINTF("Commit count %ld", local_read(<tbuf->commit_count[0]));
146 void start_consumer(void)
150 result
= clone(consumer
, consumer_stack
+sizeof(consumer_stack
)-1, CLONE_FS
| CLONE_FILES
| CLONE_VM
| CLONE_SIGHAND
| CLONE_THREAD
, NULL
);
156 void probe(const struct marker
*mdata
,
157 void *probe_private
, void *call_private
,
158 const char *fmt
, va_list *args
)
160 printf("In probe\n");
163 void inthandler(int sig
)
165 printf("in handler\n");
169 int init_int_handler(void)
172 struct sigaction act
;
174 result
= sigemptyset(&act
.sa_mask
);
176 PERROR("sigemptyset");
180 act
.sa_handler
= inthandler
;
181 act
.sa_flags
= SA_RESTART
;
183 /* Only defer ourselves. Also, try to restart interrupted
184 * syscalls to disturb the traced program as little as possible.
186 result
= sigaction(SIGINT
, &act
, NULL
);
203 printf("Hello, World!\n");
206 for(i
=0; i
<50; i
++) {
207 trace_mark(ust
, bar
, "str %s", "FOOBAZ");
208 trace_mark(ust
, bar2
, "number1 %d number2 %d", 53, 9800);
This page took 0.072062 seconds and 3 git commands to generate.