mono-counters.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * \file
  3. */
  4. #ifndef __MONO_COUNTERS_H__
  5. #define __MONO_COUNTERS_H__
  6. #include <stdio.h>
  7. #include <mono/utils/mono-publib.h>
  8. enum {
  9. /* Counter type, bits 0-7. */
  10. MONO_COUNTER_INT, /* 32 bit int */
  11. MONO_COUNTER_UINT, /* 32 bit uint */
  12. MONO_COUNTER_WORD, /* pointer-sized int */
  13. MONO_COUNTER_LONG, /* 64 bit int */
  14. MONO_COUNTER_ULONG, /* 64 bit uint */
  15. MONO_COUNTER_DOUBLE,
  16. MONO_COUNTER_STRING, /* char* */
  17. MONO_COUNTER_TIME_INTERVAL, /* 64 bits signed int holding usecs. */
  18. MONO_COUNTER_TYPE_MASK = 0xf,
  19. MONO_COUNTER_CALLBACK = 128, /* ORed with the other values */
  20. MONO_COUNTER_SECTION_MASK = 0x00ffff00,
  21. /* Sections, bits 8-23 (16 bits) */
  22. MONO_COUNTER_JIT = 1 << 8,
  23. MONO_COUNTER_GC = 1 << 9,
  24. MONO_COUNTER_METADATA = 1 << 10,
  25. MONO_COUNTER_GENERICS = 1 << 11,
  26. MONO_COUNTER_SECURITY = 1 << 12,
  27. MONO_COUNTER_RUNTIME = 1 << 13,
  28. MONO_COUNTER_SYSTEM = 1 << 14,
  29. MONO_COUNTER_PERFCOUNTERS = 1 << 15,
  30. MONO_COUNTER_PROFILER = 1 << 16,
  31. MONO_COUNTER_INTERP = 1 << 17,
  32. MONO_COUNTER_TIERED = 1 << 18,
  33. MONO_COUNTER_LAST_SECTION,
  34. /* Unit, bits 24-27 (4 bits) */
  35. MONO_COUNTER_UNIT_SHIFT = 24,
  36. MONO_COUNTER_UNIT_MASK = 0xFu << MONO_COUNTER_UNIT_SHIFT,
  37. MONO_COUNTER_RAW = 0 << 24, /* Raw value */
  38. MONO_COUNTER_BYTES = 1 << 24, /* Quantity of bytes. RSS, active heap, etc */
  39. MONO_COUNTER_TIME = 2 << 24, /* Time interval in 100ns units. Minor pause, JIT compilation*/
  40. MONO_COUNTER_COUNT = 3 << 24, /* Number of things (threads, queued jobs) or Number of events triggered (Major collections, Compiled methods).*/
  41. MONO_COUNTER_PERCENTAGE = 4 << 24, /* [0-1] Fraction Percentage of something. Load average. */
  42. /* Monotonicity, bits 28-31 (4 bits) */
  43. MONO_COUNTER_VARIANCE_SHIFT = 28,
  44. MONO_COUNTER_VARIANCE_MASK = 0xFu << MONO_COUNTER_VARIANCE_SHIFT,
  45. MONO_COUNTER_MONOTONIC = 1 << 28, /* This counter value always increase/decreases over time. Reported by --stat. */
  46. MONO_COUNTER_CONSTANT = 1 << 29, /* Fixed value. Used by configuration data. */
  47. MONO_COUNTER_VARIABLE = 1 << 30, /* This counter value can be anything on each sampling. Only interesting when sampling. */
  48. };
  49. typedef struct _MonoCounter MonoCounter;
  50. MONO_API void mono_counters_enable (int section_mask);
  51. MONO_API void mono_counters_init (void);
  52. /*
  53. * register addr as the address of a counter of type type.
  54. * It may be a function pointer if MONO_COUNTER_CALLBACK is specified:
  55. * the function should return the value and take no arguments.
  56. */
  57. MONO_API void mono_counters_register (const char* descr, int type, void *addr);
  58. MONO_API void mono_counters_register_with_size (const char *name, int type, void *addr, int size);
  59. typedef void (*MonoCounterRegisterCallback) (MonoCounter*);
  60. MONO_API void mono_counters_on_register (MonoCounterRegisterCallback callback);
  61. /*
  62. * Create a readable dump of the counters for section_mask sections (ORed section values)
  63. */
  64. MONO_API void mono_counters_dump (int section_mask, FILE *outfile);
  65. MONO_API void mono_counters_cleanup (void);
  66. typedef mono_bool (*CountersEnumCallback) (MonoCounter *counter, void *user_data);
  67. MONO_API void mono_counters_foreach (CountersEnumCallback cb, void *user_data);
  68. MONO_API int mono_counters_sample (MonoCounter *counter, void *buffer, int buffer_size);
  69. MONO_API const char* mono_counter_get_name (MonoCounter *name);
  70. MONO_API int mono_counter_get_type (MonoCounter *counter);
  71. MONO_API int mono_counter_get_section (MonoCounter *counter);
  72. MONO_API int mono_counter_get_unit (MonoCounter *counter);
  73. MONO_API int mono_counter_get_variance (MonoCounter *counter);
  74. MONO_API size_t mono_counter_get_size (MonoCounter *counter);
  75. typedef enum {
  76. MONO_RESOURCE_JIT_CODE, /* bytes */
  77. MONO_RESOURCE_METADATA, /* bytes */
  78. MONO_RESOURCE_GC_HEAP, /* bytes */
  79. MONO_RESOURCE_COUNT /* non-ABI value */
  80. } MonoResourceType;
  81. typedef void (*MonoResourceCallback) (int resource_type, uintptr_t value, int is_soft);
  82. MONO_API int mono_runtime_resource_limit (int resource_type, uintptr_t soft_limit, uintptr_t hard_limit);
  83. MONO_API void mono_runtime_resource_set_callback (MonoResourceCallback callback);
  84. MONO_API void mono_runtime_resource_check_limit (int resource_type, uintptr_t value);
  85. #endif /* __MONO_COUNTERS_H__ */