Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / tracing / rtla / src / timerlat.c
blob21cdcc5c4a2960de9ce32fcc0b54b4ad82a26b7c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
4 */
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <pthread.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <errno.h>
12 #include <fcntl.h>
13 #include <stdio.h>
15 #include "timerlat.h"
17 static void timerlat_usage(int err)
19 int i;
21 static const char * const msg[] = {
22 "",
23 "timerlat version " VERSION,
24 "",
25 " usage: [rtla] timerlat [MODE] ...",
26 "",
27 " modes:",
28 " top - prints the summary from timerlat tracer",
29 " hist - prints a histogram of timer latencies",
30 "",
31 "if no MODE is given, the top mode is called, passing the arguments",
32 NULL,
35 for (i = 0; msg[i]; i++)
36 fprintf(stderr, "%s\n", msg[i]);
37 exit(err);
40 int timerlat_main(int argc, char *argv[])
42 if (argc == 0)
43 goto usage;
46 * if timerlat was called without any argument, run the
47 * default cmdline.
49 if (argc == 1) {
50 timerlat_top_main(argc, argv);
51 exit(0);
54 if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) {
55 timerlat_usage(0);
56 } else if (strncmp(argv[1], "-", 1) == 0) {
57 /* the user skipped the tool, call the default one */
58 timerlat_top_main(argc, argv);
59 exit(0);
60 } else if (strcmp(argv[1], "top") == 0) {
61 timerlat_top_main(argc-1, &argv[1]);
62 exit(0);
63 } else if (strcmp(argv[1], "hist") == 0) {
64 timerlat_hist_main(argc-1, &argv[1]);
65 exit(0);
68 usage:
69 timerlat_usage(1);
70 exit(1);