PageRenderTime 35ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/xdebug_trace_html.c

http://github.com/derickr/xdebug
C | 132 lines | 93 code | 22 blank | 17 comment | 5 complexity | 4fce0465298b4bbb8397570d485cbcc4 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Xdebug |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2002-2016 Derick Rethans |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 1.0 of the Xdebug license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available at through the world-wide-web at |
  10. | http://xdebug.derickrethans.nl/license.php |
  11. | If you did not receive a copy of the Xdebug license and are unable |
  12. | to obtain it through the world-wide-web, please send a note to |
  13. | xdebug@derickrethans.nl so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Derick Rethans <derick@xdebug.org> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #include "xdebug_trace_html.h"
  19. #include "xdebug_var.h"
  20. extern ZEND_DECLARE_MODULE_GLOBALS(xdebug);
  21. void *xdebug_trace_html_init(char *fname, long options TSRMLS_DC)
  22. {
  23. xdebug_trace_html_context *tmp_html_context;
  24. char *used_fname;
  25. tmp_html_context = xdmalloc(sizeof(xdebug_trace_html_context));
  26. tmp_html_context->trace_file = xdebug_trace_open_file(fname, options, (char**) &used_fname TSRMLS_CC);
  27. tmp_html_context->trace_filename = used_fname;
  28. return tmp_html_context->trace_file ? tmp_html_context : NULL;
  29. }
  30. void xdebug_trace_html_deinit(void *ctxt TSRMLS_DC)
  31. {
  32. xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt;
  33. fclose(context->trace_file);
  34. context->trace_file = NULL;
  35. xdfree(context->trace_filename);
  36. xdfree(context);
  37. }
  38. void xdebug_trace_html_write_header(void *ctxt TSRMLS_DC)
  39. {
  40. xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt;
  41. fprintf(context->trace_file, "<table class='xdebug-trace' dir='ltr' border='1' cellspacing='0'>\n");
  42. fprintf(context->trace_file, "\t<tr><th>#</th><th>Time</th>");
  43. fprintf(context->trace_file, "<th>Mem</th>");
  44. fprintf(context->trace_file, "<th colspan='2'>Function</th><th>Location</th></tr>\n");
  45. fflush(context->trace_file);
  46. }
  47. void xdebug_trace_html_write_footer(void *ctxt TSRMLS_DC)
  48. {
  49. xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt;
  50. fprintf(context->trace_file, "</table>\n");
  51. fflush(context->trace_file);
  52. }
  53. char *xdebug_trace_html_get_filename(void *ctxt TSRMLS_DC)
  54. {
  55. xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt;
  56. return context->trace_filename;
  57. }
  58. void xdebug_trace_html_function_entry(void *ctxt, function_stack_entry *fse, int function_nr TSRMLS_DC)
  59. {
  60. xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt;
  61. char *tmp_name;
  62. unsigned int j;
  63. xdebug_str str = XDEBUG_STR_INITIALIZER;
  64. xdebug_str_add(&str, "\t<tr>", 0);
  65. xdebug_str_add(&str, xdebug_sprintf("<td>%d</td>", function_nr), 1);
  66. xdebug_str_add(&str, xdebug_sprintf("<td>%0.6F</td>", fse->time - XG(start_time)), 1);
  67. xdebug_str_add(&str, xdebug_sprintf("<td align='right'>%lu</td>", fse->memory), 1);
  68. xdebug_str_add(&str, "<td align='left'>", 0);
  69. for (j = 0; j < fse->level - 1; j++) {
  70. xdebug_str_add(&str, "&nbsp; &nbsp;", 0);
  71. }
  72. xdebug_str_add(&str, "-&gt;</td>", 0);
  73. tmp_name = xdebug_show_fname(fse->function, 0, 0 TSRMLS_CC);
  74. xdebug_str_add(&str, xdebug_sprintf("<td>%s(", tmp_name), 1);
  75. xdfree(tmp_name);
  76. if (fse->include_filename) {
  77. if (fse->function.type == XFUNC_EVAL) {
  78. char *joined;
  79. xdebug_arg *parts = (xdebug_arg*) xdmalloc(sizeof(xdebug_arg));
  80. xdebug_arg_init(parts);
  81. xdebug_explode("\n", fse->include_filename, parts, 99999);
  82. joined = xdebug_join("<br />", parts, 0, 99999);
  83. xdebug_arg_dtor(parts);
  84. xdebug_str_add(&str, xdebug_sprintf("'%s'", joined), 1);
  85. xdfree(joined);
  86. } else {
  87. xdebug_str_add(&str, fse->include_filename, 0);
  88. }
  89. }
  90. xdebug_str_add(&str, xdebug_sprintf(")</td><td>%s:%d</td>", fse->filename, fse->lineno), 1);
  91. xdebug_str_add(&str, "</tr>\n", 0);
  92. fprintf(context->trace_file, "%s", str.d);
  93. fflush(context->trace_file);
  94. xdfree(str.d);
  95. }
  96. xdebug_trace_handler_t xdebug_trace_handler_html =
  97. {
  98. xdebug_trace_html_init,
  99. xdebug_trace_html_deinit,
  100. xdebug_trace_html_write_header,
  101. xdebug_trace_html_write_footer,
  102. xdebug_trace_html_get_filename,
  103. xdebug_trace_html_function_entry,
  104. NULL /* xdebug_trace_html_function_exit */,
  105. NULL /* xdebug_trace_html_function_return_value */,
  106. #if PHP_VERSION_ID >= 50500
  107. NULL /* xdebug_trace_html_generator_return_value */,
  108. #endif
  109. NULL /* xdebug_trace_html_assignment */
  110. };