codegreen 0.4.8__tar.gz → 0.5.0__tar.gz

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 (311) hide show
  1. {codegreen-0.4.8 → codegreen-0.5.0}/CMakeLists.txt +4 -15
  2. codegreen-0.5.0/MANIFEST.in +16 -0
  3. {codegreen-0.4.8/codegreen.egg-info → codegreen-0.5.0}/PKG-INFO +45 -7
  4. {codegreen-0.4.8 → codegreen-0.5.0}/README.md +32 -6
  5. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/__main__.py +10 -14
  6. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/config.py +29 -13
  7. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/harness.py +22 -4
  8. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/profilers.py +74 -116
  9. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/results.py +50 -33
  10. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/suites/benchmarksgame.py +19 -3
  11. codegreen-0.5.0/benchmark/validation/experiments.py +425 -0
  12. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/__init__.py +8 -11
  13. codegreen-0.5.0/codegreen/analysis/cfg/callgraph.py +554 -0
  14. codegreen-0.5.0/codegreen/analysis/cfg/energy_flow.py +32 -0
  15. codegreen-0.5.0/codegreen/analysis/efg/__init__.py +67 -0
  16. codegreen-0.5.0/codegreen/analysis/efg/adapter.py +53 -0
  17. codegreen-0.5.0/codegreen/analysis/efg/example/Sample.java +12 -0
  18. codegreen-0.5.0/codegreen/analysis/efg/example/__init__.py +1 -0
  19. codegreen-0.5.0/codegreen/analysis/efg/example/demo.py +28 -0
  20. codegreen-0.5.0/codegreen/analysis/efg/graph.py +300 -0
  21. codegreen-0.5.0/codegreen/analysis/efg/heuristics.py +137 -0
  22. codegreen-0.5.0/codegreen/analysis/efg/paths.py +128 -0
  23. codegreen-0.5.0/codegreen/analysis/efg/serialize.py +144 -0
  24. codegreen-0.5.0/codegreen/analysis/efg/types.py +76 -0
  25. codegreen-0.5.0/codegreen/analysis/gpu_metrics.py +236 -0
  26. codegreen-0.5.0/codegreen/analysis/hwcounters.py +163 -0
  27. codegreen-0.5.0/codegreen/analysis/languages.py +65 -0
  28. codegreen-0.5.0/codegreen/analysis/line_sampling.py +288 -0
  29. codegreen-0.5.0/codegreen/analysis/metrics.py +143 -0
  30. codegreen-0.5.0/codegreen/analysis/pyalloc.py +65 -0
  31. codegreen-0.5.0/codegreen/analysis/sampling.py +322 -0
  32. codegreen-0.5.0/codegreen/analysis/timeline.py +235 -0
  33. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/cli/cli.py +1123 -773
  34. codegreen-0.5.0/codegreen/cli/entrypoint.py +59 -0
  35. codegreen-0.5.0/codegreen/config.json +336 -0
  36. codegreen-0.5.0/codegreen/hw_events/amd_zen.json +2 -0
  37. codegreen-0.5.0/codegreen/hw_events/arm_neoverse.json +3 -0
  38. codegreen-0.5.0/codegreen/hw_events/generic.json +5 -0
  39. codegreen-0.5.0/codegreen/hw_events/intel.json +2 -0
  40. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/__init__.py +1 -2
  41. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/ast_processor.py +158 -23
  42. codegreen-0.5.0/codegreen/instrumentation/brace_normaliser.py +121 -0
  43. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/bridge_instrument.py +6 -4
  44. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/configs/TEMPLATE.json +5 -2
  45. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/configs/c.json +19 -1
  46. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/configs/cpp.json +13 -8
  47. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/configs/java.json +29 -5
  48. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/configs/javascript.json +13 -3
  49. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/configs/python.json +22 -9
  50. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/language_configs.py +2 -1
  51. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/language_engine.py +457 -130
  52. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/language_runtimes/c/codegreen_runtime.h +8 -0
  53. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/language_runtimes/cpp/codegreen/runtime.hpp +15 -0
  54. codegreen-0.5.0/codegreen/instrumentation/language_runtimes/java/codegreen/runtime/CodeGreenStandaloneRuntime.java +378 -0
  55. codegreen-0.5.0/codegreen/instrumentation/language_runtimes/python/codegreen_otlp_sink.py +293 -0
  56. codegreen-0.5.0/codegreen/instrumentation/language_runtimes/python/codegreen_prometheus_sink.py +303 -0
  57. codegreen-0.5.0/codegreen/instrumentation/language_runtimes/python/codegreen_runtime.py +2946 -0
  58. codegreen-0.5.0/codegreen/measurement/CMakeLists.txt +108 -0
  59. codegreen-0.5.0/codegreen/measurement/include/adapters/language_adapter.hpp +58 -0
  60. codegreen-0.5.0/codegreen/measurement/include/adapters/python_bridge_adapter.hpp +31 -0
  61. codegreen-0.5.0/codegreen/measurement/include/config.hpp +106 -0
  62. codegreen-0.5.0/codegreen/measurement/include/energy_code_mapper.hpp +201 -0
  63. codegreen-0.5.0/codegreen/measurement/include/energy_storage.hpp +113 -0
  64. codegreen-0.5.0/codegreen/measurement/include/measurement.hpp +40 -0
  65. codegreen-0.5.0/codegreen/measurement/include/measurement_engine.hpp +120 -0
  66. codegreen-0.5.0/codegreen/measurement/include/measurement_session.hpp +43 -0
  67. codegreen-0.5.0/codegreen/measurement/include/nemb/accuracy_validator.hpp +122 -0
  68. codegreen-0.5.0/codegreen/measurement/include/nemb/codegreen_energy.hpp +485 -0
  69. codegreen-0.5.0/codegreen/measurement/include/nemb/config_loader.hpp +94 -0
  70. codegreen-0.5.0/codegreen/measurement/include/nemb/core/energy_provider.hpp +278 -0
  71. codegreen-0.5.0/codegreen/measurement/include/nemb/core/measurement_coordinator.hpp +333 -0
  72. codegreen-0.5.0/codegreen/measurement/include/nemb/drivers/amd_gpu_provider.hpp +247 -0
  73. codegreen-0.5.0/codegreen/measurement/include/nemb/drivers/amd_rapl_provider.hpp +7 -0
  74. codegreen-0.5.0/codegreen/measurement/include/nemb/drivers/arm_energy_provider.hpp +7 -0
  75. codegreen-0.5.0/codegreen/measurement/include/nemb/drivers/darwin_ioreport_provider.hpp +72 -0
  76. codegreen-0.5.0/codegreen/measurement/include/nemb/drivers/darwin_kpc_provider.hpp +50 -0
  77. codegreen-0.5.0/codegreen/measurement/include/nemb/drivers/intel_rapl_provider.hpp +206 -0
  78. codegreen-0.5.0/codegreen/measurement/include/nemb/drivers/nvidia_gpu_provider.hpp +293 -0
  79. codegreen-0.5.0/codegreen/measurement/include/nemb/drivers/windows_emi_provider.hpp +55 -0
  80. codegreen-0.5.0/codegreen/measurement/include/nemb/hal/counter_manager.hpp +384 -0
  81. codegreen-0.5.0/codegreen/measurement/include/nemb/utils/non_blocking_file_reader.hpp +62 -0
  82. codegreen-0.5.0/codegreen/measurement/include/nemb/utils/precision_timer.hpp +249 -0
  83. codegreen-0.5.0/codegreen/measurement/src/energy_code_mapper.cpp +880 -0
  84. codegreen-0.5.0/codegreen/measurement/src/nemb/accuracy_validator.cpp +581 -0
  85. codegreen-0.5.0/codegreen/measurement/src/nemb/codegreen_energy.cpp +881 -0
  86. codegreen-0.5.0/codegreen/measurement/src/nemb/config_loader.cpp +207 -0
  87. codegreen-0.5.0/codegreen/measurement/src/nemb/core/energy_provider.cpp +161 -0
  88. codegreen-0.5.0/codegreen/measurement/src/nemb/core/measurement_coordinator.cpp +576 -0
  89. codegreen-0.5.0/codegreen/measurement/src/nemb/drivers/amd_gpu_provider.cpp +541 -0
  90. codegreen-0.5.0/codegreen/measurement/src/nemb/drivers/amd_rapl_provider.cpp +153 -0
  91. codegreen-0.5.0/codegreen/measurement/src/nemb/drivers/arm_energy_provider.cpp +100 -0
  92. codegreen-0.5.0/codegreen/measurement/src/nemb/drivers/darwin_ioreport_provider.cpp +292 -0
  93. codegreen-0.5.0/codegreen/measurement/src/nemb/drivers/darwin_kpc_provider.cpp +250 -0
  94. codegreen-0.5.0/codegreen/measurement/src/nemb/drivers/intel_rapl_provider.cpp +524 -0
  95. codegreen-0.5.0/codegreen/measurement/src/nemb/drivers/nvidia_gpu_provider.cpp +644 -0
  96. codegreen-0.5.0/codegreen/measurement/src/nemb/drivers/windows_emi_provider.cpp +255 -0
  97. codegreen-0.5.0/codegreen/measurement/src/nemb/hal/counter_manager.cpp +415 -0
  98. codegreen-0.5.0/codegreen/measurement/src/nemb/utils/non_blocking_file_reader.cpp +118 -0
  99. codegreen-0.5.0/codegreen/measurement/src/nemb/utils/precision_timer.cpp +432 -0
  100. codegreen-0.5.0/codegreen/measurement/tests/nemb_validation_test.cpp +547 -0
  101. codegreen-0.5.0/codegreen/measurement/tests/rapl_provider_test.cpp +411 -0
  102. {codegreen-0.4.8 → codegreen-0.5.0/codegreen.egg-info}/PKG-INFO +45 -7
  103. codegreen-0.5.0/codegreen.egg-info/SOURCES.txt +155 -0
  104. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen.egg-info/requires.txt +15 -0
  105. {codegreen-0.4.8 → codegreen-0.5.0}/pyproject.toml +21 -4
  106. {codegreen-0.4.8 → codegreen-0.5.0}/setup.py +10 -43
  107. codegreen-0.5.0/tests/test_callgraph_python.py +63 -0
  108. codegreen-0.5.0/tests/test_efg.py +890 -0
  109. codegreen-0.5.0/tests/test_examples.py +90 -0
  110. codegreen-0.5.0/tests/test_gpu_metrics.py +128 -0
  111. codegreen-0.5.0/tests/test_hotspot_taxonomy.py +126 -0
  112. codegreen-0.5.0/tests/test_hwcounters.py +210 -0
  113. codegreen-0.5.0/tests/test_instrumentation.py +1341 -0
  114. codegreen-0.5.0/tests/test_instrumentation_braces.py +241 -0
  115. codegreen-0.5.0/tests/test_line_sampling.py +140 -0
  116. codegreen-0.5.0/tests/test_report_audit.py +2677 -0
  117. codegreen-0.5.0/tests/test_sampling.py +141 -0
  118. codegreen-0.5.0/tests/test_timeline.py +113 -0
  119. codegreen-0.4.8/MANIFEST.in +0 -17
  120. codegreen-0.4.8/benchmark/validation/experiments.py +0 -247
  121. codegreen-0.4.8/codegreen/analysis/cfg/callgraph.py +0 -185
  122. codegreen-0.4.8/codegreen/analysis/cfg/energy_flow.py +0 -725
  123. codegreen-0.4.8/codegreen/cli/entrypoint.py +0 -29
  124. codegreen-0.4.8/codegreen/config.json +0 -201
  125. codegreen-0.4.8/codegreen/instrumentation/config.py +0 -73
  126. codegreen-0.4.8/codegreen/instrumentation/language_runtimes/java/codegreen/runtime/CodeGreenStandaloneRuntime.java +0 -44
  127. codegreen-0.4.8/codegreen/instrumentation/language_runtimes/python/codegreen_runtime.py +0 -1228
  128. codegreen-0.4.8/codegreen.egg-info/SOURCES.txt +0 -219
  129. codegreen-0.4.8/tests/test_instrumentation.py +0 -345
  130. codegreen-0.4.8/tests/test_report_audit.py +0 -567
  131. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/binarytrees/2.c +0 -161
  132. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/helloworld/1.c +0 -10
  133. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/knucleotide/1.c +0 -345
  134. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/mandelbrot/1-ffi.c +0 -160
  135. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/mandelbrot/1-mffi.c +0 -160
  136. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/nbody/2.c +0 -150
  137. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/nbody/5.c +0 -151
  138. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/nbody/8-i.c +0 -200
  139. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/nsieve/1.c +0 -34
  140. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/spectral-norm/3.c +0 -72
  141. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/spectral-norm/4.c +0 -231
  142. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/spectral-norm/5-im.c +0 -88
  143. codegreen-0.4.8/third_party/Programming-Language-Benchmarks/bench/algorithm/spectral-norm/6-im.c +0 -197
  144. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/aligned_indent.c +0 -7
  145. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/array.c +0 -14
  146. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/comment.c +0 -8
  147. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/compound_lit.c +0 -10
  148. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/cond.c +0 -10
  149. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/enum.c +0 -5
  150. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/expr.c +0 -12
  151. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/func.c +0 -33
  152. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/if_else.c +0 -59
  153. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/issue-1568.c +0 -6
  154. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/issue-2086.c +0 -3
  155. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/issue-4079.c +0 -7
  156. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/issue-4117.c +0 -6
  157. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/issue-4525.c +0 -23
  158. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/label.c +0 -7
  159. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/loop.c +0 -16
  160. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/no_braces.c +0 -13
  161. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/preproc_cond.c +0 -10
  162. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/preproc_func.c +0 -9
  163. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/string.c +0 -5
  164. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/struct.c +0 -11
  165. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/switch.c +0 -16
  166. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/ternary.c +0 -6
  167. codegreen-0.4.8/third_party/nvim-treesitter/tests/indent/c/unfinished_comment.c +0 -2
  168. codegreen-0.4.8/third_party/nvim-treesitter/tests/query/highlights/c/enums-as-constants.c +0 -21
  169. codegreen-0.4.8/third_party/tree-sitter/crates/cli/src/templates/PARSER_NAME.h +0 -16
  170. codegreen-0.4.8/third_party/tree-sitter/crates/cli/src/templates/py-binding.c +0 -35
  171. codegreen-0.4.8/third_party/tree-sitter/crates/generate/src/templates/alloc.h +0 -54
  172. codegreen-0.4.8/third_party/tree-sitter/crates/generate/src/templates/array.h +0 -291
  173. codegreen-0.4.8/third_party/tree-sitter/crates/highlight/include/tree_sitter/highlight.h +0 -83
  174. codegreen-0.4.8/third_party/tree-sitter/crates/tags/include/tree_sitter/tags.h +0 -98
  175. codegreen-0.4.8/third_party/tree-sitter/lib/CMakeLists.txt +0 -95
  176. codegreen-0.4.8/third_party/tree-sitter/lib/binding_web/lib/tree-sitter.c +0 -987
  177. codegreen-0.4.8/third_party/tree-sitter/lib/include/tree_sitter/api.h +0 -1481
  178. codegreen-0.4.8/third_party/tree-sitter/lib/src/alloc.c +0 -48
  179. codegreen-0.4.8/third_party/tree-sitter/lib/src/alloc.h +0 -41
  180. codegreen-0.4.8/third_party/tree-sitter/lib/src/array.h +0 -291
  181. codegreen-0.4.8/third_party/tree-sitter/lib/src/atomic.h +0 -68
  182. codegreen-0.4.8/third_party/tree-sitter/lib/src/clock.h +0 -146
  183. codegreen-0.4.8/third_party/tree-sitter/lib/src/error_costs.h +0 -11
  184. codegreen-0.4.8/third_party/tree-sitter/lib/src/get_changed_ranges.c +0 -523
  185. codegreen-0.4.8/third_party/tree-sitter/lib/src/get_changed_ranges.h +0 -36
  186. codegreen-0.4.8/third_party/tree-sitter/lib/src/host.h +0 -21
  187. codegreen-0.4.8/third_party/tree-sitter/lib/src/language.c +0 -293
  188. codegreen-0.4.8/third_party/tree-sitter/lib/src/language.h +0 -293
  189. codegreen-0.4.8/third_party/tree-sitter/lib/src/length.h +0 -52
  190. codegreen-0.4.8/third_party/tree-sitter/lib/src/lexer.c +0 -483
  191. codegreen-0.4.8/third_party/tree-sitter/lib/src/lexer.h +0 -54
  192. codegreen-0.4.8/third_party/tree-sitter/lib/src/lib.c +0 -12
  193. codegreen-0.4.8/third_party/tree-sitter/lib/src/node.c +0 -875
  194. codegreen-0.4.8/third_party/tree-sitter/lib/src/parser.c +0 -2293
  195. codegreen-0.4.8/third_party/tree-sitter/lib/src/parser.h +0 -286
  196. codegreen-0.4.8/third_party/tree-sitter/lib/src/point.h +0 -48
  197. codegreen-0.4.8/third_party/tree-sitter/lib/src/portable/endian.h +0 -241
  198. codegreen-0.4.8/third_party/tree-sitter/lib/src/query.c +0 -4349
  199. codegreen-0.4.8/third_party/tree-sitter/lib/src/reduce_action.h +0 -34
  200. codegreen-0.4.8/third_party/tree-sitter/lib/src/reusable_node.h +0 -95
  201. codegreen-0.4.8/third_party/tree-sitter/lib/src/stack.c +0 -912
  202. codegreen-0.4.8/third_party/tree-sitter/lib/src/stack.h +0 -133
  203. codegreen-0.4.8/third_party/tree-sitter/lib/src/subtree.c +0 -1034
  204. codegreen-0.4.8/third_party/tree-sitter/lib/src/subtree.h +0 -399
  205. codegreen-0.4.8/third_party/tree-sitter/lib/src/tree.c +0 -170
  206. codegreen-0.4.8/third_party/tree-sitter/lib/src/tree.h +0 -31
  207. codegreen-0.4.8/third_party/tree-sitter/lib/src/tree_cursor.c +0 -716
  208. codegreen-0.4.8/third_party/tree-sitter/lib/src/tree_cursor.h +0 -48
  209. codegreen-0.4.8/third_party/tree-sitter/lib/src/ts_assert.h +0 -11
  210. codegreen-0.4.8/third_party/tree-sitter/lib/src/unicode/ptypes.h +0 -1
  211. codegreen-0.4.8/third_party/tree-sitter/lib/src/unicode/umachine.h +0 -448
  212. codegreen-0.4.8/third_party/tree-sitter/lib/src/unicode/urename.h +0 -1
  213. codegreen-0.4.8/third_party/tree-sitter/lib/src/unicode/utf.h +0 -1
  214. codegreen-0.4.8/third_party/tree-sitter/lib/src/unicode/utf16.h +0 -733
  215. codegreen-0.4.8/third_party/tree-sitter/lib/src/unicode/utf8.h +0 -881
  216. codegreen-0.4.8/third_party/tree-sitter/lib/src/unicode.h +0 -75
  217. codegreen-0.4.8/third_party/tree-sitter/lib/src/wasm/stdlib.c +0 -113
  218. codegreen-0.4.8/third_party/tree-sitter/lib/src/wasm/wasm-stdlib.h +0 -1314
  219. codegreen-0.4.8/third_party/tree-sitter/lib/src/wasm_store.c +0 -1936
  220. codegreen-0.4.8/third_party/tree-sitter/lib/src/wasm_store.h +0 -31
  221. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/depends_on_column/scanner.c +0 -40
  222. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/epsilon_external_extra_tokens/scanner.c +0 -33
  223. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/epsilon_external_tokens/scanner.c +0 -33
  224. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/external_and_internal_anonymous_tokens/scanner.c +0 -66
  225. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/external_and_internal_tokens/scanner.c +0 -64
  226. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/external_extra_tokens/scanner.c +0 -44
  227. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/external_tokens/scanner.c +0 -121
  228. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/external_unicode_column_alignment/scanner.c +0 -87
  229. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/get_col_eof/scanner.c +0 -34
  230. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/get_col_should_hang_not_crash/scanner.c +0 -17
  231. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/inverted_external_token/scanner.c +0 -49
  232. codegreen-0.4.8/third_party/tree-sitter/test/fixtures/test_grammars/uses_current_column/scanner.c +0 -135
  233. codegreen-0.4.8/third_party/tree-sitter-c/CMakeLists.txt +0 -63
  234. codegreen-0.4.8/third_party/tree-sitter-c/bindings/c/tree_sitter/tree-sitter-c.h +0 -16
  235. codegreen-0.4.8/third_party/tree-sitter-c/bindings/python/tree_sitter_c/binding.c +0 -35
  236. codegreen-0.4.8/third_party/tree-sitter-c/bindings/swift/TreeSitterC/c.h +0 -16
  237. codegreen-0.4.8/third_party/tree-sitter-c/examples/cluster.c +0 -5446
  238. codegreen-0.4.8/third_party/tree-sitter-c/examples/malloc.c +0 -532
  239. codegreen-0.4.8/third_party/tree-sitter-c/examples/parser.c +0 -1283
  240. codegreen-0.4.8/third_party/tree-sitter-c/src/parser.c +0 -118872
  241. codegreen-0.4.8/third_party/tree-sitter-c/src/tree_sitter/alloc.h +0 -54
  242. codegreen-0.4.8/third_party/tree-sitter-c/src/tree_sitter/array.h +0 -291
  243. codegreen-0.4.8/third_party/tree-sitter-c/src/tree_sitter/parser.h +0 -286
  244. codegreen-0.4.8/third_party/tree-sitter-c/test/highlight/keywords.c +0 -6
  245. codegreen-0.4.8/third_party/tree-sitter-c/test/highlight/names.c +0 -33
  246. codegreen-0.4.8/third_party/tree-sitter-cpp/CMakeLists.txt +0 -58
  247. codegreen-0.4.8/third_party/tree-sitter-cpp/bindings/c/tree-sitter-cpp.h +0 -16
  248. codegreen-0.4.8/third_party/tree-sitter-cpp/bindings/python/tree_sitter_cpp/binding.c +0 -27
  249. codegreen-0.4.8/third_party/tree-sitter-cpp/bindings/swift/TreeSitterCPP/cpp.h +0 -16
  250. codegreen-0.4.8/third_party/tree-sitter-cpp/examples/marker-index.h +0 -131
  251. codegreen-0.4.8/third_party/tree-sitter-cpp/src/parser.c +0 -554548
  252. codegreen-0.4.8/third_party/tree-sitter-cpp/src/scanner.c +0 -148
  253. codegreen-0.4.8/third_party/tree-sitter-cpp/src/tree_sitter/alloc.h +0 -54
  254. codegreen-0.4.8/third_party/tree-sitter-cpp/src/tree_sitter/array.h +0 -291
  255. codegreen-0.4.8/third_party/tree-sitter-cpp/src/tree_sitter/parser.h +0 -286
  256. codegreen-0.4.8/third_party/tree-sitter-java/CMakeLists.txt +0 -58
  257. codegreen-0.4.8/third_party/tree-sitter-java/bindings/c/tree-sitter-java.h +0 -16
  258. codegreen-0.4.8/third_party/tree-sitter-java/bindings/python/tree_sitter_java/binding.c +0 -27
  259. codegreen-0.4.8/third_party/tree-sitter-java/bindings/swift/TreeSitterJava/java.h +0 -16
  260. codegreen-0.4.8/third_party/tree-sitter-java/src/parser.c +0 -76760
  261. codegreen-0.4.8/third_party/tree-sitter-java/src/tree_sitter/alloc.h +0 -54
  262. codegreen-0.4.8/third_party/tree-sitter-java/src/tree_sitter/array.h +0 -291
  263. codegreen-0.4.8/third_party/tree-sitter-java/src/tree_sitter/parser.h +0 -266
  264. codegreen-0.4.8/third_party/tree-sitter-python/CMakeLists.txt +0 -60
  265. codegreen-0.4.8/third_party/tree-sitter-python/bindings/c/tree-sitter-python.h +0 -16
  266. codegreen-0.4.8/third_party/tree-sitter-python/bindings/python/tree_sitter_python/binding.c +0 -27
  267. codegreen-0.4.8/third_party/tree-sitter-python/bindings/swift/TreeSitterPython/python.h +0 -16
  268. codegreen-0.4.8/third_party/tree-sitter-python/src/parser.c +0 -130198
  269. codegreen-0.4.8/third_party/tree-sitter-python/src/scanner.c +0 -436
  270. codegreen-0.4.8/third_party/tree-sitter-python/src/tree_sitter/alloc.h +0 -54
  271. codegreen-0.4.8/third_party/tree-sitter-python/src/tree_sitter/array.h +0 -291
  272. codegreen-0.4.8/third_party/tree-sitter-python/src/tree_sitter/parser.h +0 -266
  273. {codegreen-0.4.8 → codegreen-0.5.0}/LICENSE +0 -0
  274. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/__init__.py +0 -0
  275. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/_workload_gpt2.py +0 -0
  276. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/_workload_gpt2_session.py +0 -0
  277. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/_workload_gpt2_session_staged.py +0 -0
  278. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/cg_modes_compare.py +0 -0
  279. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/compilers.py +0 -0
  280. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/suites/__init__.py +0 -0
  281. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/suites/base.py +0 -0
  282. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/suites/dacapo.py +0 -0
  283. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/suites/perfopt.py +0 -0
  284. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/suites/renaissance.py +0 -0
  285. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/validation/__init__.py +0 -0
  286. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/validation/analysis.py +0 -0
  287. {codegreen-0.4.8 → codegreen-0.5.0}/benchmark/validation/reporting.py +0 -0
  288. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analysis/__init__.py +0 -0
  289. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analysis/_ts_java.py +0 -0
  290. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analysis/cfg/__init__.py +0 -0
  291. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analysis/cfg/builder.py +0 -0
  292. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analysis/cfg/dataflow.py +0 -0
  293. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analysis/cfg/features.py +0 -0
  294. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analysis/cfg/pdg.py +0 -0
  295. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analysis/cfg/types.py +0 -0
  296. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analysis/cfg/visualization.py +0 -0
  297. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analyzer/__init__.py +0 -0
  298. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/analyzer/plot.py +0 -0
  299. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/cli/__init__.py +0 -0
  300. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/bridge_analyze.py +0 -0
  301. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/engine.py +0 -0
  302. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/instrumentation/language_runtimes/java/codegreen/runtime/CodeGreenRuntime.java +0 -0
  303. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/utils/__init__.py +0 -0
  304. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/utils/binary.py +0 -0
  305. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen/utils/platform.py +0 -0
  306. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen.egg-info/dependency_links.txt +0 -0
  307. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen.egg-info/entry_points.txt +0 -0
  308. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen.egg-info/not-zip-safe +0 -0
  309. {codegreen-0.4.8 → codegreen-0.5.0}/codegreen.egg-info/top_level.txt +0 -0
  310. {codegreen-0.4.8 → codegreen-0.5.0}/requirements.txt +0 -0
  311. {codegreen-0.4.8 → codegreen-0.5.0}/setup.cfg +0 -0
@@ -46,15 +46,8 @@ include_directories(${CMAKE_SOURCE_DIR}/codegreen/measurement/include)
46
46
  add_subdirectory(codegreen/measurement)
47
47
 
48
48
 
49
- # Copy config to build dir
50
- if(EXISTS "${CMAKE_SOURCE_DIR}/config/codegreen.json")
51
- file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/config)
52
- configure_file(
53
- ${CMAKE_SOURCE_DIR}/config/codegreen.json
54
- ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/config/codegreen.json
55
- COPYONLY
56
- )
57
- endif()
49
+ # NEMB finds its config at <library dir>/../config.json; place the bundled one there so the build tree works
50
+ configure_file(${CMAKE_SOURCE_DIR}/codegreen/config.json ${CMAKE_BINARY_DIR}/config.json COPYONLY)
58
51
 
59
52
  # Dev-install: copy NEMB library to project root for pip editable installs
60
53
  add_custom_target(dev-install ALL
@@ -73,17 +66,13 @@ install(TARGETS codegreen-nemb
73
66
  RUNTIME DESTINATION lib
74
67
  )
75
68
 
69
+ install(FILES ${CMAKE_SOURCE_DIR}/codegreen/config.json DESTINATION share/codegreen) # <prefix>/lib/../share/codegreen
70
+
76
71
  install(FILES
77
72
  ${CMAKE_SOURCE_DIR}/codegreen/instrumentation/language_runtimes/python/codegreen_runtime.py
78
73
  DESTINATION bin/runtime
79
74
  )
80
75
 
81
- if(EXISTS "${CMAKE_SOURCE_DIR}/config/codegreen.json")
82
- install(FILES ${CMAKE_SOURCE_DIR}/config/codegreen.json
83
- DESTINATION bin/config
84
- )
85
- endif()
86
-
87
76
  set(CPACK_PACKAGE_NAME "CodeGreen")
88
77
  set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
89
78
  set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Energy-aware software development tool")
@@ -0,0 +1,16 @@
1
+ include README.md LICENSE requirements.txt pyproject.toml CMakeLists.txt setup.py
2
+
3
+ recursive-include codegreen/measurement CMakeLists.txt *.cpp *.c *.h *.hpp
4
+ recursive-include codegreen/instrumentation/language_runtimes *.py *.h *.hpp *.java
5
+ recursive-include codegreen/instrumentation/configs *.json
6
+ include codegreen/config.json
7
+
8
+ global-exclude *.pyc
9
+ global-exclude __pycache__
10
+ global-exclude *.so
11
+ global-exclude *.dylib
12
+ global-exclude *.dll
13
+ global-exclude *.jar
14
+ global-exclude *.class
15
+ global-exclude .DS_Store
16
+ global-exclude *.o
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codegreen
3
- Version: 0.4.8
3
+ Version: 0.5.0
4
4
  Summary: Know the true energy cost of your code
5
5
  Author-email: Saurabhsingh Rajput <saurabh@dal.ca>
6
6
  Maintainer-email: Saurabhsingh Rajput <saurabh@dal.ca>
@@ -413,6 +413,7 @@ Requires-Dist: packaging>=21.0
413
413
  Requires-Dist: markdown-it-py<4.0.0,>=3.0.0
414
414
  Requires-Dist: tree-sitter<0.26,>=0.21
415
415
  Requires-Dist: tree-sitter-language-pack<1.0,>=0.7
416
+ Requires-Dist: tree-sitter-java<0.24,>=0.23
416
417
  Provides-Extra: dev
417
418
  Requires-Dist: pytest>=7.0.0; extra == "dev"
418
419
  Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
@@ -429,6 +430,17 @@ Provides-Extra: viz
429
430
  Requires-Dist: matplotlib>=3.5.0; extra == "viz"
430
431
  Requires-Dist: pandas>=1.4.0; extra == "viz"
431
432
  Requires-Dist: plotly>=5.10.0; extra == "viz"
433
+ Provides-Extra: otlp
434
+ Requires-Dist: opentelemetry-api>=1.20.0; extra == "otlp"
435
+ Requires-Dist: opentelemetry-sdk>=1.20.0; extra == "otlp"
436
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.20.0; extra == "otlp"
437
+ Provides-Extra: prometheus
438
+ Requires-Dist: prometheus-client>=0.20.0; extra == "prometheus"
439
+ Provides-Extra: all
440
+ Requires-Dist: opentelemetry-api>=1.20.0; extra == "all"
441
+ Requires-Dist: opentelemetry-sdk>=1.20.0; extra == "all"
442
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.20.0; extra == "all"
443
+ Requires-Dist: prometheus-client>=0.20.0; extra == "all"
432
444
  Dynamic: license-file
433
445
 
434
446
  <p align="center">
@@ -436,7 +448,12 @@ Dynamic: license-file
436
448
  <img src="docs/website/docs/assets/codegreen_logo_white.svg#gh-dark-mode-only" width="200" alt="CodeGreen Logo">
437
449
  </p>
438
450
 
439
- [![DOI](https://zenodo.org/badge/942273936.svg)](https://doi.org/10.5281/zenodo.18371771)
451
+ [![PyPI](https://img.shields.io/pypi/v/codegreen)](https://pypi.org/project/codegreen/)
452
+ [![PyPI Downloads](https://static.pepy.tech/personalized-badge/codegreen?period=total&units=NONE&left_color=GREY&right_color=GREEN&left_text=downloads)](https://pepy.tech/projects/codegreen)
453
+ [![GitHub stars](https://img.shields.io/github/stars/SMART-Dal/codegreen)](https://github.com/SMART-Dal/codegreen/stargazers)
454
+ [![License](https://img.shields.io/badge/license-MPL%202.0-blue)](LICENSE)
455
+ [![Platform](https://img.shields.io/badge/platform-linux%20%7C%20macOS%20%7C%20windows-lightgrey)](https://pypi.org/project/codegreen/)
456
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.18371771.svg)](https://doi.org/10.5281/zenodo.18371771)
440
457
 
441
458
  # CodeGreen - Garage for Energy Measurement and Optimization
442
459
 
@@ -452,6 +469,8 @@ pip install codegreen
452
469
 
453
470
  Pre-built wheels available for Linux x86_64 and macOS ARM64 (Apple Silicon). Includes the native NEMB energy measurement backend.
454
471
 
472
+ Optional telemetry exporters for `codegreen monitor`: `pip install "codegreen[otlp]"` (OpenTelemetry/OTLP) or `pip install "codegreen[prometheus]"`.
473
+
455
474
  ### From source (recommended for development)
456
475
 
457
476
  ```bash
@@ -509,6 +528,23 @@ codegreen measure python script.py -g fine --json
509
528
  codegreen measure python script.py -g fine --export-plot energy.html
510
529
  ```
511
530
 
531
+ ### Project profiling, monitoring and timelines
532
+
533
+ ```bash
534
+ # Per-function hotspots for a whole project (build once, run, attribute)
535
+ codegreen project python ./src -r "python main.py" -s "**/*.py"
536
+
537
+ # GPU work attributed to the launching function (torch/CUDA)
538
+ codegreen project python ./src -r "python train.py" --sync-device cuda
539
+
540
+ # Continuous host or per-PID sampling, optional OTLP / Prometheus export
541
+ codegreen monitor -d 30 -o energy.jsonl
542
+ codegreen monitor --pid 1234 --exporter prometheus --prometheus-port 9464
543
+
544
+ # Power, stacks, GC and GPU kernels on one axis for ui.perfetto.dev
545
+ codegreen timeline --nemb nemb.json --jfr run.json --out trace.json
546
+ ```
547
+
512
548
  ### Manual measurement from Python (Session API)
513
549
 
514
550
  For span-based measurement of arbitrary code regions, import `codegreen.Session` directly — no CLI, no AST instrumentation:
@@ -546,7 +582,7 @@ codegreen analyze python script.py --save-instrumented
546
582
  ### Benchmark validation (against perf RAPL ground truth)
547
583
 
548
584
  ```bash
549
- codegreen benchmark -p nbody spectralnorm -l python -r 5 --profilers codegreen perf
585
+ codegreen benchmark -p nbody -p spectralnorm -l python -r 5 --profiler codegreen --profiler perf
550
586
  ```
551
587
 
552
588
  ## Output formats
@@ -557,7 +593,7 @@ JSON (default for `--json`), CSV, Markdown table, and text summary. The JSON out
557
593
 
558
594
  Adding a new language requires only a JSON config file in `codegreen/instrumentation/configs/` plus the tree-sitter grammar. No Python code changes needed.
559
595
 
560
- Currently supported: Python, C, C++, Java. JavaScript config exists but is not yet exposed via CLI.
596
+ Currently supported: Python, C, C++, Java, JavaScript. Functions that cannot be framed safely (async, generators, coroutines, C++ `constexpr`) are reported as `skipped_functions` rather than instrumented.
561
597
 
562
598
  ## Benchmarking
563
599
 
@@ -574,11 +610,11 @@ bash scripts/generate_comparison_artifacts.sh docs/benchmarks/
574
610
 
575
611
  ## Energy Flow Graph (EFG)
576
612
 
577
- CodeGreen includes an Energy Flow Graph module (`codegreen/analysis/cfg/`) that builds energy-annotated control flow graphs from source code:
613
+ CodeGreen includes an Energy Flow Graph module (`codegreen/analysis/efg/`) that builds energy-annotated control flow graphs from source code:
578
614
 
579
615
  ```python
580
616
  from codegreen.analysis.cfg.builder import build_per_method_cfgs
581
- from codegreen.analysis.cfg.energy_flow import build_efg, efg_to_dot, efg_to_text
617
+ from codegreen.analysis.efg import build_efg, efg_to_dot, efg_to_text
582
618
 
583
619
  cfgs = build_per_method_cfgs(java_source_code)
584
620
  efg = build_efg(cfg_nodes, cfg_edges, "ClassName.method", "File.java", codegreen_data)
@@ -587,6 +623,8 @@ print(efg_to_text(efg)) # compact format for LLM prompts
587
623
 
588
624
  Features: Ball & Larus branch heuristics, SCC-based hot path computation, three-level accuracy annotations (MEASURED/ESTIMATED/INFERRED), configurable via `EFGConfig`.
589
625
 
626
+ See `codegreen/analysis/efg/README.md` for the module layout, a runnable example (`python -m codegreen.analysis.efg.example.demo`), and the current list of known issues. `codegreen.analysis.cfg.energy_flow` still resolves as a back-compat shim.
627
+
590
628
  ## Architecture
591
629
 
592
630
  - **C++ NEMB backend**: platform-aware energy measurement (RAPL on Linux, IOReport on macOS, EMI on Windows), sub-microsecond timestamping, background polling with lock-free ring buffers
@@ -599,7 +637,7 @@ Features: Ball & Larus branch heuristics, SCC-based hot path computation, three-
599
637
  ```bash
600
638
  # Fail pipeline if energy exceeds budget
601
639
  codegreen run --budget 10.0 --json -- python tests/benchmark.py
602
- # Exit code 1 if mean energy > 10 Joules
640
+ # Exit code 1 if mean energy > 10 Joules, 3 if the measurement is invalid (see validity.reasons)
603
641
  ```
604
642
 
605
643
  ## Upgrading
@@ -3,7 +3,12 @@
3
3
  <img src="docs/website/docs/assets/codegreen_logo_white.svg#gh-dark-mode-only" width="200" alt="CodeGreen Logo">
4
4
  </p>
5
5
 
6
- [![DOI](https://zenodo.org/badge/942273936.svg)](https://doi.org/10.5281/zenodo.18371771)
6
+ [![PyPI](https://img.shields.io/pypi/v/codegreen)](https://pypi.org/project/codegreen/)
7
+ [![PyPI Downloads](https://static.pepy.tech/personalized-badge/codegreen?period=total&units=NONE&left_color=GREY&right_color=GREEN&left_text=downloads)](https://pepy.tech/projects/codegreen)
8
+ [![GitHub stars](https://img.shields.io/github/stars/SMART-Dal/codegreen)](https://github.com/SMART-Dal/codegreen/stargazers)
9
+ [![License](https://img.shields.io/badge/license-MPL%202.0-blue)](LICENSE)
10
+ [![Platform](https://img.shields.io/badge/platform-linux%20%7C%20macOS%20%7C%20windows-lightgrey)](https://pypi.org/project/codegreen/)
11
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.18371771.svg)](https://doi.org/10.5281/zenodo.18371771)
7
12
 
8
13
  # CodeGreen - Garage for Energy Measurement and Optimization
9
14
 
@@ -19,6 +24,8 @@ pip install codegreen
19
24
 
20
25
  Pre-built wheels available for Linux x86_64 and macOS ARM64 (Apple Silicon). Includes the native NEMB energy measurement backend.
21
26
 
27
+ Optional telemetry exporters for `codegreen monitor`: `pip install "codegreen[otlp]"` (OpenTelemetry/OTLP) or `pip install "codegreen[prometheus]"`.
28
+
22
29
  ### From source (recommended for development)
23
30
 
24
31
  ```bash
@@ -76,6 +83,23 @@ codegreen measure python script.py -g fine --json
76
83
  codegreen measure python script.py -g fine --export-plot energy.html
77
84
  ```
78
85
 
86
+ ### Project profiling, monitoring and timelines
87
+
88
+ ```bash
89
+ # Per-function hotspots for a whole project (build once, run, attribute)
90
+ codegreen project python ./src -r "python main.py" -s "**/*.py"
91
+
92
+ # GPU work attributed to the launching function (torch/CUDA)
93
+ codegreen project python ./src -r "python train.py" --sync-device cuda
94
+
95
+ # Continuous host or per-PID sampling, optional OTLP / Prometheus export
96
+ codegreen monitor -d 30 -o energy.jsonl
97
+ codegreen monitor --pid 1234 --exporter prometheus --prometheus-port 9464
98
+
99
+ # Power, stacks, GC and GPU kernels on one axis for ui.perfetto.dev
100
+ codegreen timeline --nemb nemb.json --jfr run.json --out trace.json
101
+ ```
102
+
79
103
  ### Manual measurement from Python (Session API)
80
104
 
81
105
  For span-based measurement of arbitrary code regions, import `codegreen.Session` directly — no CLI, no AST instrumentation:
@@ -113,7 +137,7 @@ codegreen analyze python script.py --save-instrumented
113
137
  ### Benchmark validation (against perf RAPL ground truth)
114
138
 
115
139
  ```bash
116
- codegreen benchmark -p nbody spectralnorm -l python -r 5 --profilers codegreen perf
140
+ codegreen benchmark -p nbody -p spectralnorm -l python -r 5 --profiler codegreen --profiler perf
117
141
  ```
118
142
 
119
143
  ## Output formats
@@ -124,7 +148,7 @@ JSON (default for `--json`), CSV, Markdown table, and text summary. The JSON out
124
148
 
125
149
  Adding a new language requires only a JSON config file in `codegreen/instrumentation/configs/` plus the tree-sitter grammar. No Python code changes needed.
126
150
 
127
- Currently supported: Python, C, C++, Java. JavaScript config exists but is not yet exposed via CLI.
151
+ Currently supported: Python, C, C++, Java, JavaScript. Functions that cannot be framed safely (async, generators, coroutines, C++ `constexpr`) are reported as `skipped_functions` rather than instrumented.
128
152
 
129
153
  ## Benchmarking
130
154
 
@@ -141,11 +165,11 @@ bash scripts/generate_comparison_artifacts.sh docs/benchmarks/
141
165
 
142
166
  ## Energy Flow Graph (EFG)
143
167
 
144
- CodeGreen includes an Energy Flow Graph module (`codegreen/analysis/cfg/`) that builds energy-annotated control flow graphs from source code:
168
+ CodeGreen includes an Energy Flow Graph module (`codegreen/analysis/efg/`) that builds energy-annotated control flow graphs from source code:
145
169
 
146
170
  ```python
147
171
  from codegreen.analysis.cfg.builder import build_per_method_cfgs
148
- from codegreen.analysis.cfg.energy_flow import build_efg, efg_to_dot, efg_to_text
172
+ from codegreen.analysis.efg import build_efg, efg_to_dot, efg_to_text
149
173
 
150
174
  cfgs = build_per_method_cfgs(java_source_code)
151
175
  efg = build_efg(cfg_nodes, cfg_edges, "ClassName.method", "File.java", codegreen_data)
@@ -154,6 +178,8 @@ print(efg_to_text(efg)) # compact format for LLM prompts
154
178
 
155
179
  Features: Ball & Larus branch heuristics, SCC-based hot path computation, three-level accuracy annotations (MEASURED/ESTIMATED/INFERRED), configurable via `EFGConfig`.
156
180
 
181
+ See `codegreen/analysis/efg/README.md` for the module layout, a runnable example (`python -m codegreen.analysis.efg.example.demo`), and the current list of known issues. `codegreen.analysis.cfg.energy_flow` still resolves as a back-compat shim.
182
+
157
183
  ## Architecture
158
184
 
159
185
  - **C++ NEMB backend**: platform-aware energy measurement (RAPL on Linux, IOReport on macOS, EMI on Windows), sub-microsecond timestamping, background polling with lock-free ring buffers
@@ -166,7 +192,7 @@ Features: Ball & Larus branch heuristics, SCC-based hot path computation, three-
166
192
  ```bash
167
193
  # Fail pipeline if energy exceeds budget
168
194
  codegreen run --budget 10.0 --json -- python tests/benchmark.py
169
- # Exit code 1 if mean energy > 10 Joules
195
+ # Exit code 1 if mean energy > 10 Joules, 3 if the measurement is invalid (see validity.reasons)
170
196
  ```
171
197
 
172
198
  ## Upgrading
@@ -1,9 +1,9 @@
1
1
  """Entry point for `python3 -m benchmark`."""
2
2
  import argparse
3
- import sys
4
3
  from pathlib import Path
5
4
  from benchmark.config import BenchmarkConfig
6
5
  from benchmark.harness import BenchmarkHarness
6
+ from benchmark.suites.benchmarksgame import BenchmarksgameSuite
7
7
 
8
8
  def main():
9
9
  parser = argparse.ArgumentParser(description="CodeGreen Energy Benchmark Suite")
@@ -18,27 +18,23 @@ def main():
18
18
  args = parser.parse_args()
19
19
 
20
20
  config = BenchmarkConfig.from_yaml(args.config) if args.config else BenchmarkConfig.default()
21
- harness = BenchmarkHarness(config)
21
+ suite = BenchmarksgameSuite(Path(config.benchmarks_dir) if config.benchmarks_dir else None,
22
+ languages=args.languages, problems=args.problems, sizes=args.sizes)
23
+ harness = BenchmarkHarness(suite, repetitions=args.repetitions, warmup_runs=config.warmup_runs,
24
+ timeout_seconds=config.timeout_seconds, min_runtime_seconds=config.min_runtime_seconds)
22
25
 
23
26
  try:
24
- collector = harness.run_suite(
25
- problems=args.problems,
26
- languages=args.languages,
27
- sizes=args.sizes,
28
- profilers=args.profilers,
29
- repetitions=args.repetitions,
30
- )
27
+ collector = harness.run_suite(profilers=args.profilers, repetitions=args.repetitions)
31
28
  summaries = collector.summarize_all()
32
29
  print(f"\n{'='*60}")
33
30
  print(f"Results: {len(collector.results)} runs")
34
31
  print(f"{'='*60}")
35
32
  for key, data in sorted(summaries.items()):
36
- e = data.get("energy")
37
- t = data.get("time")
38
- valid = data.get("valid_runs", 0)
39
- total = data.get("total_runs", 0)
33
+ e, t = data["energy"], data["time"]
40
34
  energy_str = f"{e.mean:.4f} +/- {e.std:.4f} J" if e else "N/A"
41
- print(f" {key}: energy={energy_str} time={t.mean:.3f}s valid={valid}/{total}")
35
+ time_str = f"{t.mean:.3f}s" if t else "N/A"
36
+ print(f" {key}: energy={energy_str} time={time_str} valid={data['valid_runs']}/{data['total_runs']}"
37
+ f" invalid={data['invalid_reasons']}")
42
38
 
43
39
  if args.output:
44
40
  collector.to_json(args.output)
@@ -15,7 +15,7 @@ class SystemState:
15
15
  cpu_model: str = ""
16
16
  cpu_governor: str = ""
17
17
  kernel_version: str = ""
18
- rapl_domains: List[str] = field(default_factory=list)
18
+ power_events: List[str] = field(default_factory=list)
19
19
 
20
20
  @classmethod
21
21
  def capture(cls) -> "SystemState":
@@ -34,17 +34,8 @@ class SystemState:
34
34
  state.cpu_governor = f.read().strip()
35
35
  except (FileNotFoundError, OSError):
36
36
  pass
37
- import os
38
- for i in range(10):
39
- path = f"/sys/class/powercap/intel-rapl:0:{i}/name"
40
- if os.path.exists(path):
41
- try:
42
- with open(path) as f:
43
- state.rapl_domains.append(f.read().strip())
44
- except OSError:
45
- pass
46
- else:
47
- break
37
+ from benchmark.profilers import perf_power_events
38
+ state.power_events = perf_power_events()
48
39
  return state
49
40
 
50
41
  @dataclass
@@ -66,7 +57,7 @@ class RunResult:
66
57
  language: str
67
58
  size: str
68
59
  profiler: str
69
- energy_joules: float
60
+ energy_joules: Optional[float]
70
61
  time_seconds: float
71
62
  output_valid: bool
72
63
  repetition: int = 0
@@ -74,6 +65,31 @@ class RunResult:
74
65
  suite: str = "benchmarksgame"
75
66
  timestamp: datetime = field(default_factory=datetime.now)
76
67
  checkpoints: List[Dict[str, Any]] = field(default_factory=list)
68
+ validity: Optional[Dict[str, Any]] = None
69
+
70
+ @property
71
+ def measurement_valid(self) -> bool:
72
+ """No fatal validity reason; profilers without a validity contract (perf, native) report None."""
73
+ return self.validity is None or self.validity["status"] == "valid"
74
+
75
+ # perf power events summed as the CPU-scope truth, mirroring the RAPL adapters' top-level domain rule: the first set
76
+ # whose first event the power PMU offers wins (psys supersedes package + dram), using the offered events of that set.
77
+ PERF_CPU_EVENT_SETS = (("energy-psys",), ("energy-pkg", "energy-ram"))
78
+
79
+ @dataclass
80
+ class ValidityTolerances:
81
+ """Expectations of benchmark.validation.experiments.ValidityExperiment. Windows are in sampler intervals
82
+ (sampler.interval_ms of the run itself); a window below min_window_samples - 1 intervals must be flagged
83
+ TOTAL_BELOW_RESOLUTION, one at or above min_window_samples + 1 must not, the two intervals between are either (one
84
+ late reading costs the window a reading). A sampler allowed on fewer than min_affinity_cpus CPUs must raise the
85
+ AFFINITY_SINGLE_CPU warning and may be SAMPLER_STARVED, as may any run whose reading gaps exceed codegreen's gap policy.
86
+ cv_max_pct maps a minimum window (s) to the largest CV (%) of valid energies across repetitions."""
87
+ min_window_samples: int = 2
88
+ min_affinity_cpus: int = 2
89
+ exclusive_rel_tol: float = 0.01
90
+ run_vs_perf_rel_tol: float = 0.03
91
+ run_vs_perf_min_duration_s: float = 1.0
92
+ cv_max_pct: Dict[float, float] = field(default_factory=lambda: {1.0: 5.0, 0.1: 10.0})
77
93
 
78
94
  @dataclass
79
95
  class BenchmarkConfig:
@@ -3,7 +3,6 @@ import math
3
3
  import subprocess
4
4
  import sys
5
5
  import time
6
- from pathlib import Path
7
6
  from typing import Callable, List, Optional
8
7
 
9
8
  from benchmark.config import RunResult
@@ -49,11 +48,13 @@ class BenchmarkHarness:
49
48
  """Run a single task with a single profiler."""
50
49
  reps = repetitions or self.repetitions
51
50
  profiler = get_profiler(profiler_name)
51
+ if not profiler.is_available():
52
+ self.progress_callback(f" Skipping {task.name} [{profiler_name}]: {profiler.unavailable_reason()}")
53
+ return []
54
+ # Build the task (compile, construct run command); the build may name the source anew (Java public class)
55
+ task = self.suite.build(task)
52
56
  if hasattr(profiler, 'set_source') and task.source_file:
53
57
  profiler.set_source(task.source_file, task.language)
54
-
55
- # Build the task (compile, construct run command)
56
- task = self.suite.build(task)
57
58
  if not task.run_command:
58
59
  self.progress_callback(f" No run command for {task.name}, skipping")
59
60
  return []
@@ -96,6 +97,7 @@ class BenchmarkHarness:
96
97
  variant=task.variant,
97
98
  suite=self.suite.name,
98
99
  checkpoints=profile_result.checkpoints,
100
+ validity=profile_result.validity,
99
101
  )
100
102
  results.append(result)
101
103
  self.collector.add(result)
@@ -105,6 +107,22 @@ class BenchmarkHarness:
105
107
  self.progress_callback(f" Run {i+1} failed: {e}")
106
108
  return results
107
109
 
110
+ def tasks(self, problem: str, languages: List[str], sizes: Optional[List[str]] = None) -> List[Task]:
111
+ """Tasks of one problem at the given languages and sizes (suite defaults when None); the default suite is
112
+ benchmarksgame."""
113
+ if self.suite is None:
114
+ from benchmark.suites.benchmarksgame import BenchmarksgameSuite
115
+ self.suite = BenchmarksgameSuite()
116
+ found = self.suite.discover({"problems": [problem], "languages": languages, "sizes": sizes})
117
+ if not found:
118
+ raise ValueError(f"{self.suite.name} has no task for {problem} in {languages} at sizes {sizes}")
119
+ return found
120
+
121
+ def run_problem(self, problem: str, languages: List[str], sizes: List[str], profilers: List[str],
122
+ repetitions: Optional[int] = None) -> List[RunResult]:
123
+ """Run one problem for every language, size and profiler; returns the results of all runs."""
124
+ return [r for t in self.tasks(problem, languages, sizes) for p in profilers for r in self.run_task(t, p, repetitions)]
125
+
108
126
  def run_suite(self, profilers: Optional[List[str]] = None,
109
127
  repetitions: Optional[int] = None,
110
128
  filters: Optional[dict] = None) -> ResultCollector: