aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2007-05-16 11:57:36 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2007-05-16 11:57:36 -0400
commit9bee556de7489579c3bdd0d2d4d457ffa72168eb (patch)
tree717d15ada509379ff052fd50455e0089891f76b2 /src
parentd4f334c3e019d4fa1f50e33c51146dd469ee4178 (diff)
Nicer structure
Diffstat (limited to 'src')
-rw-r--r--src/ftcat.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/ftcat.c b/src/ftcat.c
new file mode 100644
index 0000000..bb7b3e6
--- /dev/null
+++ b/src/ftcat.c
@@ -0,0 +1,78 @@
1#include <stdio.h>
2#include <unistd.h>
3#include <fcntl.h>
4#include <string.h>
5
6#include "timestamp.h"
7
8
9static int enable_events(int fd, char* str)
10{
11 long id;
12 long cmd[3];
13
14 if (!strcmp(str, "sched")) {
15 id = TS_SCHED_START;
16 } else if (!strcmp(str, "tick")) {
17 id = TS_TICK_START;
18 } else if (!strcmp(str, "plug_tick")) {
19 id = TS_PLUGIN_TICK_START;
20 } else if (!strcmp(str, "plug_sched")) {
21 id = TS_PLUGIN_SCHED_START;
22 } else
23 return 0;
24
25 cmd[0] = ENABLE_CMD;
26 cmd[1] = id;
27 cmd[2] = id + 2;
28 return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long);
29}
30
31
32
33static void cat2stdout(int fd)
34{
35 static char buf[4096];
36 int rd;
37 while (rd = read(fd, buf, 4096))
38 fwrite(buf, 1, rd, stdout);
39}
40
41
42static void usage(void)
43{
44 fprintf(stderr,
45 "Usage: ftcat <ft device> TS1 TS2 ....\n\n"
46 "where TS1, TS2, ... is one of "
47 " sched, tick, plug_tick, plug_sched"
48 "\n");
49 exit(1);
50}
51
52int main(int argc, char** argv)
53{
54 int fd;
55
56 if (argc < 3)
57 usage();
58
59 fd = open(argv[1], O_RDWR);
60 if (fd < 0) {
61 perror("could not open feathertrace");
62 return 1;
63 }
64 argc -= 2;
65 argv += 2;
66 while (argc--) {
67 if (!enable_events(fd, *argv)) {
68 fprintf(stderr, "Enabling %s failed.\n", *argv);
69 return 2;
70 }
71 argv++;
72 }
73
74 cat2stdout(fd);
75 close(fd);
76 return 0;
77}
78