aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2012-10-19 15:36:09 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2012-10-19 16:54:29 -0400
commit3896f9f1eef468312cf622974c4c7ac0b287bf88 (patch)
treea06d4cc7227b7a7e6bcede171aab68ffa82f6b7f /src
parent4531e293279cdc817f7ac37bff9472e74cb085ee (diff)
Add -s (simulate) and -v (verbose) flags to ftsort
The -s flag prevents ftsort from writing back results to disk. The -v (verbose) flag enables more detailed output. These flags are useful when debugging traces and filtering.
Diffstat (limited to 'src')
-rw-r--r--src/ftsort.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/ftsort.c b/src/ftsort.c
index 5ddb48f..03e2686 100644
--- a/src/ftsort.c
+++ b/src/ftsort.c
@@ -1,5 +1,5 @@
1/* ft2sort -- Sort Feather-Trace events in a binary file by sequence number. 1/* ft2sort -- Sort Feather-Trace events in a binary file by sequence number.
2 * Copyright (C) 2011 B. Brandenburg. 2 * Copyright (C) 2011,2012 B. Brandenburg.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
@@ -35,6 +35,7 @@ static unsigned int holes = 0;
35static unsigned int reordered = 0; 35static unsigned int reordered = 0;
36 36
37#define LOOK_AHEAD 1000 37#define LOOK_AHEAD 1000
38static int want_verbose = 0;
38 39
39/* wall-clock time in seconds */ 40/* wall-clock time in seconds */
40double wctime(void) 41double wctime(void)
@@ -133,8 +134,10 @@ static void restore_byte_order(struct timestamp* start, struct timestamp* end)
133#define USAGE \ 134#define USAGE \
134 "Usage: ftsort [-e] <logfile> \n" \ 135 "Usage: ftsort [-e] <logfile> \n" \
135 " -e: endianess swap -- restores byte order \n" \ 136 " -e: endianess swap -- restores byte order \n" \
137 " -s: simulate -- don't overwrite file\n" \
138 " -v: verbose -- be chatty\n" \
136 "\n" \ 139 "\n" \
137 "WARNING: Changes are permanent.\n" 140 "WARNING: Changes are permanent, unless -s is specified.\n"
138 141
139static void die(char* msg) 142static void die(char* msg)
140{ 143{
@@ -145,7 +148,7 @@ static void die(char* msg)
145 exit(1); 148 exit(1);
146} 149}
147 150
148#define OPTS "e" 151#define OPTS "esv"
149 152
150int main(int argc, char** argv) 153int main(int argc, char** argv)
151{ 154{
@@ -153,6 +156,7 @@ int main(int argc, char** argv)
153 size_t size, count; 156 size_t size, count;
154 struct timestamp *ts, *end; 157 struct timestamp *ts, *end;
155 int swap_byte_order = 0; 158 int swap_byte_order = 0;
159 int simulate = 0;
156 int opt; 160 int opt;
157 double start, stop; 161 double start, stop;
158 162
@@ -161,6 +165,12 @@ int main(int argc, char** argv)
161 case 'e': 165 case 'e':
162 swap_byte_order = 1; 166 swap_byte_order = 1;
163 break; 167 break;
168 case 's':
169 simulate = 1;
170 break;
171 case 'v':
172 want_verbose = 1;
173 break;
164 default: 174 default:
165 die("Unknown option."); 175 die("Unknown option.");
166 break; 176 break;
@@ -172,8 +182,13 @@ int main(int argc, char** argv)
172 182
173 start = wctime(); 183 start = wctime();
174 184
175 if (map_file_rw(argv[optind], &mapped, &size)) 185 if (simulate) {
176 die("could not map file"); 186 if (map_file(argv[optind], &mapped, &size))
187 die("could not RO map file");
188 } else {
189 if (map_file_rw(argv[optind], &mapped, &size))
190 die("could not RW map file");
191 }
177 192
178 ts = (struct timestamp*) mapped; 193 ts = (struct timestamp*) mapped;
179 count = size / sizeof(struct timestamp); 194 count = size / sizeof(struct timestamp);
@@ -185,7 +200,10 @@ int main(int argc, char** argv)
185 reorder(ts, end); 200 reorder(ts, end);
186 201
187 /* write back */ 202 /* write back */
188 msync(ts, size, MS_SYNC | MS_INVALIDATE); 203 if (simulate)
204 fprintf(stderr, "Note: not writing back results.\n");
205 else
206 msync(ts, size, MS_SYNC | MS_INVALIDATE);
189 207
190 stop = wctime(); 208 stop = wctime();
191 209