mlco2 / codecarbon

Track emissions from Compute and recommend ways to reduce their impact on the environment.
https://mlco2.github.io/codecarbon
MIT License
1.01k stars 158 forks source link

Codecrbon for Java Code emission tracking? #426

Open codeastra2 opened 12 months ago

codeastra2 commented 12 months ago

I want to implement a new feature: using codecarbon for tracking java code emissions, java code is very widely adopted and many developers would like to get stats on the emission stats of the java programs. In particular I wanted to develop a plugin in intellij when running the unit/integration tests we would also get the carbon emissions by running these tests, I think it will be a very useful feature.

Implementation

  1. I was looking at Jython interpreter to install the codecarbon package and thereupon call the tracking start and stop functions from the java code to track the emissions .
  2. However, jython only supports till python2.7 and codecarbon is from python 3 I believe so this approach seems not possible.

I am open to ideas on how to implement this , and will develop this . Please do let me know, thanks!

benoit-cty commented 12 months ago

Hello,

Nice idea, CodeCarbon could be use as a command line tools with codecarbon monitor. Maybe it could help ? I think for your usecase we need to add an option to send the id of the process to monitor only the tests.

FYI, Python 2.7 is deprecated since January 2020 so Jython is probably dead...

codeastra2 commented 11 months ago

Hi,

Yes command line tool I can use to implement, however even for that I would need to pip install right? I could still need some python support and manual steps of installation for that, if there is no other way I can do that but, is there a pure java solution for this? @benoit-cty. Thanks so much for your reply!

benoit-cty commented 11 months ago

Hello, maybe you should have a look at https://github.com/aservet1/jRAPL?

inimaz commented 10 months ago

@codeastra2 maybe you can check as well this https://github.com/mlco2/codecarbon/issues/436#issuecomment-1680234254

I managed to launch a background task in VSCode that launches codecarbon. Maybe there is a similar concept in intelIJ?

Note: this script still needs you to have installed python + codecarbon in your machine