Commit 3abf6c50 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Small modification to trace_dump.

It can now be used to make a dump from a trace stream on stdin.
Nice for taking a quick look at traces which were dumped to disk first.
parent 2b2fee09
......@@ -87,25 +87,45 @@ static void handler_value(struct trace *trace,
}
}
void usage(void)
{
printf("Usage:\n\n");
printf("trace_dump [host] [port] [trace] <interval>\n");
exit(0);
}
int main(int argc, char **argv)
{
struct trace *trace;
struct trace_pkt *pkt;
int interval = 1;
uint64_t nsec_interval;
bool fromstdin = false;
if (argc < 4) {
printf("Usage:\n\n");
printf("%s [host] [port] [trace] <interval>\n", argv[0]);
return 0;
if (argc < 2) {
usage();
}
if (!strcmp(argv[1], "-")) {
fromstdin = true;
}
if (!fromstdin && argc < 4) {
usage();
}
tracename = argv[3];
if (!fromstdin) {
tracename = argv[3];
trace = trace_open(argv[1], atoi(argv[2]));
if (argc >= 5) {
interval = atoi(argv[4]);
}
trace = trace_open(argv[1], atoi(argv[2]));
if (argc >= 5) {
interval = atoi(argv[4]);
} else {
trace = trace_alloc();
trace_initialize_fd(trace, 0);
}
trace->handler_interval = handler_interval;
......@@ -125,29 +145,31 @@ int main(int argc, char **argv)
trace_handle(trace, &fdrx);
}
printf("Connection ready for tracing\n");
if (!fromstdin) {
printf("Connection ready for tracing\n");
if (interval) {
nsec_interval = t_int.tv_sec * 1000000000;
nsec_interval += t_int.tv_nsec;
if (interval) {
nsec_interval = t_int.tv_sec * 1000000000;
nsec_interval += t_int.tv_nsec;
nsec_interval *= interval;
nsec_interval *= interval;
t_int.tv_nsec = nsec_interval % 1000000000;
t_int.tv_sec = nsec_interval / 1000000000;
t_int.tv_nsec = nsec_interval % 1000000000;
t_int.tv_sec = nsec_interval / 1000000000;
pkt = trace_packet_new();
trace_packet_interval_set(pkt,
&t_int, TRACE_INTERVAL_TYPE_INTERVAL);
trace_packet_write(trace, pkt);
trace_packet_put(pkt);
}
pkt = trace_packet_new();
trace_packet_interval_set(pkt,
&t_int, TRACE_INTERVAL_TYPE_INTERVAL);
trace_packet_name_set(pkt, tracename);
trace_packet_write(trace, pkt);
trace_packet_put(pkt);
}
pkt = trace_packet_new();
trace_packet_name_set(pkt, tracename);
trace_packet_write(trace, pkt);
trace_packet_put(pkt);
printf("Wait for data\n");
while (trace_state_get(trace) == TRACE_STATE_RECEIVING ||
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment