XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.4 KiB

  1. #! /usr/bin/php
  2. <?php
  3. $srcdir = dirname(__FILE__);
  4. if (file_exists("$srcdir/phpdc.debug.php")) {
  5. include("$srcdir/phpdc.debug.php");
  6. }
  7. function get_op($op)
  8. {
  9. switch ($op['op_type']) {
  10. case 1: // CONST
  11. return var_export($op['u.constant'], true);
  12. case 2: // IS_TMP_VAR
  13. return 't@' . $op['u.var'];
  14. case 4:
  15. return 'v$' . $op['u.var'];
  16. case 8: // UNUSED
  17. if (isset($op['u.opline_num'])) {
  18. return 'l#' . $op['u.opline_num'];
  19. }
  20. else {
  21. return '-';
  22. }
  23. default:
  24. return $op['op_type'] . $op['u.var'];
  25. }
  26. }
  27. function dump_opcodes($op_array, $indent = '')
  28. {
  29. $types = array('result' => 5, 'op1' => 20, 'op2' => 20);
  30. foreach ($op_array as $line => $op) {
  31. echo $indent;
  32. echo sprintf("%3d ", $op['lineno']);
  33. echo sprintf("%3x ", $line);
  34. $name = xcache_get_opcode($op['opcode']);
  35. if (substr($name, 0, 5) == 'ZEND_') {
  36. $name = substr($name, 5);
  37. }
  38. echo str_pad($name, 25);
  39. foreach ($types as $t => $len) {
  40. echo str_pad(isset($op[$t]) ? get_op($op[$t]) : "", $len);
  41. }
  42. printf("%5s", isset($op['extended_value']) ? $op['extended_value'] : "");
  43. echo "\n";
  44. }
  45. }
  46. function dump_function($name, $func, $indent = '')
  47. {
  48. if (isset($func['op_array'])) {
  49. $op_array = $func['op_array'];
  50. unset($func['op_array']);
  51. }
  52. else {
  53. $op_array = null;
  54. }
  55. var_dump($func);
  56. echo $indent, 'function ', $name, "\n";
  57. if (isset($op_array)) {
  58. dump_opcodes($op_array['opcodes'], " " . $indent);
  59. }
  60. }
  61. function dump_class($name, $class, $indent = '')
  62. {
  63. if (isset($class['function_table'])) {
  64. $funcs = $class['function_table'];
  65. unset($class['function_table']);
  66. }
  67. else {
  68. $funcs = null;
  69. }
  70. echo $indent, 'class ', $name, "\n";
  71. if (isset($funcs)) {
  72. foreach ($funcs as $name => $func) {
  73. dump_function($name, $func, " " . $indent);
  74. }
  75. }
  76. }
  77. $pk = xcache_dasm_file($argv[1]);
  78. $op_array = $funcs = $classes = null;
  79. if (isset($pk['op_array'])) {
  80. $op_array = $pk['op_array'];
  81. unset($pk['op_array']);
  82. }
  83. if (isset($pk['function_table'])) {
  84. $funcs = $pk['function_table'];
  85. unset($pk['function_table']);
  86. }
  87. if (isset($pk['class_table'])) {
  88. $classes = $pk['class_table'];
  89. unset($pk['class_table']);
  90. }
  91. var_dump($pk);
  92. if (isset($op_array)) {
  93. dump_opcodes($op_array['opcodes']);
  94. }
  95. if (isset($funcs)) {
  96. foreach ($funcs as $name => $func) {
  97. dump_function($name, $func);
  98. }
  99. }
  100. if (isset($classes)) {
  101. foreach ($classes as $name => $class) {
  102. dump_class($name, $class);
  103. }
  104. }