pystats.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef Py_PYSTATS_H
  2. #define Py_PYSTATS_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #ifdef Py_STATS
  7. #define SPECIALIZATION_FAILURE_KINDS 36
  8. /* Stats for determining who is calling PyEval_EvalFrame */
  9. #define EVAL_CALL_TOTAL 0
  10. #define EVAL_CALL_VECTOR 1
  11. #define EVAL_CALL_GENERATOR 2
  12. #define EVAL_CALL_LEGACY 3
  13. #define EVAL_CALL_FUNCTION_VECTORCALL 4
  14. #define EVAL_CALL_BUILD_CLASS 5
  15. #define EVAL_CALL_SLOT 6
  16. #define EVAL_CALL_FUNCTION_EX 7
  17. #define EVAL_CALL_API 8
  18. #define EVAL_CALL_METHOD 9
  19. #define EVAL_CALL_KINDS 10
  20. typedef struct _specialization_stats {
  21. uint64_t success;
  22. uint64_t failure;
  23. uint64_t hit;
  24. uint64_t deferred;
  25. uint64_t miss;
  26. uint64_t deopt;
  27. uint64_t failure_kinds[SPECIALIZATION_FAILURE_KINDS];
  28. } SpecializationStats;
  29. typedef struct _opcode_stats {
  30. SpecializationStats specialization;
  31. uint64_t execution_count;
  32. uint64_t pair_count[256];
  33. } OpcodeStats;
  34. typedef struct _call_stats {
  35. uint64_t inlined_py_calls;
  36. uint64_t pyeval_calls;
  37. uint64_t frames_pushed;
  38. uint64_t frame_objects_created;
  39. uint64_t eval_calls[EVAL_CALL_KINDS];
  40. } CallStats;
  41. typedef struct _object_stats {
  42. uint64_t increfs;
  43. uint64_t decrefs;
  44. uint64_t interpreter_increfs;
  45. uint64_t interpreter_decrefs;
  46. uint64_t allocations;
  47. uint64_t allocations512;
  48. uint64_t allocations4k;
  49. uint64_t allocations_big;
  50. uint64_t frees;
  51. uint64_t to_freelist;
  52. uint64_t from_freelist;
  53. uint64_t new_values;
  54. uint64_t dict_materialized_on_request;
  55. uint64_t dict_materialized_new_key;
  56. uint64_t dict_materialized_too_big;
  57. uint64_t dict_materialized_str_subclass;
  58. uint64_t type_cache_hits;
  59. uint64_t type_cache_misses;
  60. uint64_t type_cache_dunder_hits;
  61. uint64_t type_cache_dunder_misses;
  62. uint64_t type_cache_collisions;
  63. } ObjectStats;
  64. typedef struct _stats {
  65. OpcodeStats opcode_stats[256];
  66. CallStats call_stats;
  67. ObjectStats object_stats;
  68. } PyStats;
  69. PyAPI_DATA(PyStats) _py_stats_struct;
  70. PyAPI_DATA(PyStats *) _py_stats;
  71. extern void _Py_StatsClear(void);
  72. extern void _Py_PrintSpecializationStats(int to_file);
  73. #ifdef _PY_INTERPRETER
  74. #define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_increfs++; } while (0)
  75. #define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_decrefs++; } while (0)
  76. #else
  77. #define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.increfs++; } while (0)
  78. #define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.decrefs++; } while (0)
  79. #endif
  80. #else
  81. #define _Py_INCREF_STAT_INC() ((void)0)
  82. #define _Py_DECREF_STAT_INC() ((void)0)
  83. #endif // !Py_STATS
  84. #ifdef __cplusplus
  85. }
  86. #endif
  87. #endif /* !Py_PYSTATs_H */