trace-event-scripting.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 <ctype.h>
  25. #include <errno.h>
  26. #include "../perf.h"
  27. #include "util.h"
  28. #include "trace-event.h"
  29. struct scripting_context *scripting_context;
  30. static int stop_script_unsupported(void)
  31. {
  32. return 0;
  33. }
  34. static void process_event_unsupported(union perf_event *event __unused,
  35. struct perf_sample *sample __unused,
  36. struct perf_evsel *evsel __unused,
  37. struct perf_session *session __unused,
  38. struct thread *thread __unused)
  39. {
  40. }
  41. static void print_python_unsupported_msg(void)
  42. {
  43. fprintf(stderr, "Python scripting not supported."
  44. " Install libpython and rebuild perf to enable it.\n"
  45. "For example:\n # apt-get install python-dev (ubuntu)"
  46. "\n # yum install python-devel (Fedora)"
  47. "\n etc.\n");
  48. }
  49. static int python_start_script_unsupported(const char *script __unused,
  50. int argc __unused,
  51. const char **argv __unused)
  52. {
  53. print_python_unsupported_msg();
  54. return -1;
  55. }
  56. static int python_generate_script_unsupported(const char *outfile __unused)
  57. {
  58. print_python_unsupported_msg();
  59. return -1;
  60. }
  61. struct scripting_ops python_scripting_unsupported_ops = {
  62. .name = "Python",
  63. .start_script = python_start_script_unsupported,
  64. .stop_script = stop_script_unsupported,
  65. .process_event = process_event_unsupported,
  66. .generate_script = python_generate_script_unsupported,
  67. };
  68. static void register_python_scripting(struct scripting_ops *scripting_ops)
  69. {
  70. int err;
  71. err = script_spec_register("Python", scripting_ops);
  72. if (err)
  73. die("error registering Python script extension");
  74. err = script_spec_register("py", scripting_ops);
  75. if (err)
  76. die("error registering py script extension");
  77. scripting_context = malloc(sizeof(struct scripting_context));
  78. }
  79. #ifdef NO_LIBPYTHON
  80. void setup_python_scripting(void)
  81. {
  82. register_python_scripting(&python_scripting_unsupported_ops);
  83. }
  84. #else
  85. extern struct scripting_ops python_scripting_ops;
  86. void setup_python_scripting(void)
  87. {
  88. register_python_scripting(&python_scripting_ops);
  89. }
  90. #endif
  91. static void print_perl_unsupported_msg(void)
  92. {
  93. fprintf(stderr, "Perl scripting not supported."
  94. " Install libperl and rebuild perf to enable it.\n"
  95. "For example:\n # apt-get install libperl-dev (ubuntu)"
  96. "\n # yum install 'perl(ExtUtils::Embed)' (Fedora)"
  97. "\n etc.\n");
  98. }
  99. static int perl_start_script_unsupported(const char *script __unused,
  100. int argc __unused,
  101. const char **argv __unused)
  102. {
  103. print_perl_unsupported_msg();
  104. return -1;
  105. }
  106. static int perl_generate_script_unsupported(const char *outfile __unused)
  107. {
  108. print_perl_unsupported_msg();
  109. return -1;
  110. }
  111. struct scripting_ops perl_scripting_unsupported_ops = {
  112. .name = "Perl",
  113. .start_script = perl_start_script_unsupported,
  114. .stop_script = stop_script_unsupported,
  115. .process_event = process_event_unsupported,
  116. .generate_script = perl_generate_script_unsupported,
  117. };
  118. static void register_perl_scripting(struct scripting_ops *scripting_ops)
  119. {
  120. int err;
  121. err = script_spec_register("Perl", scripting_ops);
  122. if (err)
  123. die("error registering Perl script extension");
  124. err = script_spec_register("pl", scripting_ops);
  125. if (err)
  126. die("error registering pl script extension");
  127. scripting_context = malloc(sizeof(struct scripting_context));
  128. }
  129. #ifdef NO_LIBPERL
  130. void setup_perl_scripting(void)
  131. {
  132. register_perl_scripting(&perl_scripting_unsupported_ops);
  133. }
  134. #else
  135. extern struct scripting_ops perl_scripting_ops;
  136. void setup_perl_scripting(void)
  137. {
  138. register_perl_scripting(&perl_scripting_ops);
  139. }
  140. #endif