diff options
| author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-07-23 23:08:11 -0400 |
|---|---|---|
| committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-07-23 23:08:11 -0400 |
| commit | 61d55bc9bd3a6fb29bb9affbdcf96b0858da3c92 (patch) | |
| tree | 898a26ff2b998b2024ca94a89f604fb7b4b4872d /src | |
| parent | 1d0ae3db39174888ed9309186e1bc6caf6d9821a (diff) | |
Switch to ioctl() interface for Feather-Trace devices
Diffstat (limited to 'src')
| -rw-r--r-- | src/ftcat.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/ftcat.c b/src/ftcat.c index 61e007f..0116fc3 100644 --- a/src/ftcat.c +++ b/src/ftcat.c | |||
| @@ -24,43 +24,45 @@ | |||
| 24 | #include <unistd.h> | 24 | #include <unistd.h> |
| 25 | #include <errno.h> | 25 | #include <errno.h> |
| 26 | 26 | ||
| 27 | #include <sys/ioctl.h> | ||
| 28 | |||
| 27 | #include "timestamp.h" | 29 | #include "timestamp.h" |
| 28 | 30 | ||
| 29 | #define MAX_EVENTS 128 | 31 | #define MAX_EVENTS 128 |
| 30 | 32 | ||
| 31 | static int fd; | 33 | static int fd; |
| 32 | static int event_count = 1; | 34 | static int event_count = 0; |
| 33 | static cmd_t ids[MAX_EVENTS]; | 35 | static cmd_t ids[MAX_EVENTS]; |
| 34 | static unsigned long total_bytes = 0; | 36 | static unsigned long total_bytes = 0; |
| 35 | 37 | ||
| 36 | 38 | ||
| 37 | static int disable_all(int fd) | 39 | static int disable_all(int fd) |
| 38 | { | 40 | { |
| 39 | int ret, size; | 41 | int disabled = 0; |
| 40 | ids[0] = DISABLE_CMD; | 42 | int i; |
| 41 | fprintf(stderr, "Disabling %d events.\n", event_count - 1); | 43 | |
| 42 | size = event_count * sizeof(cmd_t); | 44 | fprintf(stderr, "Disabling %d events.\n", event_count); |
| 43 | ret = write(fd, ids, size); | 45 | for (i = 0; i < event_count; i++) |
| 44 | if (ret != size) | 46 | if (ioctl(fd, DISABLE_CMD, ids[i]) < 0) |
| 45 | fprintf(stderr, "write = %d, meant to write %d (%m)\n", ret, size); | 47 | perror("ioctl(DISABLE_CMD)"); |
| 46 | return size == ret; | 48 | else |
| 49 | disabled++; | ||
| 50 | |||
| 51 | return disabled == event_count; | ||
| 47 | } | 52 | } |
| 48 | 53 | ||
| 49 | static int enable_event(int fd, char* str) | 54 | static int enable_event(int fd, char* str) |
| 50 | { | 55 | { |
| 51 | cmd_t *id; | 56 | cmd_t *id; |
| 52 | cmd_t cmd[2]; | ||
| 53 | 57 | ||
| 54 | id = ids + event_count; | 58 | id = ids + event_count; |
| 55 | if (!str2event(str, id)) { | 59 | if (!str2event(str, id)) { |
| 56 | errno = EINVAL; | 60 | errno = EINVAL; |
| 57 | return 0; | 61 | return 0; |
| 58 | } | 62 | } |
| 59 | |||
| 60 | event_count += 1; | 63 | event_count += 1; |
| 61 | cmd[0] = ENABLE_CMD; | 64 | |
| 62 | cmd[1] = id[0]; | 65 | return ioctl(fd, ENABLE_CMD, *id) == 0; |
| 63 | return write(fd, cmd, sizeof(cmd)) == sizeof(cmd_t) * 2; | ||
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | 68 | ||
