diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2007-05-16 14:53:42 -0400 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2007-05-16 14:53:42 -0400 |
commit | 4d337d4d7a3c1e6a65b090251c4e41592740b0d0 (patch) | |
tree | 11a951fbd6fd3cc3dea8e102bd57a00acc94e852 /src/ftcat.c | |
parent | 9bee556de7489579c3bdd0d2d4d457ffa72168eb (diff) |
event naming
Diffstat (limited to 'src/ftcat.c')
-rw-r--r-- | src/ftcat.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/ftcat.c b/src/ftcat.c index bb7b3e6..151fa29 100644 --- a/src/ftcat.c +++ b/src/ftcat.c | |||
@@ -2,34 +2,34 @@ | |||
2 | #include <unistd.h> | 2 | #include <unistd.h> |
3 | #include <fcntl.h> | 3 | #include <fcntl.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | #include <signal.h> | ||
6 | #include <stdlib.h> | ||
5 | 7 | ||
6 | #include "timestamp.h" | 8 | #include "timestamp.h" |
7 | 9 | ||
10 | static int fd; | ||
11 | |||
12 | static void on_sigint(int sig) | ||
13 | { | ||
14 | close(fd); | ||
15 | exit(0); | ||
16 | } | ||
8 | 17 | ||
9 | static int enable_events(int fd, char* str) | 18 | static int enable_events(int fd, char* str) |
10 | { | 19 | { |
11 | long id; | 20 | unsigned long id; |
12 | long cmd[3]; | 21 | unsigned long cmd[3]; |
13 | 22 | ||
14 | if (!strcmp(str, "sched")) { | 23 | if (!str2event(str, &id)) |
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 | return 0; |
24 | 25 | ||
25 | cmd[0] = ENABLE_CMD; | 26 | cmd[0] = ENABLE_CMD; |
26 | cmd[1] = id; | 27 | cmd[1] = id; |
27 | cmd[2] = id + 2; | 28 | cmd[2] = id + 1; |
28 | return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long); | 29 | return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long); |
29 | } | 30 | } |
30 | 31 | ||
31 | 32 | ||
32 | |||
33 | static void cat2stdout(int fd) | 33 | static void cat2stdout(int fd) |
34 | { | 34 | { |
35 | static char buf[4096]; | 35 | static char buf[4096]; |
@@ -43,19 +43,17 @@ static void usage(void) | |||
43 | { | 43 | { |
44 | fprintf(stderr, | 44 | fprintf(stderr, |
45 | "Usage: ftcat <ft device> TS1 TS2 ....\n\n" | 45 | "Usage: ftcat <ft device> TS1 TS2 ....\n\n" |
46 | "where TS1, TS2, ... is one of " | 46 | // "where TS1, TS2, ... is one of " |
47 | " sched, tick, plug_tick, plug_sched" | 47 | // " sched, tick, plug_tick, plug_sche" |
48 | "\n"); | 48 | "\n"); |
49 | exit(1); | 49 | exit(1); |
50 | } | 50 | } |
51 | 51 | ||
52 | int main(int argc, char** argv) | 52 | int main(int argc, char** argv) |
53 | { | 53 | { |
54 | int fd; | ||
55 | |||
56 | if (argc < 3) | 54 | if (argc < 3) |
57 | usage(); | 55 | usage(); |
58 | 56 | ||
59 | fd = open(argv[1], O_RDWR); | 57 | fd = open(argv[1], O_RDWR); |
60 | if (fd < 0) { | 58 | if (fd < 0) { |
61 | perror("could not open feathertrace"); | 59 | perror("could not open feathertrace"); |
@@ -63,6 +61,7 @@ int main(int argc, char** argv) | |||
63 | } | 61 | } |
64 | argc -= 2; | 62 | argc -= 2; |
65 | argv += 2; | 63 | argv += 2; |
64 | signal(SIGINT,on_sigint); | ||
66 | while (argc--) { | 65 | while (argc--) { |
67 | if (!enable_events(fd, *argv)) { | 66 | if (!enable_events(fd, *argv)) { |
68 | fprintf(stderr, "Enabling %s failed.\n", *argv); | 67 | fprintf(stderr, "Enabling %s failed.\n", *argv); |