Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
0004  */
0005 #include <sys/types.h>
0006 #include <sys/stat.h>
0007 #include <pthread.h>
0008 #include <stdlib.h>
0009 #include <string.h>
0010 #include <unistd.h>
0011 #include <errno.h>
0012 #include <fcntl.h>
0013 #include <stdio.h>
0014 
0015 #include "timerlat.h"
0016 
0017 static void timerlat_usage(void)
0018 {
0019     int i;
0020 
0021     static const char * const msg[] = {
0022         "",
0023         "timerlat version " VERSION,
0024         "",
0025         "  usage: [rtla] timerlat [MODE] ...",
0026         "",
0027         "  modes:",
0028         "     top   - prints the summary from timerlat tracer",
0029         "     hist  - prints a histogram of timer latencies",
0030         "",
0031         "if no MODE is given, the top mode is called, passing the arguments",
0032         NULL,
0033     };
0034 
0035     for (i = 0; msg[i]; i++)
0036         fprintf(stderr, "%s\n", msg[i]);
0037     exit(1);
0038 }
0039 
0040 int timerlat_main(int argc, char *argv[])
0041 {
0042     if (argc == 0)
0043         goto usage;
0044 
0045     /*
0046      * if timerlat was called without any argument, run the
0047      * default cmdline.
0048      */
0049     if (argc == 1) {
0050         timerlat_top_main(argc, argv);
0051         exit(0);
0052     }
0053 
0054     if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) {
0055         timerlat_usage();
0056         exit(0);
0057     } else if (strncmp(argv[1], "-", 1) == 0) {
0058         /* the user skipped the tool, call the default one */
0059         timerlat_top_main(argc, argv);
0060         exit(0);
0061     } else if (strcmp(argv[1], "top") == 0) {
0062         timerlat_top_main(argc-1, &argv[1]);
0063         exit(0);
0064     } else if (strcmp(argv[1], "hist") == 0) {
0065         timerlat_hist_main(argc-1, &argv[1]);
0066         exit(0);
0067     }
0068 
0069 usage:
0070     timerlat_usage();
0071     exit(1);
0072 }