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 int consumer(void *arg
)
43 char str
[] = "Hello, this is the consumer.\n";
45 struct ltt_trace_struct
*trace
;
48 trace
= _ltt_trace_find(trace_name
);
52 CPRINTF("cannot find trace!");
56 CPRINTF("consumer: got a trace: %s with %d channels\n", trace_name
, trace
->nr_channels
);
58 struct ltt_channel_struct
*chan
= &trace
->channels
[0];
60 CPRINTF("channel 1 (%s) active=%u", chan
->channel_name
, chan
->active
& 1);
62 struct rchan
*rchan
= chan
->trans_channel_data
;
63 struct rchan_buf
*rbuf
= rchan
->buf
;
64 struct ltt_channel_buf_struct
*lttbuf
= chan
->buf
;
67 result
= fd
= open("trace.out", O_WRONLY
| O_CREAT
| O_TRUNC
, 00644);
74 write(STDOUT_FILENO
, str
, sizeof(str
));
76 result
= ltt_do_get_subbuf(rbuf
, lttbuf
, &consumed_old
);
78 CPRINTF("ltt_do_get_subbuf: error: %s", strerror(-result
));
83 result
= write(fd
, rbuf
->buf_data
+ (consumed_old
& (2 * 4096-1)), 4096);
84 ltt_do_put_subbuf(rbuf
, lttbuf
, consumed_old
);
87 //CPRINTF("There seems to be %ld bytes available", SUBBUF_TRUNC(local_read(<tbuf->offset), rbuf->chan) - consumed_old);
88 CPRINTF("Commit count %ld", local_read(<tbuf
->commit_count
[0]));
95 void start_consumer(void)
99 result
= clone(consumer
, consumer_stack
+sizeof(consumer_stack
)-1, CLONE_FS
| CLONE_FILES
| CLONE_VM
, NULL
);
105 void probe(const struct marker
*mdata
,
106 void *probe_private
, void *call_private
,
107 const char *fmt
, va_list *args
)
109 printf("In probe\n");
112 void inthandler(int sig
)
114 printf("in handler\n");
118 int init_int_handler(void)
121 struct sigaction act
;
123 result
= sigemptyset(&act
.sa_mask
);
125 PERROR("sigemptyset");
129 act
.sa_handler
= inthandler
;
130 act
.sa_flags
= SA_RESTART
;
132 /* Only defer ourselves. Also, try to restart interrupted
133 * syscalls to disturb the traced program as little as possible.
135 result
= sigaction(SIGINT
, &act
, NULL
);
150 init_ustrelay_transport();
152 printf("page size is %d\n", sysconf(_SC_PAGE_SIZE
));
154 marker_control_init();
156 //marker_probe_register("abc", "testmark", "", probe, NULL);
157 //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);
158 //ust// result = ltt_probe_register(&default_probe);
160 //ust// ERR("ltt_probe_register");
162 //result = ltt_marker_connect("metadata", "testev", "default");
164 // ERR("ltt_marker_connect");
167 result
= ltt_trace_setup(trace_name
);
169 ERR("ltt_trace_setup failed");
173 result
= ltt_trace_set_type(trace_name
, trace_type
);
175 ERR("ltt_trace_set_type failed");
179 result
= ltt_trace_alloc(trace_name
);
181 ERR("ltt_trace_alloc failed");
185 result
= ltt_trace_start(trace_name
);
187 ERR("ltt_trace_start failed");
192 printf("Hello, World!\n");
196 //trace_mark(abc, testmark, "", MARK_NOARGS);
197 //trace_mark(metadata, testev, "", MARK_NOARGS);
198 trace_mark(metadata
, core_marker_id
,
199 "channel %s name %s event_id %hu "
200 "int #1u%zu long #1u%zu pointer #1u%zu "
201 "size_t #1u%zu alignment #1u%u",
202 "abc", "def", (unsigned short)1000,
203 sizeof(int), sizeof(long), sizeof(void *),
204 sizeof(size_t), ltt_get_alignment());
This page took 0.038021 seconds and 4 git commands to generate.