blob: 09bd21b8af810b65a2af5fbbff35487c463be607 [file] [log] [blame]
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +01001// 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 Oliveira0605bf02021-12-10 19:11:22 +010011#include "osnoise.h"
Daniel Bristot de Oliveiraa828cd12021-12-10 19:11:25 +010012#include "timerlat.h"
Daniel Bristot de Oliveira0605bf02021-12-10 19:11:22 +010013
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010014/*
15 * rtla_usage - print rtla usage
16 */
17static 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 Oliveira0605bf02021-12-10 19:11:22 +010028 " osnoise - gives information about the operating system noise (osnoise)",
Daniel Bristot de Oliveiraa828cd12021-12-10 19:11:25 +010029 " timerlat - measures the timer irq and thread latency",
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010030 "",
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 */
45int run_command(int argc, char **argv, int start_position)
46{
Daniel Bristot de Oliveira0605bf02021-12-10 19:11:22 +010047 if (strcmp(argv[start_position], "osnoise") == 0) {
48 osnoise_main(argc-start_position, &argv[start_position]);
49 goto ran;
Daniel Bristot de Oliveiraa828cd12021-12-10 19:11:25 +010050 } else if (strcmp(argv[start_position], "timerlat") == 0) {
51 timerlat_main(argc-start_position, &argv[start_position]);
52 goto ran;
Daniel Bristot de Oliveira0605bf02021-12-10 19:11:22 +010053 }
54
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010055 return 0;
Daniel Bristot de Oliveira0605bf02021-12-10 19:11:22 +010056ran:
57 return 1;
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010058}
59
60int 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
84usage:
85 rtla_usage();
86 exit(1);
87}