diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-25 00:18:22 -0400 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-25 00:18:22 -0400 |
commit | 61c3279f8a1e8f4a742a470b37c1ceb4fe6f6b3b (patch) | |
tree | 7ec8ecef571d97515e789dfb7a17a9174788f5ff | |
parent | 1c6aeb0448af8712ad5ca8a695351d397bc1e0ce (diff) |
add support for big/little endian swapping
-rw-r--r-- | src/ft2csv.c | 81 |
1 files changed, 67 insertions, 14 deletions
diff --git a/src/ft2csv.c b/src/ft2csv.c index 2cd417c..bed2645 100644 --- a/src/ft2csv.c +++ b/src/ft2csv.c | |||
@@ -2,6 +2,8 @@ | |||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include <errno.h> | 4 | #include <errno.h> |
5 | #include <unistd.h> | ||
6 | #include <arpa/inet.h> | ||
5 | 7 | ||
6 | #include "mapping.h" | 8 | #include "mapping.h" |
7 | 9 | ||
@@ -19,7 +21,7 @@ static unsigned int interleaved = 0; | |||
19 | static unsigned long long threshold = 2700 * 1000; /* 1 ms == 1 full tick */ | 21 | static unsigned long long threshold = 2700 * 1000; /* 1 ms == 1 full tick */ |
20 | //static unsigned long long threshold = 2700 * 50; /* 1 ms == 1 full tick */ | 22 | //static unsigned long long threshold = 2700 * 50; /* 1 ms == 1 full tick */ |
21 | 23 | ||
22 | static struct timestamp* next(struct timestamp* start, struct timestamp* end, | 24 | static struct timestamp* next(struct timestamp* start, struct timestamp* end, |
23 | int cpu) | 25 | int cpu) |
24 | { | 26 | { |
25 | struct timestamp* pos; | 27 | struct timestamp* pos; |
@@ -62,22 +64,50 @@ static void show_csv(struct timestamp* first, struct timestamp *end) | |||
62 | if (second) { | 64 | if (second) { |
63 | if (second->timestamp - first->timestamp > threshold) | 65 | if (second->timestamp - first->timestamp > threshold) |
64 | filtered++; | 66 | filtered++; |
65 | else if (first->task_type != TSK_RT && | 67 | else if (first->task_type != TSK_RT && |
66 | second->task_type != TSK_RT) | 68 | second->task_type != TSK_RT) |
67 | non_rt++; | 69 | non_rt++; |
68 | else { | 70 | else { |
69 | printf("%llu, %llu, %llu\n", | 71 | printf("%llu, %llu, %llu\n", |
70 | (unsigned long long) first->timestamp, | 72 | (unsigned long long) first->timestamp, |
71 | (unsigned long long) second->timestamp, | 73 | (unsigned long long) second->timestamp, |
72 | (unsigned long long) | 74 | (unsigned long long) |
73 | (second->timestamp - first->timestamp)); | 75 | (second->timestamp - first->timestamp)); |
74 | complete++; | 76 | complete++; |
75 | } | 77 | } |
76 | } else | 78 | } else |
77 | incomplete++; | 79 | incomplete++; |
78 | 80 | ||
81 | } | ||
82 | |||
83 | static inline uint64_t bget(int x, uint64_t quad) | ||
84 | |||
85 | { | ||
86 | return (((0xffll << 8 * x) & quad) >> 8 * x); | ||
87 | } | ||
88 | |||
89 | static inline uint64_t bput(uint64_t b, int pos) | ||
90 | { | ||
91 | return (b << 8 * pos); | ||
92 | } | ||
93 | |||
94 | static inline uint64_t ntohx(uint64_t q) | ||
95 | { | ||
96 | return (bput(bget(0, q), 7) | bput(bget(1, q), 6) | bput(bget(2, q), 5) | | ||
97 | bput(bget(3, q), 4) | bput(bget(4, q), 3) | bput(bget(5, q), 2) | | ||
98 | bput(bget(6, q), 1) | bput(bget(7, q), 0)); | ||
79 | } | 99 | } |
80 | 100 | ||
101 | static void restore_byte_order(struct timestamp* start, struct timestamp* end) | ||
102 | { | ||
103 | struct timestamp* pos = start; | ||
104 | while (pos !=end) { | ||
105 | pos->timestamp = ntohx(pos->timestamp); | ||
106 | pos->seq_no = ntohl(pos->seq_no); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | |||
81 | static void show_id(struct timestamp* start, struct timestamp* end, | 111 | static void show_id(struct timestamp* start, struct timestamp* end, |
82 | unsigned long id) | 112 | unsigned long id) |
83 | { | 113 | { |
@@ -95,29 +125,52 @@ static void die(char* msg) | |||
95 | { | 125 | { |
96 | if (errno) | 126 | if (errno) |
97 | perror("error: "); | 127 | perror("error: "); |
98 | fprintf(stderr, "%s\n", msg); | 128 | fprintf(stderr, "%s\n", msg); |
99 | exit(1); | 129 | exit(1); |
100 | } | 130 | } |
101 | 131 | ||
102 | int main(int argc, char** argv) | 132 | #define OPTS "e" |
133 | |||
134 | int main(int argc, char** argv) | ||
103 | { | 135 | { |
104 | void* mapped; | 136 | void* mapped; |
105 | size_t size, count; | 137 | size_t size, count; |
106 | struct timestamp *ts, *end; | 138 | struct timestamp *ts, *end; |
107 | cmd_t id; | 139 | cmd_t id; |
140 | int swap_byte_order = 0; | ||
141 | int opt; | ||
142 | |||
143 | /* | ||
144 | printf("%llx -> %llx\n", 0xaabbccddeeff1122ll, | ||
145 | ntohx(0xaabbccddeeff1122ll)); | ||
146 | printf("%x -> %x\n", 0xaabbccdd, | ||
147 | ntohl(0xaabbccdd)); | ||
148 | */ | ||
149 | while ((opt = getopt(argc, argv, OPTS)) != -1) { | ||
150 | switch (opt) { | ||
151 | case 'e': | ||
152 | swap_byte_order = 1; | ||
153 | break; | ||
154 | default: | ||
155 | die("Unknown option."); | ||
156 | break; | ||
157 | } | ||
158 | } | ||
108 | 159 | ||
109 | if (argc != 3) | 160 | if (argc - optind != 2) |
110 | die("Usage: ft2csv <event_name> <logfile>"); | 161 | die("Usage: ft2csv [-e] <event_name> <logfile>"); |
111 | if (map_file(argv[2], &mapped, &size)) | 162 | if (map_file(argv[optind + 1], &mapped, &size)) |
112 | die("could not map file"); | 163 | die("could not map file"); |
113 | 164 | ||
114 | if (!str2event(argv[1], &id)) | 165 | if (!str2event(argv[optind], &id)) |
115 | die("Unknown event!"); | 166 | die("Unknown event!"); |
116 | 167 | ||
117 | ts = (struct timestamp*) mapped; | 168 | ts = (struct timestamp*) mapped; |
118 | count = size / sizeof(struct timestamp); | 169 | count = size / sizeof(struct timestamp); |
119 | end = ts + count; | 170 | end = ts + count; |
120 | 171 | ||
172 | if (swap_byte_order) | ||
173 | restore_byte_order(ts, end); | ||
121 | show_id(ts, end, id); | 174 | show_id(ts, end, id); |
122 | 175 | ||
123 | fprintf(stderr, | 176 | fprintf(stderr, |
@@ -129,7 +182,7 @@ int main(int argc, char** argv) | |||
129 | "Non RT : %10d\n" | 182 | "Non RT : %10d\n" |
130 | "Interleaved : %10d\n", | 183 | "Interleaved : %10d\n", |
131 | (int) count, | 184 | (int) count, |
132 | skipped, complete, | 185 | skipped, complete, |
133 | incomplete, filtered, non_rt, | 186 | incomplete, filtered, non_rt, |
134 | interleaved); | 187 | interleaved); |
135 | 188 | ||