diff options
| author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-02-18 02:58:10 -0500 |
|---|---|---|
| committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-02-18 02:58:10 -0500 |
| commit | cff74703ad71f333491941d85baaa3f1835101fc (patch) | |
| tree | 2976df8f569e01c47ca73f4296964b5f284439a9 /src | |
| parent | 690b3db97d0f5e74ab8d14cb70f0601a4eb0cb79 (diff) | |
allow binary output in ft2csv
This can help with large data sets.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ft2csv.c | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/src/ft2csv.c b/src/ft2csv.c index 17898c6..b52a3a1 100644 --- a/src/ft2csv.c +++ b/src/ft2csv.c | |||
| @@ -91,6 +91,25 @@ static struct timestamp* find_second_ts(struct timestamp* start, | |||
| 91 | start->event); | 91 | start->event); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | typedef void (*pair_fmt_t)(struct timestamp* first, struct timestamp* second); | ||
| 95 | |||
| 96 | static void print_pair_csv(struct timestamp* first, struct timestamp* second) | ||
| 97 | { | ||
| 98 | printf("%llu, %llu, %llu\n", | ||
| 99 | (unsigned long long) first->timestamp, | ||
| 100 | (unsigned long long) second->timestamp, | ||
| 101 | (unsigned long long) | ||
| 102 | (second->timestamp - first->timestamp)); | ||
| 103 | } | ||
| 104 | |||
| 105 | static void print_pair_bin(struct timestamp* first, struct timestamp* second) | ||
| 106 | { | ||
| 107 | float delta = second->timestamp - first->timestamp; | ||
| 108 | fwrite(&delta, sizeof(delta), 1, stdout); | ||
| 109 | } | ||
| 110 | |||
| 111 | pair_fmt_t format_pair = print_pair_csv; | ||
| 112 | |||
| 94 | static void show_csv(struct timestamp* first, struct timestamp *end) | 113 | static void show_csv(struct timestamp* first, struct timestamp *end) |
| 95 | { | 114 | { |
| 96 | struct timestamp *second; | 115 | struct timestamp *second; |
| @@ -103,22 +122,33 @@ static void show_csv(struct timestamp* first, struct timestamp *end) | |||
| 103 | second->task_type != TSK_RT && !want_best_effort) | 122 | second->task_type != TSK_RT && !want_best_effort) |
| 104 | non_rt++; | 123 | non_rt++; |
| 105 | else { | 124 | else { |
| 106 | printf("%llu, %llu, %llu\n", | 125 | format_pair(first, second); |
| 107 | (unsigned long long) first->timestamp, | ||
| 108 | (unsigned long long) second->timestamp, | ||
| 109 | (unsigned long long) | ||
| 110 | (second->timestamp - first->timestamp)); | ||
| 111 | complete++; | 126 | complete++; |
| 112 | } | 127 | } |
| 113 | } else | 128 | } else |
| 114 | incomplete++; | 129 | incomplete++; |
| 115 | } | 130 | } |
| 116 | 131 | ||
| 117 | static void show_single_csv(struct timestamp* ts) | 132 | typedef void (*single_fmt_t)(struct timestamp* ts); |
| 133 | |||
| 134 | static void print_single_csv(struct timestamp* ts) | ||
| 135 | { | ||
| 136 | printf("0, 0, %llu\n", | ||
| 137 | (unsigned long long) (ts->timestamp)); | ||
| 138 | } | ||
| 139 | |||
| 140 | static void print_single_bin(struct timestamp* ts) | ||
| 141 | { | ||
| 142 | float delta = ts->timestamp; | ||
| 143 | fwrite(&delta, sizeof(delta), 1, stdout); | ||
| 144 | } | ||
| 145 | |||
| 146 | single_fmt_t single_fmt = print_single_csv; | ||
| 147 | |||
| 148 | static void show_single(struct timestamp* ts) | ||
| 118 | { | 149 | { |
| 119 | if (ts->task_type == TSK_RT) { | 150 | if (ts->task_type == TSK_RT) { |
| 120 | printf("0, 0, %llu\n", | 151 | single_fmt(ts); |
| 121 | (unsigned long long) (ts->timestamp)); | ||
| 122 | complete++; | 152 | complete++; |
| 123 | } else | 153 | } else |
| 124 | non_rt++; | 154 | non_rt++; |
| @@ -142,14 +172,15 @@ static void show_single_records(struct timestamp* start, struct timestamp* end, | |||
| 142 | { | 172 | { |
| 143 | for (; start != end; start++) | 173 | for (; start != end; start++) |
| 144 | if (start->event == id) | 174 | if (start->event == id) |
| 145 | show_single_csv(start); | 175 | show_single(start); |
| 146 | } | 176 | } |
| 147 | 177 | ||
| 148 | #define USAGE \ | 178 | #define USAGE \ |
| 149 | "Usage: ft2csv [-e] [-i] [-b] <event_name> <logfile> \n" \ | 179 | "Usage: ft2csv [-r] [-i] [-b] <event_name> <logfile> \n" \ |
| 150 | " -i: ignore interleaved -- ignore samples if start " \ | 180 | " -i: ignore interleaved -- ignore samples if start " \ |
| 151 | "and end are non-consecutive\n" \ | 181 | "and end are non-consecutive\n" \ |
| 152 | " -b: best effort -- don't skip non-rt time stamps \n" \ | 182 | " -b: best effort -- don't skip non-rt time stamps \n" \ |
| 183 | " -r: raw binary format -- don't produce .csv output \n" \ | ||
| 153 | "" | 184 | "" |
| 154 | 185 | ||
| 155 | static void die(char* msg) | 186 | static void die(char* msg) |
| @@ -161,7 +192,7 @@ static void die(char* msg) | |||
| 161 | exit(1); | 192 | exit(1); |
| 162 | } | 193 | } |
| 163 | 194 | ||
| 164 | #define OPTS "ib" | 195 | #define OPTS "ibr" |
| 165 | 196 | ||
| 166 | int main(int argc, char** argv) | 197 | int main(int argc, char** argv) |
| 167 | { | 198 | { |
| @@ -180,6 +211,10 @@ int main(int argc, char** argv) | |||
| 180 | case 'b': | 211 | case 'b': |
| 181 | want_best_effort = 1; | 212 | want_best_effort = 1; |
| 182 | break; | 213 | break; |
| 214 | case 'r': | ||
| 215 | single_fmt = print_single_bin; | ||
| 216 | format_pair = print_pair_bin; | ||
| 217 | break; | ||
| 183 | default: | 218 | default: |
| 184 | die("Unknown option."); | 219 | die("Unknown option."); |
| 185 | break; | 220 | break; |
