builtin-config.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * builtin-config.c
  3. *
  4. * Copyright (C) 2015, Taeung Song <treeze.taeung@gmail.com>
  5. *
  6. */
  7. #include "builtin.h"
  8. #include "perf.h"
  9. #include "util/cache.h"
  10. #include <subcmd/parse-options.h>
  11. #include "util/util.h"
  12. #include "util/debug.h"
  13. static const char * const config_usage[] = {
  14. "perf config [options]",
  15. NULL
  16. };
  17. enum actions {
  18. ACTION_LIST = 1
  19. } actions;
  20. static struct option config_options[] = {
  21. OPT_SET_UINT('l', "list", &actions,
  22. "show current config variables", ACTION_LIST),
  23. OPT_END()
  24. };
  25. static int show_config(const char *key, const char *value,
  26. void *cb __maybe_unused)
  27. {
  28. if (value)
  29. printf("%s=%s\n", key, value);
  30. else
  31. printf("%s\n", key);
  32. return 0;
  33. }
  34. int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
  35. {
  36. int ret = 0;
  37. argc = parse_options(argc, argv, config_options, config_usage,
  38. PARSE_OPT_STOP_AT_NON_OPTION);
  39. switch (actions) {
  40. case ACTION_LIST:
  41. if (argc) {
  42. pr_err("Error: takes no arguments\n");
  43. parse_options_usage(config_usage, config_options, "l", 1);
  44. } else {
  45. ret = perf_config(show_config, NULL);
  46. if (ret < 0)
  47. pr_err("Nothing configured, "
  48. "please check your ~/.perfconfig file\n");
  49. }
  50. break;
  51. default:
  52. usage_with_options(config_usage, config_options);
  53. }
  54. return ret;
  55. }