~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/builtin-config.c

Version: ~ [ linux-5.9.1 ] ~ [ linux-5.8.16 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.72 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.152 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.202 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.240 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.240 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * builtin-config.c
  3  *
  4  * Copyright (C) 2015, Taeung Song <treeze.taeung@gmail.com>
  5  *
  6  */
  7 #include "builtin.h"
  8 
  9 #include "perf.h"
 10 
 11 #include "util/cache.h"
 12 #include <subcmd/parse-options.h>
 13 #include "util/util.h"
 14 #include "util/debug.h"
 15 
 16 static bool use_system_config, use_user_config;
 17 
 18 static const char * const config_usage[] = {
 19         "perf config [<file-option>] [options]",
 20         NULL
 21 };
 22 
 23 enum actions {
 24         ACTION_LIST = 1
 25 } actions;
 26 
 27 static struct option config_options[] = {
 28         OPT_SET_UINT('l', "list", &actions,
 29                      "show current config variables", ACTION_LIST),
 30         OPT_BOOLEAN(0, "system", &use_system_config, "use system config file"),
 31         OPT_BOOLEAN(0, "user", &use_user_config, "use user config file"),
 32         OPT_END()
 33 };
 34 
 35 static int show_config(const char *key, const char *value,
 36                        void *cb __maybe_unused)
 37 {
 38         if (value)
 39                 printf("%s=%s\n", key, value);
 40         else
 41                 printf("%s\n", key);
 42 
 43         return 0;
 44 }
 45 
 46 int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 47 {
 48         int ret = 0;
 49         char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
 50 
 51         argc = parse_options(argc, argv, config_options, config_usage,
 52                              PARSE_OPT_STOP_AT_NON_OPTION);
 53 
 54         if (use_system_config && use_user_config) {
 55                 pr_err("Error: only one config file at a time\n");
 56                 parse_options_usage(config_usage, config_options, "user", 0);
 57                 parse_options_usage(NULL, config_options, "system", 0);
 58                 return -1;
 59         }
 60 
 61         if (use_system_config)
 62                 config_exclusive_filename = perf_etc_perfconfig();
 63         else if (use_user_config)
 64                 config_exclusive_filename = user_config;
 65 
 66         switch (actions) {
 67         case ACTION_LIST:
 68                 if (argc) {
 69                         pr_err("Error: takes no arguments\n");
 70                         parse_options_usage(config_usage, config_options, "l", 1);
 71                 } else {
 72                         ret = perf_config(show_config, NULL);
 73                         if (ret < 0) {
 74                                 const char * config_filename = config_exclusive_filename;
 75                                 if (!config_exclusive_filename)
 76                                         config_filename = user_config;
 77                                 pr_err("Nothing configured, "
 78                                        "please check your %s \n", config_filename);
 79                         }
 80                 }
 81                 break;
 82         default:
 83                 usage_with_options(config_usage, config_options);
 84         }
 85 
 86         return ret;
 87 }
 88 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp