il2cpp-runtime-stats.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #pragma once
  2. #include <atomic>
  3. #include <map>
  4. #include <stdint.h>
  5. struct Il2CppRuntimeStats
  6. {
  7. std::atomic<uint64_t> new_object_count;
  8. std::atomic<uint64_t> initialized_class_count;
  9. // uint64_t generic_vtable_count;
  10. // uint64_t used_class_count;
  11. std::atomic<uint64_t> method_count;
  12. // uint64_t class_vtable_size;
  13. std::atomic<uint64_t> class_static_data_size;
  14. std::atomic<uint64_t> generic_instance_count;
  15. std::atomic<uint64_t> generic_class_count;
  16. std::atomic<uint64_t> inflated_method_count;
  17. std::atomic<uint64_t> inflated_type_count;
  18. // uint64_t delegate_creations;
  19. // uint64_t minor_gc_count;
  20. // uint64_t major_gc_count;
  21. // uint64_t minor_gc_time_usecs;
  22. // uint64_t major_gc_time_usecs;
  23. std::atomic<uint64_t> hashtable_mem;
  24. std::atomic<uint64_t> global_metadata_file_size;
  25. bool enabled;
  26. };
  27. extern Il2CppRuntimeStats il2cpp_runtime_stats;
  28. typedef enum
  29. {
  30. IL2CPP_MSTAT_TYPE,
  31. IL2CPP_MSTAT_CLASS,
  32. IL2CPP_MSTAT_METHOD,
  33. IL2CPP_MSTAT_FIELD,
  34. IL2CPP_MSTAT_EVENT,
  35. IL2CPP_MSTAT_PROPERTY,
  36. IL2CPP_MSTAT_GENERIC_INST,
  37. IL2CPP_MSTAT_INTERFACE,
  38. IL2CPP_MSTAT_RGCTX,
  39. IL2CPP_MSTAT_COUNT
  40. } Il2CppMemStat;
  41. typedef enum {
  42. IL2CPP_MEM_META_POOL, //metadata_pool
  43. IL2CPP_MEM_HASH_TABLE,// hash used
  44. IL2CPP_MEM_FromTypeDefinition,
  45. IL2CPP_MEM_GLOBAL_METADATA,
  46. IL2CPP_MEM_MEMORY_MAP,
  47. IL2CPP_MEM_GC_HANDLE,
  48. IL2CPP_MEM_Cryptography,
  49. IL2CPP_MEM_il2cpp_alloc,
  50. IL2CPP_MEM_IMAGE,
  51. IL2CPP_MEM_STRING,
  52. IL2CPP_MEM_MonoGenericParameterInfo,
  53. IL2CPP_MEM_GatherMetadata,
  54. IL2CPP_MEM_THREAD,
  55. IL2CPP_MEM_DYNAMIC_ARRAY,
  56. IL2CPP_MEM_MonoAssemblyName,
  57. IL2CPP_MEM_RCW,
  58. IL2CPP_MEM_GPtrArray,
  59. IL2CPP_MEM_MonoMethodSignature,
  60. IL2CPP_MEM_MonoMethodHeader,
  61. IL2CPP_MEM_METADATA_CACHE,
  62. IL2CPP_MEM_CustomAttributesCache,
  63. IL2CPP_MEM_DomainData,
  64. IL2CPP_MEM_FindHandle,
  65. IL2CPP_MEM_OS_ALLOCATOR,
  66. IL2CPP_MEM_WeakReference,
  67. IL2CPP_MEM_ActivationFactory,
  68. IL2CPP_MEM_ManagedObject,
  69. IL2CPP_MEM_CpuUsageState,
  70. IL2CPP_MEM_Socket,
  71. IL2CPP_MEM_CustomAttribute,
  72. IL2CPP_MEM_GC,
  73. IL2CPP_MEM_MonoDebugLocalsInfo,
  74. IL2CPP_MEM_DEBUGGER,
  75. IL2CPP_MEM_LABLE_COUNT,
  76. } Il2CppMemLabel;
  77. #if IL2CPP_ENABLE_MEM_STATS
  78. //don't use std::atomic because assuming it's proteced by g_MetadataLock
  79. struct Il2CppMetaMemStats {
  80. std::size_t meta_total; // total usage through MetadataAlloc
  81. std::size_t meta_wasted; // wasted mem in MetadataAlloc pools
  82. std::size_t meta_region_count;
  83. std::size_t generic_class_count;
  84. std::size_t generic_class_size;
  85. std::size_t generic_method_count;
  86. std::size_t generic_method_size;
  87. std::size_t sizes[IL2CPP_MSTAT_COUNT];
  88. };
  89. struct Il2CppMemStats {
  90. //typedef std::atomic<uint64_t> size_t;
  91. std::size_t il2cpp_malloc;// total usage from IL2CPP_MALLOC
  92. Il2CppMetaMemStats meta;
  93. std::size_t hash_table; //Note: only add malloc and realloc, no free
  94. //Other --------------
  95. std::size_t classFromTypeDef_count;
  96. std::size_t globalMetadataMapfile; //global-metadata.dat map file size
  97. std::size_t interal_calls_total; // s_InternalCalls count
  98. std::size_t interal_calls_resolved;// s_InternalCalls resolved
  99. std::size_t lableSizes[IL2CPP_MEM_LABLE_COUNT];
  100. };
  101. extern Il2CppMemStats il2cpp_mem_stats;
  102. extern const char* g_Il2CppMemLabelName[IL2CPP_MEM_LABLE_COUNT];
  103. // use static object to avoid globel variable init order issue.
  104. std::map<void*, size_t>& GetAllocMap();
  105. std::map<void*, size_t>& GetHashAllocMap();
  106. void mem_stats_add_on_label(Il2CppMemStat label, std::size_t s);
  107. #endif //IL2CPP_ENABLE_MEM_STATS