Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org> |
| 4 | */ |
| 5 | |
| 6 | #include <getopt.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | #include <stdio.h> |
| 10 | |
Daniel Bristot de Oliveira | 0605bf0 | 2021-12-10 19:11:22 +0100 | [diff] [blame] | 11 | #include "osnoise.h" |
Daniel Bristot de Oliveira | a828cd1 | 2021-12-10 19:11:25 +0100 | [diff] [blame] | 12 | #include "timerlat.h" |
Daniel Bristot de Oliveira | 0605bf0 | 2021-12-10 19:11:22 +0100 | [diff] [blame] | 13 | |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 14 | /* |
| 15 | * rtla_usage - print rtla usage |
| 16 | */ |
| 17 | static void rtla_usage(void) |
| 18 | { |
| 19 | int i; |
| 20 | |
| 21 | static const char *msg[] = { |
| 22 | "", |
| 23 | "rtla version " VERSION, |
| 24 | "", |
| 25 | " usage: rtla COMMAND ...", |
| 26 | "", |
| 27 | " commands:", |
Daniel Bristot de Oliveira | 0605bf0 | 2021-12-10 19:11:22 +0100 | [diff] [blame] | 28 | " osnoise - gives information about the operating system noise (osnoise)", |
Daniel Bristot de Oliveira | a828cd1 | 2021-12-10 19:11:25 +0100 | [diff] [blame] | 29 | " timerlat - measures the timer irq and thread latency", |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 30 | "", |
| 31 | NULL, |
| 32 | }; |
| 33 | |
| 34 | for (i = 0; msg[i]; i++) |
| 35 | fprintf(stderr, "%s\n", msg[i]); |
| 36 | exit(1); |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * run_command - try to run a rtla tool command |
| 41 | * |
| 42 | * It returns 0 if it fails. The tool's main will generally not |
| 43 | * return as they should call exit(). |
| 44 | */ |
| 45 | int run_command(int argc, char **argv, int start_position) |
| 46 | { |
Daniel Bristot de Oliveira | 0605bf0 | 2021-12-10 19:11:22 +0100 | [diff] [blame] | 47 | if (strcmp(argv[start_position], "osnoise") == 0) { |
| 48 | osnoise_main(argc-start_position, &argv[start_position]); |
| 49 | goto ran; |
Daniel Bristot de Oliveira | a828cd1 | 2021-12-10 19:11:25 +0100 | [diff] [blame] | 50 | } else if (strcmp(argv[start_position], "timerlat") == 0) { |
| 51 | timerlat_main(argc-start_position, &argv[start_position]); |
| 52 | goto ran; |
Daniel Bristot de Oliveira | 0605bf0 | 2021-12-10 19:11:22 +0100 | [diff] [blame] | 53 | } |
| 54 | |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 55 | return 0; |
Daniel Bristot de Oliveira | 0605bf0 | 2021-12-10 19:11:22 +0100 | [diff] [blame] | 56 | ran: |
| 57 | return 1; |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | int main(int argc, char *argv[]) |
| 61 | { |
| 62 | int retval; |
| 63 | |
| 64 | /* is it an alias? */ |
| 65 | retval = run_command(argc, argv, 0); |
| 66 | if (retval) |
| 67 | exit(0); |
| 68 | |
| 69 | if (argc < 2) |
| 70 | goto usage; |
| 71 | |
| 72 | if (strcmp(argv[1], "-h") == 0) { |
| 73 | rtla_usage(); |
| 74 | exit(0); |
| 75 | } else if (strcmp(argv[1], "--help") == 0) { |
| 76 | rtla_usage(); |
| 77 | exit(0); |
| 78 | } |
| 79 | |
| 80 | retval = run_command(argc, argv, 1); |
| 81 | if (retval) |
| 82 | exit(0); |
| 83 | |
| 84 | usage: |
| 85 | rtla_usage(); |
| 86 | exit(1); |
| 87 | } |