diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-02-17 22:17:53 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-02-17 22:17:53 -0500 |
commit | 690b3db97d0f5e74ab8d14cb70f0601a4eb0cb79 (patch) | |
tree | 6deefa7c321b63efc712760e530aba6933490f13 | |
parent | 3e2ce9a7d1b33340651b7cc0e8d3ff14bbe1e868 (diff) |
Remove endian swapping from ft2csv; don't skip over holes
-rw-r--r-- | src/ft2csv.c | 55 |
1 files changed, 15 insertions, 40 deletions
diff --git a/src/ft2csv.c b/src/ft2csv.c index 0df45ce..17898c6 100644 --- a/src/ft2csv.c +++ b/src/ft2csv.c | |||
@@ -45,8 +45,20 @@ static struct timestamp* next(struct timestamp* start, struct timestamp* end, | |||
45 | int cpu) | 45 | int cpu) |
46 | { | 46 | { |
47 | struct timestamp* pos; | 47 | struct timestamp* pos; |
48 | for (pos = start; pos != end && pos->cpu != cpu; pos++); | 48 | unsigned int last_seqno = 0; |
49 | return pos != end ? pos : NULL; | 49 | |
50 | for (pos = start; pos != end; pos++) { | ||
51 | /* check for for holes in the sequence number */ | ||
52 | if (last_seqno && last_seqno + 1 != pos->seq_no) { | ||
53 | /* stumbled across a hole */ | ||
54 | return NULL; | ||
55 | } | ||
56 | last_seqno = pos->seq_no; | ||
57 | |||
58 | if (pos->cpu == cpu) | ||
59 | return pos; | ||
60 | } | ||
61 | return NULL; | ||
50 | } | 62 | } |
51 | 63 | ||
52 | static struct timestamp* next_id(struct timestamp* start, struct timestamp* end, | 64 | static struct timestamp* next_id(struct timestamp* start, struct timestamp* end, |
@@ -112,35 +124,6 @@ static void show_single_csv(struct timestamp* ts) | |||
112 | non_rt++; | 124 | non_rt++; |
113 | } | 125 | } |
114 | 126 | ||
115 | static inline uint64_t bget(int x, uint64_t quad) | ||
116 | |||
117 | { | ||
118 | return (((0xffll << 8 * x) & quad) >> 8 * x); | ||
119 | } | ||
120 | |||
121 | static inline uint64_t bput(uint64_t b, int pos) | ||
122 | { | ||
123 | return (b << 8 * pos); | ||
124 | } | ||
125 | |||
126 | static inline uint64_t ntohx(uint64_t q) | ||
127 | { | ||
128 | return (bput(bget(0, q), 7) | bput(bget(1, q), 6) | | ||
129 | bput(bget(2, q), 5) | bput(bget(3, q), 4) | | ||
130 | bput(bget(4, q), 3) | bput(bget(5, q), 2) | | ||
131 | bput(bget(6, q), 1) | bput(bget(7, q), 0)); | ||
132 | } | ||
133 | |||
134 | static void restore_byte_order(struct timestamp* start, struct timestamp* end) | ||
135 | { | ||
136 | struct timestamp* pos = start; | ||
137 | while (pos !=end) { | ||
138 | pos->timestamp = ntohx(pos->timestamp); | ||
139 | pos->seq_no = ntohl(pos->seq_no); | ||
140 | pos++; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | static void show_id(struct timestamp* start, struct timestamp* end, | 127 | static void show_id(struct timestamp* start, struct timestamp* end, |
145 | unsigned long id) | 128 | unsigned long id) |
146 | { | 129 | { |
@@ -164,7 +147,6 @@ static void show_single_records(struct timestamp* start, struct timestamp* end, | |||
164 | 147 | ||
165 | #define USAGE \ | 148 | #define USAGE \ |
166 | "Usage: ft2csv [-e] [-i] [-b] <event_name> <logfile> \n" \ | 149 | "Usage: ft2csv [-e] [-i] [-b] <event_name> <logfile> \n" \ |
167 | " -e: endianess swap -- restores byte order \n" \ | ||
168 | " -i: ignore interleaved -- ignore samples if start " \ | 150 | " -i: ignore interleaved -- ignore samples if start " \ |
169 | "and end are non-consecutive\n" \ | 151 | "and end are non-consecutive\n" \ |
170 | " -b: best effort -- don't skip non-rt time stamps \n" \ | 152 | " -b: best effort -- don't skip non-rt time stamps \n" \ |
@@ -179,7 +161,7 @@ static void die(char* msg) | |||
179 | exit(1); | 161 | exit(1); |
180 | } | 162 | } |
181 | 163 | ||
182 | #define OPTS "eib" | 164 | #define OPTS "ib" |
183 | 165 | ||
184 | int main(int argc, char** argv) | 166 | int main(int argc, char** argv) |
185 | { | 167 | { |
@@ -187,15 +169,11 @@ int main(int argc, char** argv) | |||
187 | size_t size, count; | 169 | size_t size, count; |
188 | struct timestamp *ts, *end; | 170 | struct timestamp *ts, *end; |
189 | cmd_t id; | 171 | cmd_t id; |
190 | int swap_byte_order = 0; | ||
191 | int opt; | 172 | int opt; |
192 | char event_name[80]; | 173 | char event_name[80]; |
193 | 174 | ||
194 | while ((opt = getopt(argc, argv, OPTS)) != -1) { | 175 | while ((opt = getopt(argc, argv, OPTS)) != -1) { |
195 | switch (opt) { | 176 | switch (opt) { |
196 | case 'e': | ||
197 | swap_byte_order = 1; | ||
198 | break; | ||
199 | case 'i': | 177 | case 'i': |
200 | want_interleaved = 0; | 178 | want_interleaved = 0; |
201 | break; | 179 | break; |
@@ -225,9 +203,6 @@ int main(int argc, char** argv) | |||
225 | count = size / sizeof(struct timestamp); | 203 | count = size / sizeof(struct timestamp); |
226 | end = ts + count; | 204 | end = ts + count; |
227 | 205 | ||
228 | if (swap_byte_order) | ||
229 | restore_byte_order(ts, end); | ||
230 | |||
231 | if (id >= SINGLE_RECORDS_RANGE) | 206 | if (id >= SINGLE_RECORDS_RANGE) |
232 | show_single_records(ts, end, id); | 207 | show_single_records(ts, end, id); |
233 | else | 208 | else |