builtin-version.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. };
  19. static const char * const version_usage[] = {
  20. "perf version [<options>]",
  21. NULL
  22. };
  23. static void on_off_print(const char *status)
  24. {
  25. printf("[ ");
  26. if (!strcmp(status, "OFF"))
  27. color_fprintf(stdout, PERF_COLOR_RED, "%-3s", status);
  28. else
  29. color_fprintf(stdout, PERF_COLOR_GREEN, "%-3s", status);
  30. printf(" ]");
  31. }
  32. static void status_print(const char *name, const char *macro,
  33. const char *status)
  34. {
  35. printf("%22s: ", name);
  36. on_off_print(status);
  37. printf(" # %s\n", macro);
  38. }
  39. #define STATUS(__d, __m) \
  40. do { \
  41. if (IS_BUILTIN(__d)) \
  42. status_print(#__m, #__d, "on"); \
  43. else \
  44. status_print(#__m, #__d, "OFF"); \
  45. } while (0)
  46. static void library_status(void)
  47. {
  48. STATUS(HAVE_DWARF_SUPPORT, dwarf);
  49. STATUS(HAVE_DWARF_GETLOCATIONS_SUPPORT, dwarf_getlocations);
  50. STATUS(HAVE_GLIBC_SUPPORT, glibc);
  51. STATUS(HAVE_GTK2_SUPPORT, gtk2);
  52. #ifndef HAVE_SYSCALL_TABLE_SUPPORT
  53. STATUS(HAVE_LIBAUDIT_SUPPORT, libaudit);
  54. #endif
  55. STATUS(HAVE_SYSCALL_TABLE_SUPPORT, syscall_table);
  56. STATUS(HAVE_LIBBFD_SUPPORT, libbfd);
  57. STATUS(HAVE_LIBELF_SUPPORT, libelf);
  58. STATUS(HAVE_LIBNUMA_SUPPORT, libnuma);
  59. STATUS(HAVE_LIBNUMA_SUPPORT, numa_num_possible_cpus);
  60. STATUS(HAVE_LIBPERL_SUPPORT, libperl);
  61. STATUS(HAVE_LIBPYTHON_SUPPORT, libpython);
  62. STATUS(HAVE_SLANG_SUPPORT, libslang);
  63. STATUS(HAVE_LIBCRYPTO_SUPPORT, libcrypto);
  64. STATUS(HAVE_LIBUNWIND_SUPPORT, libunwind);
  65. STATUS(HAVE_DWARF_SUPPORT, libdw-dwarf-unwind);
  66. STATUS(HAVE_ZLIB_SUPPORT, zlib);
  67. STATUS(HAVE_LZMA_SUPPORT, lzma);
  68. STATUS(HAVE_AUXTRACE_SUPPORT, get_cpuid);
  69. STATUS(HAVE_LIBBPF_SUPPORT, bpf);
  70. }
  71. int cmd_version(int argc, const char **argv)
  72. {
  73. argc = parse_options(argc, argv, version_options, version_usage,
  74. PARSE_OPT_STOP_AT_NON_OPTION);
  75. printf("perf version %s\n", perf_version_string);
  76. if (version.build_options || version_verbose == 1)
  77. library_status();
  78. return 0;
  79. }