builtin-version.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "builtin.h"
  3. #include "perf.h"
  4. #include "color.h"
  5. #include <tools/config.h>
  6. #include <stdbool.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. STATUS(HAVE_AIO_SUPPORT, aio);
  72. STATUS(HAVE_ZSTD_SUPPORT, zstd);
  73. }
  74. int cmd_version(int argc, const char **argv)
  75. {
  76. argc = parse_options(argc, argv, version_options, version_usage,
  77. PARSE_OPT_STOP_AT_NON_OPTION);
  78. printf("perf version %s\n", perf_version_string);
  79. if (version.build_options || version_verbose == 1)
  80. library_status();
  81. return 0;
  82. }