zend_dtrace.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2009 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: David Soria Parra <david.soriaparra@sun.com> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id: $ */
  19. #include "zend.h"
  20. #include "zend_API.h"
  21. #include "zend_dtrace.h"
  22. #ifdef HAVE_DTRACE
  23. /* PHP DTrace probes {{{ */
  24. static inline const char *dtrace_get_executed_filename(TSRMLS_D)
  25. {
  26. if (EG(current_execute_data) && EG(current_execute_data)->op_array) {
  27. return EG(current_execute_data)->op_array->filename;
  28. } else {
  29. return zend_get_executed_filename(TSRMLS_C);
  30. }
  31. }
  32. ZEND_API zend_op_array *dtrace_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC)
  33. {
  34. zend_op_array *res;
  35. DTRACE_COMPILE_FILE_ENTRY(file_handle->opened_path, (char *)file_handle->filename);
  36. res = compile_file(file_handle, type TSRMLS_CC);
  37. DTRACE_COMPILE_FILE_RETURN(file_handle->opened_path, (char *)file_handle->filename);
  38. return res;
  39. }
  40. /* We wrap the execute function to have fire the execute-entry/return and function-entry/return probes */
  41. ZEND_API void dtrace_execute_ex(zend_execute_data *execute_data TSRMLS_DC)
  42. {
  43. int lineno;
  44. const char *scope, *filename, *funcname, *classname;
  45. scope = filename = funcname = classname = NULL;
  46. /* we need filename and lineno for both execute and function probes */
  47. if (DTRACE_EXECUTE_ENTRY_ENABLED() || DTRACE_EXECUTE_RETURN_ENABLED()
  48. || DTRACE_FUNCTION_ENTRY_ENABLED() || DTRACE_FUNCTION_RETURN_ENABLED()) {
  49. filename = dtrace_get_executed_filename(TSRMLS_C);
  50. lineno = zend_get_executed_lineno(TSRMLS_C);
  51. }
  52. if (DTRACE_FUNCTION_ENTRY_ENABLED() || DTRACE_FUNCTION_RETURN_ENABLED()) {
  53. classname = get_active_class_name(&scope TSRMLS_CC);
  54. funcname = get_active_function_name(TSRMLS_C);
  55. }
  56. if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
  57. DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
  58. }
  59. if (DTRACE_FUNCTION_ENTRY_ENABLED() && funcname != NULL) {
  60. DTRACE_FUNCTION_ENTRY((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
  61. }
  62. execute_ex(execute_data TSRMLS_CC);
  63. if (DTRACE_FUNCTION_RETURN_ENABLED() && funcname != NULL) {
  64. DTRACE_FUNCTION_RETURN((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
  65. }
  66. if (DTRACE_EXECUTE_RETURN_ENABLED()) {
  67. DTRACE_EXECUTE_RETURN((char *)filename, lineno);
  68. }
  69. }
  70. ZEND_API void dtrace_execute_internal(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC)
  71. {
  72. int lineno;
  73. const char *filename;
  74. if (DTRACE_EXECUTE_ENTRY_ENABLED() || DTRACE_EXECUTE_RETURN_ENABLED()) {
  75. filename = dtrace_get_executed_filename(TSRMLS_C);
  76. lineno = zend_get_executed_lineno(TSRMLS_C);
  77. }
  78. if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
  79. DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
  80. }
  81. execute_internal(execute_data_ptr, fci, return_value_used TSRMLS_CC);
  82. if (DTRACE_EXECUTE_RETURN_ENABLED()) {
  83. DTRACE_EXECUTE_RETURN((char *)filename, lineno);
  84. }
  85. }
  86. /* }}} */
  87. #endif /* HAVE_DTRACE */