@shd101wyy/yo 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +80 -0
  3. package/out/cjs/index.cjs +51 -0
  4. package/out/cjs/yo-cli.cjs +2158 -0
  5. package/out/esm/index.mjs +51 -0
  6. package/out/types/src/codegen/async/runtime.d.ts +2 -0
  7. package/out/types/src/codegen/async/state-code-gen.d.ts +10 -0
  8. package/out/types/src/codegen/async/state-machine.d.ts +13 -0
  9. package/out/types/src/codegen/c/collection.d.ts +3 -0
  10. package/out/types/src/codegen/codegen-c.d.ts +12 -0
  11. package/out/types/src/codegen/constants.d.ts +3 -0
  12. package/out/types/src/codegen/expressions/array.d.ts +4 -0
  13. package/out/types/src/codegen/expressions/generation.d.ts +11 -0
  14. package/out/types/src/codegen/expressions/index.d.ts +2 -0
  15. package/out/types/src/codegen/functions/collection.d.ts +5 -0
  16. package/out/types/src/codegen/functions/context.d.ts +57 -0
  17. package/out/types/src/codegen/functions/generation.d.ts +25 -0
  18. package/out/types/src/codegen/functions/index.d.ts +2 -0
  19. package/out/types/src/codegen/index.d.ts +20 -0
  20. package/out/types/src/codegen/parallelism/runtime.d.ts +2 -0
  21. package/out/types/src/codegen/types/collection.d.ts +8 -0
  22. package/out/types/src/codegen/types/generation.d.ts +13 -0
  23. package/out/types/src/codegen/types/index.d.ts +2 -0
  24. package/out/types/src/codegen/utils/fixup.d.ts +2 -0
  25. package/out/types/src/codegen/utils/index.d.ts +77 -0
  26. package/out/types/src/codegen/values/index.d.ts +1 -0
  27. package/out/types/src/emitter.d.ts +11 -0
  28. package/out/types/src/env.d.ts +85 -0
  29. package/out/types/src/error.d.ts +45 -0
  30. package/out/types/src/evaluator/async/await-analysis-types.d.ts +23 -0
  31. package/out/types/src/evaluator/async/await-analysis.d.ts +5 -0
  32. package/out/types/src/evaluator/builtins/alignof.d.ts +8 -0
  33. package/out/types/src/evaluator/builtins/and_or.d.ts +8 -0
  34. package/out/types/src/evaluator/builtins/arc_fns.d.ts +58 -0
  35. package/out/types/src/evaluator/builtins/array_fns.d.ts +0 -0
  36. package/out/types/src/evaluator/builtins/as.d.ts +8 -0
  37. package/out/types/src/evaluator/builtins/async_fns.d.ts +8 -0
  38. package/out/types/src/evaluator/builtins/compt_assert.d.ts +8 -0
  39. package/out/types/src/evaluator/builtins/compt_boolean_fns.d.ts +8 -0
  40. package/out/types/src/evaluator/builtins/compt_expect_error.d.ts +8 -0
  41. package/out/types/src/evaluator/builtins/compt_list_fns.d.ts +33 -0
  42. package/out/types/src/evaluator/builtins/compt_print.d.ts +8 -0
  43. package/out/types/src/evaluator/builtins/compt_string_fns.d.ts +8 -0
  44. package/out/types/src/evaluator/builtins/consume.d.ts +8 -0
  45. package/out/types/src/evaluator/builtins/drop.d.ts +8 -0
  46. package/out/types/src/evaluator/builtins/dup.d.ts +8 -0
  47. package/out/types/src/evaluator/builtins/expr_fns.d.ts +33 -0
  48. package/out/types/src/evaluator/builtins/future_fns.d.ts +8 -0
  49. package/out/types/src/evaluator/builtins/gc.d.ts +8 -0
  50. package/out/types/src/evaluator/builtins/gensym.d.ts +8 -0
  51. package/out/types/src/evaluator/builtins/impl_constraint.d.ts +8 -0
  52. package/out/types/src/evaluator/builtins/macro_expand.d.ts +8 -0
  53. package/out/types/src/evaluator/builtins/numeric_fns.d.ts +8 -0
  54. package/out/types/src/evaluator/builtins/panic.d.ts +8 -0
  55. package/out/types/src/evaluator/builtins/ptr_fns.d.ts +8 -0
  56. package/out/types/src/evaluator/builtins/quote.d.ts +13 -0
  57. package/out/types/src/evaluator/builtins/rc.d.ts +8 -0
  58. package/out/types/src/evaluator/builtins/sizeof.d.ts +8 -0
  59. package/out/types/src/evaluator/builtins/the.d.ts +8 -0
  60. package/out/types/src/evaluator/builtins/type_fns.d.ts +28 -0
  61. package/out/types/src/evaluator/builtins/va_start.d.ts +8 -0
  62. package/out/types/src/evaluator/builtins/var_fns.d.ts +18 -0
  63. package/out/types/src/evaluator/calls/array.d.ts +13 -0
  64. package/out/types/src/evaluator/calls/array_type.d.ts +11 -0
  65. package/out/types/src/evaluator/calls/closure_type.d.ts +11 -0
  66. package/out/types/src/evaluator/calls/compt_function.d.ts +19 -0
  67. package/out/types/src/evaluator/calls/compt_list_type.d.ts +11 -0
  68. package/out/types/src/evaluator/calls/function.d.ts +16 -0
  69. package/out/types/src/evaluator/calls/function_type.d.ts +15 -0
  70. package/out/types/src/evaluator/calls/helper.d.ts +42 -0
  71. package/out/types/src/evaluator/calls/iso.d.ts +15 -0
  72. package/out/types/src/evaluator/calls/module_type.d.ts +11 -0
  73. package/out/types/src/evaluator/calls/numeric_type.d.ts +15 -0
  74. package/out/types/src/evaluator/calls/pointer.d.ts +8 -0
  75. package/out/types/src/evaluator/calls/pointer_type.d.ts +14 -0
  76. package/out/types/src/evaluator/calls/type.d.ts +12 -0
  77. package/out/types/src/evaluator/context.d.ts +169 -0
  78. package/out/types/src/evaluator/exprs/_expr.d.ts +8 -0
  79. package/out/types/src/evaluator/exprs/assignment.d.ts +9 -0
  80. package/out/types/src/evaluator/exprs/begin.d.ts +10 -0
  81. package/out/types/src/evaluator/exprs/binding.d.ts +12 -0
  82. package/out/types/src/evaluator/exprs/c_include.d.ts +8 -0
  83. package/out/types/src/evaluator/exprs/cond.d.ts +8 -0
  84. package/out/types/src/evaluator/exprs/destructuring_assignment.d.ts +33 -0
  85. package/out/types/src/evaluator/exprs/exists.d.ts +0 -0
  86. package/out/types/src/evaluator/exprs/expr.d.ts +9 -0
  87. package/out/types/src/evaluator/exprs/extern.d.ts +8 -0
  88. package/out/types/src/evaluator/exprs/identifer_and_operator.d.ts +9 -0
  89. package/out/types/src/evaluator/exprs/import.d.ts +9 -0
  90. package/out/types/src/evaluator/exprs/initialization_assignment.d.ts +8 -0
  91. package/out/types/src/evaluator/exprs/match.d.ts +8 -0
  92. package/out/types/src/evaluator/exprs/open.d.ts +8 -0
  93. package/out/types/src/evaluator/exprs/property_access.d.ts +8 -0
  94. package/out/types/src/evaluator/exprs/recur.d.ts +8 -0
  95. package/out/types/src/evaluator/exprs/subtype_of.d.ts +21 -0
  96. package/out/types/src/evaluator/exprs/test.d.ts +8 -0
  97. package/out/types/src/evaluator/exprs/typeof.d.ts +8 -0
  98. package/out/types/src/evaluator/exprs/while.d.ts +8 -0
  99. package/out/types/src/evaluator/index.d.ts +26 -0
  100. package/out/types/src/evaluator/types/array.d.ts +8 -0
  101. package/out/types/src/evaluator/types/closure.d.ts +8 -0
  102. package/out/types/src/evaluator/types/compt_list.d.ts +8 -0
  103. package/out/types/src/evaluator/types/concrete_module.d.ts +8 -0
  104. package/out/types/src/evaluator/types/dyn.d.ts +8 -0
  105. package/out/types/src/evaluator/types/enum.d.ts +8 -0
  106. package/out/types/src/evaluator/types/expr_synthesizer.d.ts +14 -0
  107. package/out/types/src/evaluator/types/field.d.ts +14 -0
  108. package/out/types/src/evaluator/types/fn_module.d.ts +8 -0
  109. package/out/types/src/evaluator/types/function.d.ts +58 -0
  110. package/out/types/src/evaluator/types/future_module.d.ts +8 -0
  111. package/out/types/src/evaluator/types/module.d.ts +19 -0
  112. package/out/types/src/evaluator/types/newtype.d.ts +8 -0
  113. package/out/types/src/evaluator/types/object.d.ts +8 -0
  114. package/out/types/src/evaluator/types/proofs.d.ts +0 -0
  115. package/out/types/src/evaluator/types/slice.d.ts +8 -0
  116. package/out/types/src/evaluator/types/struct.d.ts +8 -0
  117. package/out/types/src/evaluator/types/synthesizer.d.ts +16 -0
  118. package/out/types/src/evaluator/types/tuple.d.ts +18 -0
  119. package/out/types/src/evaluator/types/union.d.ts +8 -0
  120. package/out/types/src/evaluator/types/utils.d.ts +71 -0
  121. package/out/types/src/evaluator/types/validation.d.ts +3 -0
  122. package/out/types/src/evaluator/utils/array-utils.d.ts +15 -0
  123. package/out/types/src/evaluator/utils/closure.d.ts +35 -0
  124. package/out/types/src/evaluator/utils.d.ts +4 -0
  125. package/out/types/src/evaluator/values/anonymous_function.d.ts +8 -0
  126. package/out/types/src/evaluator/values/anonymous_module.d.ts +17 -0
  127. package/out/types/src/evaluator/values/anonymous_struct.d.ts +8 -0
  128. package/out/types/src/evaluator/values/array.d.ts +8 -0
  129. package/out/types/src/evaluator/values/boolean.d.ts +3 -0
  130. package/out/types/src/evaluator/values/char.d.ts +3 -0
  131. package/out/types/src/evaluator/values/compt_list.d.ts +8 -0
  132. package/out/types/src/evaluator/values/dyn.d.ts +8 -0
  133. package/out/types/src/evaluator/values/float.d.ts +4 -0
  134. package/out/types/src/evaluator/values/integer.d.ts +4 -0
  135. package/out/types/src/evaluator/values/module.d.ts +58 -0
  136. package/out/types/src/evaluator/values/string.d.ts +3 -0
  137. package/out/types/src/evaluator/values/tuple.d.ts +32 -0
  138. package/out/types/src/expr.d.ts +456 -0
  139. package/out/types/src/function-value.d.ts +42 -0
  140. package/out/types/src/index.d.ts +4 -0
  141. package/out/types/src/lexer.d.ts +2 -0
  142. package/out/types/src/logger.d.ts +1 -0
  143. package/out/types/src/module-manager.d.ts +30 -0
  144. package/out/types/src/naming-checker.d.ts +4 -0
  145. package/out/types/src/parser.d.ts +33 -0
  146. package/out/types/src/test-runner.d.ts +30 -0
  147. package/out/types/src/tests/codegen.test.d.ts +1 -0
  148. package/out/types/src/tests/fixme.test.d.ts +1 -0
  149. package/out/types/src/tests/module-manager.test.d.ts +1 -0
  150. package/out/types/src/tests/parser.test.d.ts +1 -0
  151. package/out/types/src/tests/sample.test.d.ts +0 -0
  152. package/out/types/src/tests/std.test.d.ts +1 -0
  153. package/out/types/src/token.d.ts +40 -0
  154. package/out/types/src/type-value.d.ts +7 -0
  155. package/out/types/src/types/compatibility.d.ts +16 -0
  156. package/out/types/src/types/creators.d.ts +73 -0
  157. package/out/types/src/types/definitions.d.ts +218 -0
  158. package/out/types/src/types/guards.d.ts +70 -0
  159. package/out/types/src/types/hierarchy.d.ts +4 -0
  160. package/out/types/src/types/index.d.ts +7 -0
  161. package/out/types/src/types/module_field.d.ts +2 -0
  162. package/out/types/src/types/tags.d.ts +45 -0
  163. package/out/types/src/types/utils.d.ts +50 -0
  164. package/out/types/src/unit-value.d.ts +7 -0
  165. package/out/types/src/utils.d.ts +6 -0
  166. package/out/types/src/value-tag.d.ts +29 -0
  167. package/out/types/src/value.d.ts +110 -0
  168. package/out/types/src/yo-cli.d.ts +1 -0
  169. package/out/types/tsconfig.tsbuildinfo +1 -0
  170. package/package.json +57 -0
  171. package/scripts/check-liburing.js +76 -0
  172. package/std/alg/hash.yo +50 -0
  173. package/std/allocator.yo +113 -0
  174. package/std/allocators/c_allocator.yo +118 -0
  175. package/std/async.yo +13 -0
  176. package/std/collections/array_list.yo +415 -0
  177. package/std/collections/hash_map.yo +482 -0
  178. package/std/collections/hash_set.yo +706 -0
  179. package/std/collections/index.yo +11 -0
  180. package/std/collections/linked_list.yo +439 -0
  181. package/std/error.yo +0 -0
  182. package/std/gc.yo +10 -0
  183. package/std/index.yo +12 -0
  184. package/std/io/file.yo +191 -0
  185. package/std/io/index.yo +5 -0
  186. package/std/libc/assert.yo +39 -0
  187. package/std/libc/ctype.yo +57 -0
  188. package/std/libc/errno.yo +182 -0
  189. package/std/libc/float.yo +87 -0
  190. package/std/libc/index.yo +29 -0
  191. package/std/libc/limits.yo +65 -0
  192. package/std/libc/math.yo +679 -0
  193. package/std/libc/signal.yo +101 -0
  194. package/std/libc/stdatomic.yo +213 -0
  195. package/std/libc/stdint.yo +214 -0
  196. package/std/libc/stdio.yo +225 -0
  197. package/std/libc/stdlib.yo +204 -0
  198. package/std/libc/string.yo +151 -0
  199. package/std/libc/time.yo +92 -0
  200. package/std/libc/unistd.yo +130 -0
  201. package/std/monad.yo +152 -0
  202. package/std/prelude.yo +3094 -0
  203. package/std/string/index.yo +8 -0
  204. package/std/string/rune.yo +82 -0
  205. package/std/string/string.yo +288 -0
  206. package/std/sync.yo +95 -0
  207. package/std/thread.yo +36 -0
  208. package/std/time.yo +13 -0
  209. package/std/worker.yo +36 -0
  210. package/vendor/mimalloc/.gitattributes +12 -0
  211. package/vendor/mimalloc/CMakeLists.txt +763 -0
  212. package/vendor/mimalloc/LICENSE +21 -0
  213. package/vendor/mimalloc/SECURITY.md +41 -0
  214. package/vendor/mimalloc/azure-pipelines.yml +251 -0
  215. package/vendor/mimalloc/bin/mimalloc-redirect-arm64.dll +0 -0
  216. package/vendor/mimalloc/bin/mimalloc-redirect-arm64.lib +0 -0
  217. package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.dll +0 -0
  218. package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.lib +0 -0
  219. package/vendor/mimalloc/bin/mimalloc-redirect.dll +0 -0
  220. package/vendor/mimalloc/bin/mimalloc-redirect.lib +0 -0
  221. package/vendor/mimalloc/bin/mimalloc-redirect32.dll +0 -0
  222. package/vendor/mimalloc/bin/mimalloc-redirect32.lib +0 -0
  223. package/vendor/mimalloc/bin/minject-arm64.exe +0 -0
  224. package/vendor/mimalloc/bin/minject.exe +0 -0
  225. package/vendor/mimalloc/bin/minject32.exe +0 -0
  226. package/vendor/mimalloc/bin/readme.md +118 -0
  227. package/vendor/mimalloc/cmake/JoinPaths.cmake +23 -0
  228. package/vendor/mimalloc/cmake/mimalloc-config-version.cmake +19 -0
  229. package/vendor/mimalloc/cmake/mimalloc-config.cmake +14 -0
  230. package/vendor/mimalloc/contrib/docker/alpine/Dockerfile +23 -0
  231. package/vendor/mimalloc/contrib/docker/alpine-arm32v7/Dockerfile +28 -0
  232. package/vendor/mimalloc/contrib/docker/alpine-x86/Dockerfile +28 -0
  233. package/vendor/mimalloc/contrib/docker/manylinux-x64/Dockerfile +23 -0
  234. package/vendor/mimalloc/contrib/docker/readme.md +10 -0
  235. package/vendor/mimalloc/contrib/vcpkg/portfile.cmake +64 -0
  236. package/vendor/mimalloc/contrib/vcpkg/readme.md +40 -0
  237. package/vendor/mimalloc/contrib/vcpkg/usage +20 -0
  238. package/vendor/mimalloc/contrib/vcpkg/vcpkg-cmake-wrapper.cmake +20 -0
  239. package/vendor/mimalloc/contrib/vcpkg/vcpkg.json +48 -0
  240. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-a.svg +887 -0
  241. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-b.svg +1185 -0
  242. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-a.svg +757 -0
  243. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-b.svg +1028 -0
  244. package/vendor/mimalloc/doc/bench-2020/bench-r5a-1.svg +769 -0
  245. package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-a.svg +868 -0
  246. package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-b.svg +1157 -0
  247. package/vendor/mimalloc/doc/bench-2020/bench-r5a-2.svg +983 -0
  248. package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-1.svg +683 -0
  249. package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-2.svg +854 -0
  250. package/vendor/mimalloc/doc/bench-2020/bench-spec-rss.svg +713 -0
  251. package/vendor/mimalloc/doc/bench-2020/bench-spec.svg +713 -0
  252. package/vendor/mimalloc/doc/bench-2020/bench-z4-1.svg +890 -0
  253. package/vendor/mimalloc/doc/bench-2020/bench-z4-2.svg +1146 -0
  254. package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-1.svg +796 -0
  255. package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-2.svg +974 -0
  256. package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-a.svg +952 -0
  257. package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-b.svg +1255 -0
  258. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-a.svg +955 -0
  259. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-b.svg +1269 -0
  260. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-a.svg +836 -0
  261. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-b.svg +1131 -0
  262. package/vendor/mimalloc/doc/bench-2021/bench-macmini-2021-01-30.svg +766 -0
  263. package/vendor/mimalloc/doc/doxyfile +2895 -0
  264. package/vendor/mimalloc/doc/ds-logo.jpg +0 -0
  265. package/vendor/mimalloc/doc/ds-logo.png +0 -0
  266. package/vendor/mimalloc/doc/mimalloc-doc.h +1452 -0
  267. package/vendor/mimalloc/doc/mimalloc-doxygen.css +60 -0
  268. package/vendor/mimalloc/doc/mimalloc-logo-100.png +0 -0
  269. package/vendor/mimalloc/doc/mimalloc-logo.png +0 -0
  270. package/vendor/mimalloc/doc/mimalloc-logo.svg +161 -0
  271. package/vendor/mimalloc/doc/spades-logo.png +0 -0
  272. package/vendor/mimalloc/doc/unreal-logo.svg +43 -0
  273. package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj +500 -0
  274. package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj.filters +108 -0
  275. package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj +508 -0
  276. package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj.filters +111 -0
  277. package/vendor/mimalloc/ide/vs2022/mimalloc-override-test-dep.vcxproj +355 -0
  278. package/vendor/mimalloc/ide/vs2022/mimalloc-override-test.vcxproj +360 -0
  279. package/vendor/mimalloc/ide/vs2022/mimalloc-test-api.vcxproj +295 -0
  280. package/vendor/mimalloc/ide/vs2022/mimalloc-test-stress.vcxproj +292 -0
  281. package/vendor/mimalloc/ide/vs2022/mimalloc-test.vcxproj +289 -0
  282. package/vendor/mimalloc/ide/vs2022/mimalloc.sln +151 -0
  283. package/vendor/mimalloc/include/mimalloc/atomic.h +557 -0
  284. package/vendor/mimalloc/include/mimalloc/internal.h +1153 -0
  285. package/vendor/mimalloc/include/mimalloc/prim.h +421 -0
  286. package/vendor/mimalloc/include/mimalloc/track.h +145 -0
  287. package/vendor/mimalloc/include/mimalloc/types.h +685 -0
  288. package/vendor/mimalloc/include/mimalloc-new-delete.h +66 -0
  289. package/vendor/mimalloc/include/mimalloc-override.h +68 -0
  290. package/vendor/mimalloc/include/mimalloc-stats.h +103 -0
  291. package/vendor/mimalloc/include/mimalloc.h +612 -0
  292. package/vendor/mimalloc/mimalloc.pc.in +11 -0
  293. package/vendor/mimalloc/readme.md +946 -0
  294. package/vendor/mimalloc/src/alloc-aligned.c +360 -0
  295. package/vendor/mimalloc/src/alloc-override.c +316 -0
  296. package/vendor/mimalloc/src/alloc-posix.c +185 -0
  297. package/vendor/mimalloc/src/alloc.c +692 -0
  298. package/vendor/mimalloc/src/arena-abandon.c +346 -0
  299. package/vendor/mimalloc/src/arena.c +1043 -0
  300. package/vendor/mimalloc/src/bitmap.c +441 -0
  301. package/vendor/mimalloc/src/bitmap.h +119 -0
  302. package/vendor/mimalloc/src/free.c +572 -0
  303. package/vendor/mimalloc/src/heap.c +733 -0
  304. package/vendor/mimalloc/src/init.c +714 -0
  305. package/vendor/mimalloc/src/libc.c +334 -0
  306. package/vendor/mimalloc/src/options.c +663 -0
  307. package/vendor/mimalloc/src/os.c +770 -0
  308. package/vendor/mimalloc/src/page-queue.c +390 -0
  309. package/vendor/mimalloc/src/page.c +1049 -0
  310. package/vendor/mimalloc/src/prim/emscripten/prim.c +249 -0
  311. package/vendor/mimalloc/src/prim/osx/alloc-override-zone.c +461 -0
  312. package/vendor/mimalloc/src/prim/osx/prim.c +9 -0
  313. package/vendor/mimalloc/src/prim/prim.c +76 -0
  314. package/vendor/mimalloc/src/prim/readme.md +9 -0
  315. package/vendor/mimalloc/src/prim/unix/prim.c +934 -0
  316. package/vendor/mimalloc/src/prim/wasi/prim.c +284 -0
  317. package/vendor/mimalloc/src/prim/windows/etw-mimalloc.wprp +61 -0
  318. package/vendor/mimalloc/src/prim/windows/etw.h +905 -0
  319. package/vendor/mimalloc/src/prim/windows/etw.man +0 -0
  320. package/vendor/mimalloc/src/prim/windows/prim.c +878 -0
  321. package/vendor/mimalloc/src/prim/windows/readme.md +17 -0
  322. package/vendor/mimalloc/src/random.c +258 -0
  323. package/vendor/mimalloc/src/segment-map.c +142 -0
  324. package/vendor/mimalloc/src/segment.c +1702 -0
  325. package/vendor/mimalloc/src/static.c +41 -0
  326. package/vendor/mimalloc/src/stats.c +635 -0
  327. package/vendor/mimalloc/test/CMakeLists.txt +56 -0
  328. package/vendor/mimalloc/test/main-override-dep.cpp +51 -0
  329. package/vendor/mimalloc/test/main-override-dep.h +11 -0
  330. package/vendor/mimalloc/test/main-override-static.c +539 -0
  331. package/vendor/mimalloc/test/main-override.c +36 -0
  332. package/vendor/mimalloc/test/main-override.cpp +497 -0
  333. package/vendor/mimalloc/test/main.c +46 -0
  334. package/vendor/mimalloc/test/readme.md +16 -0
  335. package/vendor/mimalloc/test/test-api-fill.c +343 -0
  336. package/vendor/mimalloc/test/test-api.c +466 -0
  337. package/vendor/mimalloc/test/test-stress.c +428 -0
  338. package/vendor/mimalloc/test/test-wrong.c +92 -0
  339. package/vendor/mimalloc/test/testhelper.h +49 -0
@@ -0,0 +1,41 @@
1
+ /* ----------------------------------------------------------------------------
2
+ Copyright (c) 2018-2020, Microsoft Research, Daan Leijen
3
+ This is free software; you can redistribute it and/or modify it under the
4
+ terms of the MIT license. A copy of the license can be found in the file
5
+ "LICENSE" at the root of this distribution.
6
+ -----------------------------------------------------------------------------*/
7
+ #ifndef _DEFAULT_SOURCE
8
+ #define _DEFAULT_SOURCE
9
+ #endif
10
+ #if defined(__sun)
11
+ // same remarks as os.c for the static's context.
12
+ #undef _XOPEN_SOURCE
13
+ #undef _POSIX_C_SOURCE
14
+ #endif
15
+
16
+ #include "mimalloc.h"
17
+ #include "mimalloc/internal.h"
18
+
19
+ // For a static override we create a single object file
20
+ // containing the whole library. If it is linked first
21
+ // it will override all the standard library allocation
22
+ // functions (on Unix's).
23
+ #include "alloc.c" // includes alloc-override.c
24
+ #include "alloc-aligned.c"
25
+ #include "alloc-posix.c"
26
+ #include "arena.c"
27
+ #include "bitmap.c"
28
+ #include "heap.c"
29
+ #include "init.c"
30
+ #include "libc.c"
31
+ #include "options.c"
32
+ #include "os.c"
33
+ #include "page.c" // includes page-queue.c
34
+ #include "random.c"
35
+ #include "segment.c"
36
+ #include "segment-map.c"
37
+ #include "stats.c"
38
+ #include "prim/prim.c"
39
+ #if MI_OSX_ZONE
40
+ #include "prim/osx/alloc-override-zone.c"
41
+ #endif
@@ -0,0 +1,635 @@
1
+ /* ----------------------------------------------------------------------------
2
+ Copyright (c) 2018-2021, Microsoft Research, Daan Leijen
3
+ This is free software; you can redistribute it and/or modify it under the
4
+ terms of the MIT license. A copy of the license can be found in the file
5
+ "LICENSE" at the root of this distribution.
6
+ -----------------------------------------------------------------------------*/
7
+ #include "mimalloc.h"
8
+ #include "mimalloc/internal.h"
9
+ #include "mimalloc/atomic.h"
10
+ #include "mimalloc/prim.h"
11
+
12
+ #include <string.h> // memset
13
+
14
+ #if defined(_MSC_VER) && (_MSC_VER < 1920)
15
+ #pragma warning(disable:4204) // non-constant aggregate initializer
16
+ #endif
17
+
18
+ /* -----------------------------------------------------------
19
+ Statistics operations
20
+ ----------------------------------------------------------- */
21
+
22
+ static bool mi_is_in_main(void* stat) {
23
+ return ((uint8_t*)stat >= (uint8_t*)&_mi_stats_main
24
+ && (uint8_t*)stat < ((uint8_t*)&_mi_stats_main + sizeof(mi_stats_t)));
25
+ }
26
+
27
+ static void mi_stat_update(mi_stat_count_t* stat, int64_t amount) {
28
+ if (amount == 0) return;
29
+ if mi_unlikely(mi_is_in_main(stat))
30
+ {
31
+ // add atomically (for abandoned pages)
32
+ int64_t current = mi_atomic_addi64_relaxed(&stat->current, amount);
33
+ // if (stat == &_mi_stats_main.committed) { mi_assert_internal(current + amount >= 0); };
34
+ mi_atomic_maxi64_relaxed(&stat->peak, current + amount);
35
+ if (amount > 0) {
36
+ mi_atomic_addi64_relaxed(&stat->total,amount);
37
+ }
38
+ }
39
+ else {
40
+ // add thread local
41
+ stat->current += amount;
42
+ if (stat->current > stat->peak) { stat->peak = stat->current; }
43
+ if (amount > 0) { stat->total += amount; }
44
+ }
45
+ }
46
+
47
+ void _mi_stat_counter_increase(mi_stat_counter_t* stat, size_t amount) {
48
+ if (mi_is_in_main(stat)) {
49
+ mi_atomic_addi64_relaxed( &stat->total, (int64_t)amount );
50
+ }
51
+ else {
52
+ stat->total += amount;
53
+ }
54
+ }
55
+
56
+ void _mi_stat_increase(mi_stat_count_t* stat, size_t amount) {
57
+ mi_stat_update(stat, (int64_t)amount);
58
+ }
59
+
60
+ void _mi_stat_decrease(mi_stat_count_t* stat, size_t amount) {
61
+ mi_stat_update(stat, -((int64_t)amount));
62
+ }
63
+
64
+
65
+ static void mi_stat_adjust(mi_stat_count_t* stat, int64_t amount) {
66
+ if (amount == 0) return;
67
+ if mi_unlikely(mi_is_in_main(stat))
68
+ {
69
+ // adjust atomically
70
+ mi_atomic_addi64_relaxed(&stat->current, amount);
71
+ mi_atomic_addi64_relaxed(&stat->total,amount);
72
+ }
73
+ else {
74
+ // adjust local
75
+ stat->current += amount;
76
+ stat->total += amount;
77
+ }
78
+ }
79
+
80
+ void _mi_stat_adjust_decrease(mi_stat_count_t* stat, size_t amount) {
81
+ mi_stat_adjust(stat, -((int64_t)amount));
82
+ }
83
+
84
+
85
+ // must be thread safe as it is called from stats_merge
86
+ static void mi_stat_count_add_mt(mi_stat_count_t* stat, const mi_stat_count_t* src) {
87
+ if (stat==src) return;
88
+ mi_atomic_void_addi64_relaxed(&stat->total, &src->total);
89
+ mi_atomic_void_addi64_relaxed(&stat->current, &src->current);
90
+ // peak scores do really not work across threads .. we just add them
91
+ mi_atomic_void_addi64_relaxed( &stat->peak, &src->peak);
92
+ // or, take the max?
93
+ // mi_atomic_maxi64_relaxed(&stat->peak, src->peak);
94
+ }
95
+
96
+ static void mi_stat_counter_add_mt(mi_stat_counter_t* stat, const mi_stat_counter_t* src) {
97
+ if (stat==src) return;
98
+ mi_atomic_void_addi64_relaxed(&stat->total, &src->total);
99
+ }
100
+
101
+ #define MI_STAT_COUNT(stat) mi_stat_count_add_mt(&stats->stat, &src->stat);
102
+ #define MI_STAT_COUNTER(stat) mi_stat_counter_add_mt(&stats->stat, &src->stat);
103
+
104
+ // must be thread safe as it is called from stats_merge
105
+ static void mi_stats_add(mi_stats_t* stats, const mi_stats_t* src) {
106
+ if (stats==src) return;
107
+
108
+ // copy all fields
109
+ MI_STAT_FIELDS()
110
+
111
+ #if MI_STAT>1
112
+ for (size_t i = 0; i <= MI_BIN_HUGE; i++) {
113
+ mi_stat_count_add_mt(&stats->malloc_bins[i], &src->malloc_bins[i]);
114
+ }
115
+ #endif
116
+ for (size_t i = 0; i <= MI_BIN_HUGE; i++) {
117
+ mi_stat_count_add_mt(&stats->page_bins[i], &src->page_bins[i]);
118
+ }
119
+ }
120
+
121
+ #undef MI_STAT_COUNT
122
+ #undef MI_STAT_COUNTER
123
+
124
+ /* -----------------------------------------------------------
125
+ Display statistics
126
+ ----------------------------------------------------------- */
127
+
128
+ // unit > 0 : size in binary bytes
129
+ // unit == 0: count as decimal
130
+ // unit < 0 : count in binary
131
+ static void mi_printf_amount(int64_t n, int64_t unit, mi_output_fun* out, void* arg, const char* fmt) {
132
+ char buf[32]; buf[0] = 0;
133
+ int len = 32;
134
+ const char* suffix = (unit <= 0 ? " " : "B");
135
+ const int64_t base = (unit == 0 ? 1000 : 1024);
136
+ if (unit>0) n *= unit;
137
+
138
+ const int64_t pos = (n < 0 ? -n : n);
139
+ if (pos < base) {
140
+ if (n!=1 || suffix[0] != 'B') { // skip printing 1 B for the unit column
141
+ _mi_snprintf(buf, len, "%lld %-3s", (long long)n, (n==0 ? "" : suffix));
142
+ }
143
+ }
144
+ else {
145
+ int64_t divider = base;
146
+ const char* magnitude = "K";
147
+ if (pos >= divider*base) { divider *= base; magnitude = "M"; }
148
+ if (pos >= divider*base) { divider *= base; magnitude = "G"; }
149
+ const int64_t tens = (n / (divider/10));
150
+ const long whole = (long)(tens/10);
151
+ const long frac1 = (long)(tens%10);
152
+ char unitdesc[8];
153
+ _mi_snprintf(unitdesc, 8, "%s%s%s", magnitude, (base==1024 ? "i" : ""), suffix);
154
+ _mi_snprintf(buf, len, "%ld.%ld %-3s", whole, (frac1 < 0 ? -frac1 : frac1), unitdesc);
155
+ }
156
+ _mi_fprintf(out, arg, (fmt==NULL ? "%12s" : fmt), buf);
157
+ }
158
+
159
+
160
+ static void mi_print_amount(int64_t n, int64_t unit, mi_output_fun* out, void* arg) {
161
+ mi_printf_amount(n,unit,out,arg,NULL);
162
+ }
163
+
164
+ static void mi_print_count(int64_t n, int64_t unit, mi_output_fun* out, void* arg) {
165
+ if (unit==1) _mi_fprintf(out, arg, "%12s"," ");
166
+ else mi_print_amount(n,0,out,arg);
167
+ }
168
+
169
+ static void mi_stat_print_ex(const mi_stat_count_t* stat, const char* msg, int64_t unit, mi_output_fun* out, void* arg, const char* notok ) {
170
+ _mi_fprintf(out, arg,"%10s:", msg);
171
+ if (unit != 0) {
172
+ if (unit > 0) {
173
+ mi_print_amount(stat->peak, unit, out, arg);
174
+ mi_print_amount(stat->total, unit, out, arg);
175
+ // mi_print_amount(stat->freed, unit, out, arg);
176
+ mi_print_amount(stat->current, unit, out, arg);
177
+ mi_print_amount(unit, 1, out, arg);
178
+ mi_print_count(stat->total, unit, out, arg);
179
+ }
180
+ else {
181
+ mi_print_amount(stat->peak, -1, out, arg);
182
+ mi_print_amount(stat->total, -1, out, arg);
183
+ // mi_print_amount(stat->freed, -1, out, arg);
184
+ mi_print_amount(stat->current, -1, out, arg);
185
+ if (unit == -1) {
186
+ _mi_fprintf(out, arg, "%24s", "");
187
+ }
188
+ else {
189
+ mi_print_amount(-unit, 1, out, arg);
190
+ mi_print_count((stat->total / -unit), 0, out, arg);
191
+ }
192
+ }
193
+ if (stat->current != 0) {
194
+ _mi_fprintf(out, arg, " ");
195
+ _mi_fprintf(out, arg, (notok == NULL ? "not all freed" : notok));
196
+ _mi_fprintf(out, arg, "\n");
197
+ }
198
+ else {
199
+ _mi_fprintf(out, arg, " ok\n");
200
+ }
201
+ }
202
+ else {
203
+ mi_print_amount(stat->peak, 1, out, arg);
204
+ mi_print_amount(stat->total, 1, out, arg);
205
+ _mi_fprintf(out, arg, "%11s", " "); // no freed
206
+ mi_print_amount(stat->current, 1, out, arg);
207
+ _mi_fprintf(out, arg, "\n");
208
+ }
209
+ }
210
+
211
+ static void mi_stat_print(const mi_stat_count_t* stat, const char* msg, int64_t unit, mi_output_fun* out, void* arg) {
212
+ mi_stat_print_ex(stat, msg, unit, out, arg, NULL);
213
+ }
214
+
215
+ static void mi_stat_peak_print(const mi_stat_count_t* stat, const char* msg, int64_t unit, mi_output_fun* out, void* arg) {
216
+ _mi_fprintf(out, arg, "%10s:", msg);
217
+ mi_print_amount(stat->peak, unit, out, arg);
218
+ _mi_fprintf(out, arg, "\n");
219
+ }
220
+
221
+ #if MI_STAT>1
222
+ static void mi_stat_total_print(const mi_stat_count_t* stat, const char* msg, int64_t unit, mi_output_fun* out, void* arg) {
223
+ _mi_fprintf(out, arg, "%10s:", msg);
224
+ _mi_fprintf(out, arg, "%12s", " "); // no peak
225
+ mi_print_amount(stat->total, unit, out, arg);
226
+ _mi_fprintf(out, arg, "\n");
227
+ }
228
+ #endif
229
+
230
+ static void mi_stat_counter_print(const mi_stat_counter_t* stat, const char* msg, mi_output_fun* out, void* arg ) {
231
+ _mi_fprintf(out, arg, "%10s:", msg);
232
+ mi_print_amount(stat->total, -1, out, arg);
233
+ _mi_fprintf(out, arg, "\n");
234
+ }
235
+
236
+
237
+ static void mi_stat_counter_print_avg(const mi_stat_counter_t* stat, const char* msg, mi_output_fun* out, void* arg) {
238
+ const int64_t avg_tens = (stat->total == 0 ? 0 : (stat->total*10 / stat->total));
239
+ const long avg_whole = (long)(avg_tens/10);
240
+ const long avg_frac1 = (long)(avg_tens%10);
241
+ _mi_fprintf(out, arg, "%10s: %5ld.%ld avg\n", msg, avg_whole, avg_frac1);
242
+ }
243
+
244
+
245
+ static void mi_print_header(mi_output_fun* out, void* arg ) {
246
+ _mi_fprintf(out, arg, "%10s: %11s %11s %11s %11s %11s\n", "heap stats", "peak ", "total ", "current ", "block ", "total# ");
247
+ }
248
+
249
+ #if MI_STAT>1
250
+ static void mi_stats_print_bins(const mi_stat_count_t* bins, size_t max, const char* fmt, mi_output_fun* out, void* arg) {
251
+ bool found = false;
252
+ char buf[64];
253
+ for (size_t i = 0; i <= max; i++) {
254
+ if (bins[i].total > 0) {
255
+ found = true;
256
+ int64_t unit = _mi_bin_size((uint8_t)i);
257
+ _mi_snprintf(buf, 64, "%s %3lu", fmt, (long)i);
258
+ mi_stat_print(&bins[i], buf, unit, out, arg);
259
+ }
260
+ }
261
+ if (found) {
262
+ _mi_fprintf(out, arg, "\n");
263
+ mi_print_header(out, arg);
264
+ }
265
+ }
266
+ #endif
267
+
268
+
269
+
270
+ //------------------------------------------------------------
271
+ // Use an output wrapper for line-buffered output
272
+ // (which is nice when using loggers etc.)
273
+ //------------------------------------------------------------
274
+ typedef struct buffered_s {
275
+ mi_output_fun* out; // original output function
276
+ void* arg; // and state
277
+ char* buf; // local buffer of at least size `count+1`
278
+ size_t used; // currently used chars `used <= count`
279
+ size_t count; // total chars available for output
280
+ } buffered_t;
281
+
282
+ static void mi_buffered_flush(buffered_t* buf) {
283
+ buf->buf[buf->used] = 0;
284
+ _mi_fputs(buf->out, buf->arg, NULL, buf->buf);
285
+ buf->used = 0;
286
+ }
287
+
288
+ static void mi_cdecl mi_buffered_out(const char* msg, void* arg) {
289
+ buffered_t* buf = (buffered_t*)arg;
290
+ if (msg==NULL || buf==NULL) return;
291
+ for (const char* src = msg; *src != 0; src++) {
292
+ char c = *src;
293
+ if (buf->used >= buf->count) mi_buffered_flush(buf);
294
+ mi_assert_internal(buf->used < buf->count);
295
+ buf->buf[buf->used++] = c;
296
+ if (c == '\n') mi_buffered_flush(buf);
297
+ }
298
+ }
299
+
300
+ //------------------------------------------------------------
301
+ // Print statistics
302
+ //------------------------------------------------------------
303
+
304
+ static void _mi_stats_print(mi_stats_t* stats, mi_output_fun* out0, void* arg0) mi_attr_noexcept {
305
+ // wrap the output function to be line buffered
306
+ char buf[256];
307
+ buffered_t buffer = { out0, arg0, NULL, 0, 255 };
308
+ buffer.buf = buf;
309
+ mi_output_fun* out = &mi_buffered_out;
310
+ void* arg = &buffer;
311
+
312
+ // and print using that
313
+ mi_print_header(out,arg);
314
+ #if MI_STAT>1
315
+ mi_stats_print_bins(stats->malloc_bins, MI_BIN_HUGE, "bin",out,arg);
316
+ #endif
317
+ #if MI_STAT
318
+ mi_stat_print(&stats->malloc_normal, "binned", (stats->malloc_normal_count.total == 0 ? 1 : -1), out, arg);
319
+ // mi_stat_print(&stats->malloc_large, "large", (stats->malloc_large_count.total == 0 ? 1 : -1), out, arg);
320
+ mi_stat_print(&stats->malloc_huge, "huge", (stats->malloc_huge_count.total == 0 ? 1 : -1), out, arg);
321
+ mi_stat_count_t total = { 0,0,0 };
322
+ mi_stat_count_add_mt(&total, &stats->malloc_normal);
323
+ // mi_stat_count_add(&total, &stats->malloc_large);
324
+ mi_stat_count_add_mt(&total, &stats->malloc_huge);
325
+ mi_stat_print_ex(&total, "total", 1, out, arg, "");
326
+ #endif
327
+ #if MI_STAT>1
328
+ mi_stat_total_print(&stats->malloc_requested, "malloc req", 1, out, arg);
329
+ _mi_fprintf(out, arg, "\n");
330
+ #endif
331
+ mi_stat_print_ex(&stats->reserved, "reserved", 1, out, arg, "");
332
+ mi_stat_print_ex(&stats->committed, "committed", 1, out, arg, "");
333
+ mi_stat_peak_print(&stats->reset, "reset", 1, out, arg );
334
+ mi_stat_peak_print(&stats->purged, "purged", 1, out, arg );
335
+ mi_stat_print_ex(&stats->page_committed, "touched", 1, out, arg, "");
336
+ mi_stat_print(&stats->segments, "segments", -1, out, arg);
337
+ mi_stat_print(&stats->segments_abandoned, "-abandoned", -1, out, arg);
338
+ mi_stat_print(&stats->segments_cache, "-cached", -1, out, arg);
339
+ mi_stat_print(&stats->pages, "pages", -1, out, arg);
340
+ mi_stat_print(&stats->pages_abandoned, "-abandoned", -1, out, arg);
341
+ mi_stat_counter_print(&stats->pages_extended, "-extended", out, arg);
342
+ mi_stat_counter_print(&stats->pages_retire, "-retire", out, arg);
343
+ mi_stat_counter_print(&stats->arena_count, "arenas", out, arg);
344
+ // mi_stat_counter_print(&stats->arena_crossover_count, "-crossover", out, arg);
345
+ mi_stat_counter_print(&stats->arena_rollback_count, "-rollback", out, arg);
346
+ mi_stat_counter_print(&stats->mmap_calls, "mmaps", out, arg);
347
+ mi_stat_counter_print(&stats->commit_calls, "commits", out, arg);
348
+ mi_stat_counter_print(&stats->reset_calls, "resets", out, arg);
349
+ mi_stat_counter_print(&stats->purge_calls, "purges", out, arg);
350
+ mi_stat_counter_print(&stats->malloc_guarded_count, "guarded", out, arg);
351
+ mi_stat_print(&stats->threads, "threads", -1, out, arg);
352
+ mi_stat_counter_print_avg(&stats->page_searches, "searches", out, arg);
353
+ _mi_fprintf(out, arg, "%10s: %5i\n", "numa nodes", _mi_os_numa_node_count());
354
+
355
+ size_t elapsed;
356
+ size_t user_time;
357
+ size_t sys_time;
358
+ size_t current_rss;
359
+ size_t peak_rss;
360
+ size_t current_commit;
361
+ size_t peak_commit;
362
+ size_t page_faults;
363
+ mi_process_info(&elapsed, &user_time, &sys_time, &current_rss, &peak_rss, &current_commit, &peak_commit, &page_faults);
364
+ _mi_fprintf(out, arg, "%10s: %5zu.%03zu s\n", "elapsed", elapsed/1000, elapsed%1000);
365
+ _mi_fprintf(out, arg, "%10s: user: %zu.%03zu s, system: %zu.%03zu s, faults: %zu, rss: ", "process",
366
+ user_time/1000, user_time%1000, sys_time/1000, sys_time%1000, page_faults );
367
+ mi_printf_amount((int64_t)peak_rss, 1, out, arg, "%s");
368
+ if (peak_commit > 0) {
369
+ _mi_fprintf(out, arg, ", commit: ");
370
+ mi_printf_amount((int64_t)peak_commit, 1, out, arg, "%s");
371
+ }
372
+ _mi_fprintf(out, arg, "\n");
373
+ }
374
+
375
+ static mi_msecs_t mi_process_start; // = 0
376
+
377
+ static mi_stats_t* mi_stats_get_default(void) {
378
+ mi_heap_t* heap = mi_heap_get_default();
379
+ return &heap->tld->stats;
380
+ }
381
+
382
+ static void mi_stats_merge_from(mi_stats_t* stats) {
383
+ if (stats != &_mi_stats_main) {
384
+ mi_stats_add(&_mi_stats_main, stats);
385
+ memset(stats, 0, sizeof(mi_stats_t));
386
+ }
387
+ }
388
+
389
+ void mi_stats_reset(void) mi_attr_noexcept {
390
+ mi_stats_t* stats = mi_stats_get_default();
391
+ if (stats != &_mi_stats_main) { memset(stats, 0, sizeof(mi_stats_t)); }
392
+ memset(&_mi_stats_main, 0, sizeof(mi_stats_t));
393
+ if (mi_process_start == 0) { mi_process_start = _mi_clock_start(); };
394
+ }
395
+
396
+ void mi_stats_merge(void) mi_attr_noexcept {
397
+ mi_stats_merge_from( mi_stats_get_default() );
398
+ }
399
+
400
+ void _mi_stats_merge_thread(mi_tld_t* tld) {
401
+ mi_stats_merge_from( &tld->stats );
402
+ }
403
+
404
+ void _mi_stats_done(mi_stats_t* stats) { // called from `mi_thread_done`
405
+ mi_stats_merge_from(stats);
406
+ }
407
+
408
+ void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept {
409
+ mi_stats_merge_from(mi_stats_get_default());
410
+ _mi_stats_print(&_mi_stats_main, out, arg);
411
+ }
412
+
413
+ void mi_stats_print(void* out) mi_attr_noexcept {
414
+ // for compatibility there is an `out` parameter (which can be `stdout` or `stderr`)
415
+ mi_stats_print_out((mi_output_fun*)out, NULL);
416
+ }
417
+
418
+ void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept {
419
+ _mi_stats_print(mi_stats_get_default(), out, arg);
420
+ }
421
+
422
+
423
+ // ----------------------------------------------------------------
424
+ // Basic timer for convenience; use milli-seconds to avoid doubles
425
+ // ----------------------------------------------------------------
426
+
427
+ static mi_msecs_t mi_clock_diff;
428
+
429
+ mi_msecs_t _mi_clock_now(void) {
430
+ return _mi_prim_clock_now();
431
+ }
432
+
433
+ mi_msecs_t _mi_clock_start(void) {
434
+ if (mi_clock_diff == 0.0) {
435
+ mi_msecs_t t0 = _mi_clock_now();
436
+ mi_clock_diff = _mi_clock_now() - t0;
437
+ }
438
+ return _mi_clock_now();
439
+ }
440
+
441
+ mi_msecs_t _mi_clock_end(mi_msecs_t start) {
442
+ mi_msecs_t end = _mi_clock_now();
443
+ return (end - start - mi_clock_diff);
444
+ }
445
+
446
+
447
+ // --------------------------------------------------------
448
+ // Basic process statistics
449
+ // --------------------------------------------------------
450
+
451
+ mi_decl_export void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, size_t* system_msecs, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept
452
+ {
453
+ mi_process_info_t pinfo;
454
+ _mi_memzero_var(pinfo);
455
+ pinfo.elapsed = _mi_clock_end(mi_process_start);
456
+ pinfo.current_commit = (size_t)(mi_atomic_loadi64_relaxed((_Atomic(int64_t)*)&_mi_stats_main.committed.current));
457
+ pinfo.peak_commit = (size_t)(mi_atomic_loadi64_relaxed((_Atomic(int64_t)*)&_mi_stats_main.committed.peak));
458
+ pinfo.current_rss = pinfo.current_commit;
459
+ pinfo.peak_rss = pinfo.peak_commit;
460
+ pinfo.utime = 0;
461
+ pinfo.stime = 0;
462
+ pinfo.page_faults = 0;
463
+
464
+ _mi_prim_process_info(&pinfo);
465
+
466
+ if (elapsed_msecs!=NULL) *elapsed_msecs = (pinfo.elapsed < 0 ? 0 : (pinfo.elapsed < (mi_msecs_t)PTRDIFF_MAX ? (size_t)pinfo.elapsed : PTRDIFF_MAX));
467
+ if (user_msecs!=NULL) *user_msecs = (pinfo.utime < 0 ? 0 : (pinfo.utime < (mi_msecs_t)PTRDIFF_MAX ? (size_t)pinfo.utime : PTRDIFF_MAX));
468
+ if (system_msecs!=NULL) *system_msecs = (pinfo.stime < 0 ? 0 : (pinfo.stime < (mi_msecs_t)PTRDIFF_MAX ? (size_t)pinfo.stime : PTRDIFF_MAX));
469
+ if (current_rss!=NULL) *current_rss = pinfo.current_rss;
470
+ if (peak_rss!=NULL) *peak_rss = pinfo.peak_rss;
471
+ if (current_commit!=NULL) *current_commit = pinfo.current_commit;
472
+ if (peak_commit!=NULL) *peak_commit = pinfo.peak_commit;
473
+ if (page_faults!=NULL) *page_faults = pinfo.page_faults;
474
+ }
475
+
476
+
477
+ // --------------------------------------------------------
478
+ // Return statistics
479
+ // --------------------------------------------------------
480
+
481
+ void mi_stats_get(size_t stats_size, mi_stats_t* stats) mi_attr_noexcept {
482
+ if (stats == NULL || stats_size == 0) return;
483
+ _mi_memzero(stats, stats_size);
484
+ const size_t size = (stats_size > sizeof(mi_stats_t) ? sizeof(mi_stats_t) : stats_size);
485
+ _mi_memcpy(stats, &_mi_stats_main, size);
486
+ stats->version = MI_STAT_VERSION;
487
+ }
488
+
489
+
490
+ // --------------------------------------------------------
491
+ // Statics in json format
492
+ // --------------------------------------------------------
493
+
494
+ typedef struct mi_heap_buf_s {
495
+ char* buf;
496
+ size_t size;
497
+ size_t used;
498
+ bool can_realloc;
499
+ } mi_heap_buf_t;
500
+
501
+ static bool mi_heap_buf_expand(mi_heap_buf_t* hbuf) {
502
+ if (hbuf==NULL) return false;
503
+ if (hbuf->buf != NULL && hbuf->size>0) {
504
+ hbuf->buf[hbuf->size-1] = 0;
505
+ }
506
+ if (hbuf->size > SIZE_MAX/2 || !hbuf->can_realloc) return false;
507
+ const size_t newsize = (hbuf->size == 0 ? mi_good_size(12*MI_KiB) : 2*hbuf->size);
508
+ char* const newbuf = (char*)mi_rezalloc(hbuf->buf, newsize);
509
+ if (newbuf == NULL) return false;
510
+ hbuf->buf = newbuf;
511
+ hbuf->size = newsize;
512
+ return true;
513
+ }
514
+
515
+ static void mi_heap_buf_print(mi_heap_buf_t* hbuf, const char* msg) {
516
+ if (msg==NULL || hbuf==NULL) return;
517
+ if (hbuf->used + 1 >= hbuf->size && !hbuf->can_realloc) return;
518
+ for (const char* src = msg; *src != 0; src++) {
519
+ char c = *src;
520
+ if (hbuf->used + 1 >= hbuf->size) {
521
+ if (!mi_heap_buf_expand(hbuf)) return;
522
+ }
523
+ mi_assert_internal(hbuf->used < hbuf->size);
524
+ hbuf->buf[hbuf->used++] = c;
525
+ }
526
+ mi_assert_internal(hbuf->used < hbuf->size);
527
+ hbuf->buf[hbuf->used] = 0;
528
+ }
529
+
530
+ static void mi_heap_buf_print_count_bin(mi_heap_buf_t* hbuf, const char* prefix, mi_stat_count_t* stat, size_t bin, bool add_comma) {
531
+ const size_t binsize = _mi_bin_size(bin);
532
+ const size_t pagesize = (binsize <= MI_SMALL_OBJ_SIZE_MAX ? MI_SMALL_PAGE_SIZE :
533
+ (binsize <= MI_MEDIUM_OBJ_SIZE_MAX ? MI_MEDIUM_PAGE_SIZE :
534
+ #if MI_LARGE_PAGE_SIZE
535
+ (binsize <= MI_LARGE_OBJ_SIZE_MAX ? MI_LARGE_PAGE_SIZE : 0)
536
+ #else
537
+ 0
538
+ #endif
539
+ ));
540
+ char buf[128];
541
+ _mi_snprintf(buf, 128, "%s{ \"total\": %lld, \"peak\": %lld, \"current\": %lld, \"block_size\": %zu, \"page_size\": %zu }%s\n", prefix, stat->total, stat->peak, stat->current, binsize, pagesize, (add_comma ? "," : ""));
542
+ buf[127] = 0;
543
+ mi_heap_buf_print(hbuf, buf);
544
+ }
545
+
546
+ static void mi_heap_buf_print_count(mi_heap_buf_t* hbuf, const char* prefix, mi_stat_count_t* stat, bool add_comma) {
547
+ char buf[128];
548
+ _mi_snprintf(buf, 128, "%s{ \"total\": %lld, \"peak\": %lld, \"current\": %lld }%s\n", prefix, stat->total, stat->peak, stat->current, (add_comma ? "," : ""));
549
+ buf[127] = 0;
550
+ mi_heap_buf_print(hbuf, buf);
551
+ }
552
+
553
+ static void mi_heap_buf_print_count_value(mi_heap_buf_t* hbuf, const char* name, mi_stat_count_t* stat) {
554
+ char buf[128];
555
+ _mi_snprintf(buf, 128, " \"%s\": ", name);
556
+ buf[127] = 0;
557
+ mi_heap_buf_print(hbuf, buf);
558
+ mi_heap_buf_print_count(hbuf, "", stat, true);
559
+ }
560
+
561
+ static void mi_heap_buf_print_value(mi_heap_buf_t* hbuf, const char* name, int64_t val) {
562
+ char buf[128];
563
+ _mi_snprintf(buf, 128, " \"%s\": %lld,\n", name, val);
564
+ buf[127] = 0;
565
+ mi_heap_buf_print(hbuf, buf);
566
+ }
567
+
568
+ static void mi_heap_buf_print_size(mi_heap_buf_t* hbuf, const char* name, size_t val, bool add_comma) {
569
+ char buf[128];
570
+ _mi_snprintf(buf, 128, " \"%s\": %zu%s\n", name, val, (add_comma ? "," : ""));
571
+ buf[127] = 0;
572
+ mi_heap_buf_print(hbuf, buf);
573
+ }
574
+
575
+ static void mi_heap_buf_print_counter_value(mi_heap_buf_t* hbuf, const char* name, mi_stat_counter_t* stat) {
576
+ mi_heap_buf_print_value(hbuf, name, stat->total);
577
+ }
578
+
579
+ #define MI_STAT_COUNT(stat) mi_heap_buf_print_count_value(&hbuf, #stat, &stats->stat);
580
+ #define MI_STAT_COUNTER(stat) mi_heap_buf_print_counter_value(&hbuf, #stat, &stats->stat);
581
+
582
+ char* mi_stats_get_json(size_t output_size, char* output_buf) mi_attr_noexcept {
583
+ mi_heap_buf_t hbuf = { NULL, 0, 0, true };
584
+ if (output_size > 0 && output_buf != NULL) {
585
+ _mi_memzero(output_buf, output_size);
586
+ hbuf.buf = output_buf;
587
+ hbuf.size = output_size;
588
+ hbuf.can_realloc = false;
589
+ }
590
+ else {
591
+ if (!mi_heap_buf_expand(&hbuf)) return NULL;
592
+ }
593
+ mi_heap_buf_print(&hbuf, "{\n");
594
+ mi_heap_buf_print_value(&hbuf, "version", MI_STAT_VERSION);
595
+ mi_heap_buf_print_value(&hbuf, "mimalloc_version", MI_MALLOC_VERSION);
596
+
597
+ // process info
598
+ mi_heap_buf_print(&hbuf, " \"process\": {\n");
599
+ size_t elapsed;
600
+ size_t user_time;
601
+ size_t sys_time;
602
+ size_t current_rss;
603
+ size_t peak_rss;
604
+ size_t current_commit;
605
+ size_t peak_commit;
606
+ size_t page_faults;
607
+ mi_process_info(&elapsed, &user_time, &sys_time, &current_rss, &peak_rss, &current_commit, &peak_commit, &page_faults);
608
+ mi_heap_buf_print_size(&hbuf, "elapsed_msecs", elapsed, true);
609
+ mi_heap_buf_print_size(&hbuf, "user_msecs", user_time, true);
610
+ mi_heap_buf_print_size(&hbuf, "system_msecs", sys_time, true);
611
+ mi_heap_buf_print_size(&hbuf, "page_faults", page_faults, true);
612
+ mi_heap_buf_print_size(&hbuf, "rss_current", current_rss, true);
613
+ mi_heap_buf_print_size(&hbuf, "rss_peak", peak_rss, true);
614
+ mi_heap_buf_print_size(&hbuf, "commit_current", current_commit, true);
615
+ mi_heap_buf_print_size(&hbuf, "commit_peak", peak_commit, false);
616
+ mi_heap_buf_print(&hbuf, " },\n");
617
+
618
+ // statistics
619
+ mi_stats_t* stats = &_mi_stats_main;
620
+ MI_STAT_FIELDS()
621
+
622
+ // size bins
623
+ mi_heap_buf_print(&hbuf, " \"malloc_bins\": [\n");
624
+ for (size_t i = 0; i <= MI_BIN_HUGE; i++) {
625
+ mi_heap_buf_print_count_bin(&hbuf, " ", &stats->malloc_bins[i], i, i!=MI_BIN_HUGE);
626
+ }
627
+ mi_heap_buf_print(&hbuf, " ],\n");
628
+ mi_heap_buf_print(&hbuf, " \"page_bins\": [\n");
629
+ for (size_t i = 0; i <= MI_BIN_HUGE; i++) {
630
+ mi_heap_buf_print_count_bin(&hbuf, " ", &stats->page_bins[i], i, i!=MI_BIN_HUGE);
631
+ }
632
+ mi_heap_buf_print(&hbuf, " ]\n");
633
+ mi_heap_buf_print(&hbuf, "}\n");
634
+ return hbuf.buf;
635
+ }