diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2016-02-17 13:09:03 -0500 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2016-03-08 11:03:49 -0500 |
| commit | d085e70581760ffb9231bd01d79e08be6a1604ef (patch) | |
| tree | 3b55dc705bb30a49381760034900d2aec0fdf9fa /src | |
| parent | b990a32d15f0f95afe4b08e264bf016e251e3b40 (diff) | |
ftcat: add -p (ping) option
Ask ftcat to store its PID when it is done with initialization.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ftcat.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/ftcat.c b/src/ftcat.c index 483bc6e..548498d 100644 --- a/src/ftcat.c +++ b/src/ftcat.c | |||
| @@ -112,6 +112,14 @@ static void cat2stdout(int fd) | |||
| 112 | } | 112 | } |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | static void ping(const char* fname) | ||
| 116 | { | ||
| 117 | FILE* f = fopen(fname, "a"); | ||
| 118 | if (f) { | ||
| 119 | fprintf(f, "%d\n", getpid()); | ||
| 120 | fclose(f); | ||
| 121 | } | ||
| 122 | } | ||
| 115 | 123 | ||
| 116 | static void _usage(void) | 124 | static void _usage(void) |
| 117 | { | 125 | { |
| @@ -120,6 +128,7 @@ static void _usage(void) | |||
| 120 | "\nOptions:\n" | 128 | "\nOptions:\n" |
| 121 | " -s SIZE -- stop tracing afer recording SIZE bytes\n" | 129 | " -s SIZE -- stop tracing afer recording SIZE bytes\n" |
| 122 | " -c -- calibrate the CPU cycle counter offsets\n" | 130 | " -c -- calibrate the CPU cycle counter offsets\n" |
| 131 | " -p FILE -- ping: write PID to FILE after initialization\n" | ||
| 123 | " -v -- enable verbose output\n" | 132 | " -v -- enable verbose output\n" |
| 124 | "\n"); | 133 | "\n"); |
| 125 | exit(1); | 134 | exit(1); |
| @@ -135,7 +144,7 @@ static void shutdown(int sig) | |||
| 135 | fprintf(stderr, "disable_all: %m\n"); | 144 | fprintf(stderr, "disable_all: %m\n"); |
| 136 | } | 145 | } |
| 137 | 146 | ||
| 138 | #define OPTSTR "s:cv" | 147 | #define OPTSTR "s:cvp:" |
| 139 | 148 | ||
| 140 | int main(int argc, char** argv) | 149 | int main(int argc, char** argv) |
| 141 | { | 150 | { |
| @@ -143,6 +152,7 @@ int main(int argc, char** argv) | |||
| 143 | int want_calibrate = 0; | 152 | int want_calibrate = 0; |
| 144 | 153 | ||
| 145 | const char* trace_file; | 154 | const char* trace_file; |
| 155 | const char* ping_file = NULL; | ||
| 146 | 156 | ||
| 147 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { | 157 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { |
| 148 | switch (opt) { | 158 | switch (opt) { |
| @@ -157,6 +167,9 @@ int main(int argc, char** argv) | |||
| 157 | case 'v': | 167 | case 'v': |
| 158 | verbose = 1; | 168 | verbose = 1; |
| 159 | break; | 169 | break; |
| 170 | case 'p': | ||
| 171 | ping_file = optarg; | ||
| 172 | break; | ||
| 160 | case ':': | 173 | case ':': |
| 161 | usage("Argument missing."); | 174 | usage("Argument missing."); |
| 162 | break; | 175 | break; |
| @@ -198,6 +211,9 @@ int main(int argc, char** argv) | |||
| 198 | argv++; | 211 | argv++; |
| 199 | } | 212 | } |
| 200 | 213 | ||
| 214 | if (ping_file) | ||
| 215 | ping(ping_file); | ||
| 216 | |||
| 201 | cat2stdout(fd); | 217 | cat2stdout(fd); |
| 202 | close(fd); | 218 | close(fd); |
| 203 | fflush(stdout); | 219 | fflush(stdout); |
