diff options
Diffstat (limited to 'measure_startup_oh.c')
| -rw-r--r-- | measure_startup_oh.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/measure_startup_oh.c b/measure_startup_oh.c index 56f9ea7..7c7ba14 100644 --- a/measure_startup_oh.c +++ b/measure_startup_oh.c | |||
| @@ -12,31 +12,32 @@ extern char **environ; | |||
| 12 | 12 | ||
| 13 | #include "testbench.h" | 13 | #include "testbench.h" |
| 14 | 14 | ||
| 15 | #define measure_launch_oh "./measure_launch_oh" | 15 | static char* child_argv_default[3] = {"./measure_launch_oh", "1", NULL}; |
| 16 | 16 | ||
| 17 | int main(int argc, char **argv) { | 17 | int main(int argc, char **argv) { |
| 18 | int *__unused, i; | ||
| 19 | struct timespec start; | 18 | struct timespec start; |
| 20 | 19 | ||
| 21 | if (argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) { | 20 | if (argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) { |
| 22 | fprintf(stderr, "Usage: %s [environment var to apply to child (optional)]\n", argv[0]); | 21 | fprintf(stderr, "Usage: %s [-e environment var to apply to child (optional) | prog prog_arg...]\n", argv[0]); |
| 23 | return 1; | 22 | return 1; |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | static char* child_argv[3]; | 25 | char **child_argv = child_argv_default; |
| 27 | child_argv[0] = measure_launch_oh; | 26 | if (argv[1]) { |
| 28 | child_argv[1] = "1"; | 27 | // Change env |
| 29 | child_argv[2] = NULL; | 28 | // (Use this to apply LD_PRELOAD to the child only) |
| 30 | 29 | if (!strcmp(argv[1], "-e")) | |
| 31 | // Use this to apply LD_PRELOAD to the child only | 30 | putenv(argv[2]); |
| 32 | if (argv[1]) | 31 | // Special exec (e.g., ./nvtaskset --gpc-list 0 ./measure_launch_oh 1) |
| 33 | putenv(argv[1]); | 32 | else |
| 33 | child_argv = &argv[1]; | ||
| 34 | } | ||
| 34 | 35 | ||
| 35 | clock_gettime(CLOCK_MONOTONIC_RAW, &start); | 36 | clock_gettime(CLOCK_MONOTONIC_RAW, &start); |
| 36 | fprintf(stderr, "(%d) Starting '"measure_launch_oh"' at CLOCK_MONOTONIC_RAW = %ld ns\n", | 37 | fprintf(stderr, "(%d) Starting '%s' at CLOCK_MONOTONIC_RAW = %ld ns\n", |
| 37 | getpid(), time2ns(start)); | 38 | getpid(), child_argv[0], time2ns(start)); |
| 38 | if (execve(measure_launch_oh, child_argv, environ)) { | 39 | if (execve(child_argv[0], child_argv, environ)) { |
| 39 | perror("Unable to start '"measure_launch_oh"'"); | 40 | perror("Unable to start subprogram"); |
| 40 | return 1; | 41 | return 1; |
| 41 | } | 42 | } |
| 42 | 43 | ||
