builtin-version.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "builtin.h"
  3. #include "perf.h"
  4. #include "color.h"
  5. #include <linux/compiler.h>
  6. #include <tools/config.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <subcmd/parse-options.h>
  10. int version_verbose;
  11. struct version {
  12. bool build_options;
  13. };
  14. static struct version version;
  15. static struct option version_options[] = {
  16. OPT_BOOLEAN(0, "build-options", &version.build_options,
  17. "display the build options"),
  18. OPT_END(),
  19. };
  20. static const char * const version_usage[] = {
  21. "perf version [<options>]",
  22. NULL
  23. };
  24. static void on_off_print(const char *status)
  25. {
  26. printf("[ ");
  27. if (!strcmp(status, "OFF"))
  28. color_fprintf(stdout, PERF_COLOR_RED, "%-3s", status);
  29. else
  30. color_fprintf(stdout, PERF_COLOR_GREEN, "%-3s", status);
  31. printf(" ]");
  32. }
  33. static void status_print(const char *name, const char *macro,
  34. const char *status)
  35. {
  36. printf("%22s: ", name);
  37. on_off_print(status);
  38. printf(" # %s\n", macro);
  39. }
  40. #define STATUS(__d, __m) \
  41. do { \
  42. if (IS_BUILTIN(__d)) \
  43. status_print(#__m, #__d, "on"); \
  44. else \
  45. status_print(#__m, #__d, "OFF"); \
  46. } while (0)
  47. static void library_status(void)
  48. {
  49. STATUS(HAVE_DWARF_SUPPORT, dwarf);
  50. STATUS(HAVE_DWARF_GETLOCATIONS_SUPPORT, dwarf_getlocations);
  51. STATUS(HAVE_GLIBC_SUPPORT, glibc);
  52. STATUS(HAVE_GTK2_SUPPORT, gtk2);
  53. #ifndef HAVE_SYSCALL_TABLE_SUPPORT
  54. STATUS(HAVE_LIBAUDIT_SUPPORT, libaudit);
  55. #endif
  56. STATUS(HAVE_SYSCALL_TABLE_SUPPORT, syscall_table);
  57. STATUS(HAVE_LIBBFD_SUPPORT, libbfd);
  58. STATUS(HAVE_LIBELF_SUPPORT, libelf);
  59. STATUS(HAVE_LIBNUMA_SUPPORT, libnuma);
  60. STATUS(HAVE_LIBNUMA_SUPPORT, numa_num_possible_cpus);
  61. STATUS(HAVE_LIBPERL_SUPPORT, libperl);
  62. STATUS(HAVE_LIBPYTHON_SUPPORT, libpython);
  63. STATUS(HAVE_SLANG_SUPPORT, libslang);
  64. STATUS(HAVE_LIBCRYPTO_SUPPORT, libcrypto);
  65. STATUS(HAVE_LIBUNWIND_SUPPORT, libunwind);
  66. STATUS(HAVE_DWARF_SUPPORT, libdw-dwarf-unwind);
  67. STATUS(HAVE_ZLIB_SUPPORT, zlib);
  68. STATUS(HAVE_LZMA_SUPPORT, lzma);
  69. STATUS(HAVE_AUXTRACE_SUPPORT, get_cpuid);
  70. STATUS(HAVE_LIBBPF_SUPPORT, bpf);
  71. }
  72. int cmd_version(int argc, const char **argv)
  73. {
  74. argc = parse_options(argc, argv, version_options, version_usage,
  75. PARSE_OPT_STOP_AT_NON_OPTION);
  76. printf("perf version %s\n", perf_version_string);
  77. if (version.build_options || version_verbose == 1)
  78. library_status();
  79. return 0;
  80. }