9 #include "../libmarkers/marker.h"
12 #include "marker-control.h"
16 char consumer_stack
[10000];
17 char trace_name
[] = "theusttrace";
18 char trace_type
[] = "ustrelay";
20 #define CPRINTF(fmt, args...) safe_printf(fmt "\n", ## args)
22 int safe_printf(const char *fmt
, ...)
30 n
= vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
32 write(STDOUT_FILENO
, buf
, n
);
37 struct consumer_channel
{
39 struct ltt_channel_struct
*chan
;
42 int consumer(void *arg
)
46 char str
[] = "Hello, this is the consumer.\n";
47 struct ltt_trace_struct
*trace
;
48 struct consumer_channel
*consumer_channels
;
52 trace
= _ltt_trace_find(trace_name
);
56 CPRINTF("cannot find trace!");
60 consumer_channels
= (struct consumer_channel
*) malloc(trace
->nr_channels
* sizeof(struct consumer_channel
));
61 if(consumer_channels
== NULL
) {
62 ERR("malloc returned NULL");
66 CPRINTF("opening trace files");
67 for(i
=0; i
<trace
->nr_channels
; i
++) {
69 struct ltt_channel_struct
*chan
= &trace
->channels
[i
];
71 consumer_channels
[i
].chan
= chan
;
73 snprintf(tmp
, sizeof(tmp
), "trace/%s", chan
->channel_name
);
74 result
= consumer_channels
[i
].fd
= open(tmp
, O_WRONLY
| O_CREAT
| O_TRUNC
, 00644);
79 CPRINTF("\topened trace file %s", tmp
);
82 CPRINTF("done opening trace files");
87 for(i
=0; i
<trace
->nr_channels
; i
++) {
88 struct rchan
*rchan
= consumer_channels
[i
].chan
->trans_channel_data
;
89 struct rchan_buf
*rbuf
= rchan
->buf
;
90 struct ltt_channel_buf_struct
*lttbuf
= consumer_channels
[i
].chan
->buf
;
93 result
= ltt_do_get_subbuf(rbuf
, lttbuf
, &consumed_old
);
95 CPRINTF("ltt_do_get_subbuf: error: %s", strerror(-result
));
100 result
= write(consumer_channels
[i
].fd
, rbuf
->buf_data
+ (consumed_old
& (2 * 4096-1)), 4096);
101 ltt_do_put_subbuf(rbuf
, lttbuf
, consumed_old
);
108 // CPRINTF("consumer: got a trace: %s with %d channels\n", trace_name, trace->nr_channels);
110 // struct ltt_channel_struct *chan = &trace->channels[0];
112 // CPRINTF("channel 1 (%s) active=%u", chan->channel_name, chan->active & 1);
114 // struct rchan *rchan = chan->trans_channel_data;
115 // struct rchan_buf *rbuf = rchan->buf;
116 // struct ltt_channel_buf_struct *lttbuf = chan->buf;
117 // long consumed_old;
119 // result = fd = open("trace.out", O_WRONLY | O_CREAT | O_TRUNC, 00644);
120 // if(result == -1) {
126 // write(STDOUT_FILENO, str, sizeof(str));
128 // result = ltt_do_get_subbuf(rbuf, lttbuf, &consumed_old);
130 // CPRINTF("ltt_do_get_subbuf: error: %s", strerror(-result));
133 // CPRINTF("success!");
135 // result = write(fd, rbuf->buf_data + (consumed_old & (2 * 4096-1)), 4096);
136 // ltt_do_put_subbuf(rbuf, lttbuf, consumed_old);
139 // //CPRINTF("There seems to be %ld bytes available", SUBBUF_TRUNC(local_read(<tbuf->offset), rbuf->chan) - consumed_old);
140 // CPRINTF("Commit count %ld", local_read(<tbuf->commit_count[0]));
147 void start_consumer(void)
151 result
= clone(consumer
, consumer_stack
+sizeof(consumer_stack
)-1, CLONE_FS
| CLONE_FILES
| CLONE_VM
, NULL
);
157 void probe(const struct marker
*mdata
,
158 void *probe_private
, void *call_private
,
159 const char *fmt
, va_list *args
)
161 printf("In probe\n");
164 void inthandler(int sig
)
166 printf("in handler\n");
170 int init_int_handler(void)
173 struct sigaction act
;
175 result
= sigemptyset(&act
.sa_mask
);
177 PERROR("sigemptyset");
181 act
.sa_handler
= inthandler
;
182 act
.sa_flags
= SA_RESTART
;
184 /* Only defer ourselves. Also, try to restart interrupted
185 * syscalls to disturb the traced program as little as possible.
187 result
= sigaction(SIGINT
, &act
, NULL
);
203 init_ustrelay_transport();
205 printf("page size is %d\n", sysconf(_SC_PAGE_SIZE
));
207 marker_control_init();
209 //marker_probe_register("abc", "testmark", "", probe, NULL);
210 //ust// marker_probe_register("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", probe, NULL);
211 //ust// result = ltt_probe_register(&default_probe);
213 //ust// ERR("ltt_probe_register");
215 //result = ltt_marker_connect("metadata", "testev", "default");
217 // ERR("ltt_marker_connect");
218 result
= ltt_marker_connect("foo", "bar", "default");
220 ERR("ltt_marker_connect");
222 result
= ltt_trace_setup(trace_name
);
224 ERR("ltt_trace_setup failed");
228 result
= ltt_trace_set_type(trace_name
, trace_type
);
230 ERR("ltt_trace_set_type failed");
234 result
= ltt_trace_alloc(trace_name
);
236 ERR("ltt_trace_alloc failed");
240 result
= ltt_trace_start(trace_name
);
242 ERR("ltt_trace_start failed");
247 printf("Hello, World!\n");
250 for(i
=0; i
<50; i
++) {
251 //trace_mark(abc, testmark, "", MARK_NOARGS);
252 //trace_mark(metadata, testev, "", MARK_NOARGS);
253 trace_mark(foo
, bar
, "%s", "FOOBAZ");
254 //trace_mark(metadata, core_marker_id,
255 // "channel %s name %s event_id %hu "
256 // "int #1u%zu long #1u%zu pointer #1u%zu "
257 // "size_t #1u%zu alignment #1u%u",
258 // "abc", "def", (unsigned short)1000,
259 // sizeof(int), sizeof(long), sizeof(void *),
260 // sizeof(size_t), ltt_get_alignment());
264 ltt_trace_stop(trace_name
);
265 ltt_trace_destroy(trace_name
);
This page took 0.054559 seconds and 4 git commands to generate.