trace-event-scripting.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * trace-event-scripting. Scripting engine common and initialization code.
  3. *
  4. * Copyright (C) 2009-2010 Tom Zanussi <tzanussi@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <errno.h>
  25. #include "../perf.h"
  26. #include "debug.h"
  27. #include "util.h"
  28. #include "trace-event.h"
  29. struct scripting_context *scripting_context;
  30. static int flush_script_unsupported(void)
  31. {
  32. return 0;
  33. }
  34. static int stop_script_unsupported(void)
  35. {
  36. return 0;
  37. }
  38. static void process_event_unsupported(union perf_event *event __maybe_unused,
  39. struct perf_sample *sample __maybe_unused,
  40. struct perf_evsel *evsel __maybe_unused,
  41. struct addr_location *al __maybe_unused)
  42. {
  43. }
  44. static void print_python_unsupported_msg(void)
  45. {
  46. fprintf(stderr, "Python scripting not supported."
  47. " Install libpython and rebuild perf to enable it.\n"
  48. "For example:\n # apt-get install python-dev (ubuntu)"
  49. "\n # yum install python-devel (Fedora)"
  50. "\n etc.\n");
  51. }
  52. static int python_start_script_unsupported(const char *script __maybe_unused,
  53. int argc __maybe_unused,
  54. const char **argv __maybe_unused)
  55. {
  56. print_python_unsupported_msg();
  57. return -1;
  58. }
  59. static int python_generate_script_unsupported(struct tep_handle *pevent
  60. __maybe_unused,
  61. const char *outfile
  62. __maybe_unused)
  63. {
  64. print_python_unsupported_msg();
  65. return -1;
  66. }
  67. struct scripting_ops python_scripting_unsupported_ops = {
  68. .name = "Python",
  69. .start_script = python_start_script_unsupported,
  70. .flush_script = flush_script_unsupported,
  71. .stop_script = stop_script_unsupported,
  72. .process_event = process_event_unsupported,
  73. .generate_script = python_generate_script_unsupported,
  74. };
  75. static void register_python_scripting(struct scripting_ops *scripting_ops)
  76. {
  77. if (scripting_context == NULL)
  78. scripting_context = malloc(sizeof(*scripting_context));
  79. if (scripting_context == NULL ||
  80. script_spec_register("Python", scripting_ops) ||
  81. script_spec_register("py", scripting_ops)) {
  82. pr_err("Error registering Python script extension: disabling it\n");
  83. zfree(&scripting_context);
  84. }
  85. }
  86. #ifndef HAVE_LIBPYTHON_SUPPORT
  87. void setup_python_scripting(void)
  88. {
  89. register_python_scripting(&python_scripting_unsupported_ops);
  90. }
  91. #else
  92. extern struct scripting_ops python_scripting_ops;
  93. void setup_python_scripting(void)
  94. {
  95. register_python_scripting(&python_scripting_ops);
  96. }
  97. #endif
  98. static void print_perl_unsupported_msg(void)
  99. {
  100. fprintf(stderr, "Perl scripting not supported."
  101. " Install libperl and rebuild perf to enable it.\n"
  102. "For example:\n # apt-get install libperl-dev (ubuntu)"
  103. "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
  104. "\n etc.\n");
  105. }
  106. static int perl_start_script_unsupported(const char *script __maybe_unused,
  107. int argc __maybe_unused,
  108. const char **argv __maybe_unused)
  109. {
  110. print_perl_unsupported_msg();
  111. return -1;
  112. }
  113. static int perl_generate_script_unsupported(struct tep_handle *pevent
  114. __maybe_unused,
  115. const char *outfile __maybe_unused)
  116. {
  117. print_perl_unsupported_msg();
  118. return -1;
  119. }
  120. struct scripting_ops perl_scripting_unsupported_ops = {
  121. .name = "Perl",
  122. .start_script = perl_start_script_unsupported,
  123. .flush_script = flush_script_unsupported,
  124. .stop_script = stop_script_unsupported,
  125. .process_event = process_event_unsupported,
  126. .generate_script = perl_generate_script_unsupported,
  127. };
  128. static void register_perl_scripting(struct scripting_ops *scripting_ops)
  129. {
  130. if (scripting_context == NULL)
  131. scripting_context = malloc(sizeof(*scripting_context));
  132. if (scripting_context == NULL ||
  133. script_spec_register("Perl", scripting_ops) ||
  134. script_spec_register("pl", scripting_ops)) {
  135. pr_err("Error registering Perl script extension: disabling it\n");
  136. zfree(&scripting_context);
  137. }
  138. }
  139. #ifndef HAVE_LIBPERL_SUPPORT
  140. void setup_perl_scripting(void)
  141. {
  142. register_perl_scripting(&perl_scripting_unsupported_ops);
  143. }
  144. #else
  145. extern struct scripting_ops perl_scripting_ops;
  146. void setup_perl_scripting(void)
  147. {
  148. register_perl_scripting(&perl_scripting_ops);
  149. }
  150. #endif