Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using recommended PyMonsoon fork returns huge values for current #10

Open
odmnk opened this issue Jul 24, 2021 · 4 comments
Open

Using recommended PyMonsoon fork returns huge values for current #10

odmnk opened this issue Jul 24, 2021 · 4 comments

Comments

@odmnk
Copy link

odmnk commented Jul 24, 2021

To install Physalia the GitHub installation section says to install this fork of PyMonsoon before running pip install physalia.

However, if I run Physalia using this version of the PyMonsoon library I get measurements that do not make sense. Profiling for 15 seconds gives me an average current of 27882.41 mA. Which is impossible.

If I instead use the original PyMonsoon library in combination with Physalia my average mA for a 15 seconds profiling session is 208.97 mA. This is acceptable.

The problem is that when I use the original PyMonsoon library I sometimes get the following error when using it with Physalia: msoon/PyMonsoon#35

My questions:

  1. Are these huge, unrealistic currents a known issue?
  2. Why the use of the fork is recommended instead of the original PyMonsoon library? The fork is around 90 commits behind upstream?
  3. If we install Physalia as instructed here it will install the original PyMonsoon library instead of the fork. Which one is preferred?

Thanks a lot!

@luiscruz
Copy link
Member

Hi @odmnk !
thanks for using physalia. I’m on leave until august 9. Is this urgent or can I take when I get back to the office?

@odmnk
Copy link
Author

odmnk commented Jul 24, 2021

Hi Luis,

Thank you so much for your quick reply! Also thanks a lot for creating Physalia, really makes using the Monsoon a lot easier ;).

It is not super urgent as I understand that you want to enjoy your summer holiday as well.

The thing is that I'm a MSc student working on my thesis. Part of my thesis is an experiment investigating the effects of certain web performance optimizations on the energy consumption of mobile web apps. To do this I wanted to use the Monsoon. However, if I don't get it work I will probably switch to a software based profiler.

I will do some more debugging before I will do that though. I will let you know if I find a fix!

Cheers

@odmnk
Copy link
Author

odmnk commented Jul 25, 2021

Hmm, no luck yet. I created a document describing how to reproduce the issue. I want to share it here before I forget :p. Maybe other people are interested as well.

  1. Create a new directory, create a Python 3 virtualenv and install Physalia as described in the README.md:
$ mkdir monsoon_test; cd monsoon_test
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install git+https://github.com/luiscruz/PyMonsoon
$ pip install physalia

Note: its important to first install the forked PyMonsoon library, pip install git+https://github.com/luiscruz/PyMonsoon, before running pip install physalia. If we just run pip install physalia pip will use the "official" monsoon library.

  1. We make a small change to the Physalia source code so we can inspect the average current. Modify venv/lib/python3.8/site-packages/physalia/power_meters.py so it prints the average current, see here

  2. Create a test script test.py that profiles for 15 seconds like this. I have a Nexus 5X connected to the Monsoon.

  3. Running this script, sudo $(which python3) test.py, we get the following output:

avg currents 32625.98545513053
ener consum 488.7309844075435
duration 14.981789112091064
  1. Over the 15 second run we have an average current of 32625 mA. This is not realistic. When using the Monsoon on Windows with the PowerTool GUI I get an average current of 200-600 mA depending on the activity using the same device.

We can fix this issue by replacing the forked PyMonsoon library with its original version.

  1. Remove the forked PyMonsoon library from our virtualenv pip uninstall monsoon and then install the original PyMonsoon library pip install monsoon.
  2. Since the official PyMonsoon library returns all channels when the getSamples() method is called (even when no measurements are stored for that channel) while the fork does not do this we need to make a very small modification. Modify venv/lib/python3.8/site-packages/Monsoon/sampleEngine.py and replace result = self.__arrangeSamples(True) with result = self.__arrangeSamples() as shown here: https://gist.github.com/odmnk/3c5051efcdbc06fcf33aabbb13ceb15e#file-sampleengine-py-L444
  3. Running this script again, sudo $(which python3) test.py, we get the following output:
avg currents 130.24532814904214
ener consum 1.94886781040676
duration 15.008735418319702

We can clearly see a huge difference, 130 mA versus 32625 mA.

While this initially solves the issue I now sometimes, but quite frequently, have the problem that the PyMonsoon's getSamples() method returned nr of currents does not match nr of timestamps. This then gives an error in Physalia when calculating the consumed energy:

packages/physalia/power_meters.py", line 187, in stop
      energy_consumption = sum(np.array(currents[:-1])*np.array(time_deltas))/1000
ValueError: operands could not be broadcast together with shapes (51442,) (51570,)

I have reported that issue here: msoon/PyMonsoon#35

Platform
I experience this issue on both a x64_86 based machine as well as on a ARM (RPi 4B) based machine.

I'm going to do some more debugging but I just wanted to share this here.

@LY-ai
Copy link

LY-ai commented Oct 20, 2022

Hmm, no luck yet. I created a document describing how to reproduce the issue. I want to share it here before I forget :p. Maybe other people are interested as well.

  1. Create a new directory, create a Python 3 virtualenv and install Physalia as described in the README.md:
$ mkdir monsoon_test; cd monsoon_test
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install git+https://github.com/luiscruz/PyMonsoon
$ pip install physalia

Note: its important to first install the forked PyMonsoon library, pip install git+https://github.com/luiscruz/PyMonsoon, before running pip install physalia. If we just run pip install physalia pip will use the "official" monsoon library.

  1. We make a small change to the Physalia source code so we can inspect the average current. Modify venv/lib/python3.8/site-packages/physalia/power_meters.py so it prints the average current, see here
  2. Create a test script test.py that profiles for 15 seconds like this. I have a Nexus 5X connected to the Monsoon.
  3. Running this script, sudo $(which python3) test.py, we get the following output:
avg currents 32625.98545513053
ener consum 488.7309844075435
duration 14.981789112091064
  1. Over the 15 second run we have an average current of 32625 mA. This is not realistic. When using the Monsoon on Windows with the PowerTool GUI I get an average current of 200-600 mA depending on the activity using the same device.

We can fix this issue by replacing the forked PyMonsoon library with its original version.

  1. Remove the forked PyMonsoon library from our virtualenv pip uninstall monsoon and then install the original PyMonsoon library pip install monsoon.
  2. Since the official PyMonsoon library returns all channels when the getSamples() method is called (even when no measurements are stored for that channel) while the fork does not do this we need to make a very small modification. Modify venv/lib/python3.8/site-packages/Monsoon/sampleEngine.py and replace result = self.__arrangeSamples(True) with result = self.__arrangeSamples() as shown here: https://gist.github.com/odmnk/3c5051efcdbc06fcf33aabbb13ceb15e#file-sampleengine-py-L444
  3. Running this script again, sudo $(which python3) test.py, we get the following output:
avg currents 130.24532814904214
ener consum 1.94886781040676
duration 15.008735418319702

We can clearly see a huge difference, 130 mA versus 32625 mA.

While this initially solves the issue I now sometimes, but quite frequently, have the problem that the PyMonsoon's getSamples() method returned nr of currents does not match nr of timestamps. This then gives an error in Physalia when calculating the consumed energy:

packages/physalia/power_meters.py", line 187, in stop
      energy_consumption = sum(np.array(currents[:-1])*np.array(time_deltas))/1000
ValueError: operands could not be broadcast together with shapes (51442,) (51570,)

I have reported that issue here: msoon/PyMonsoon#35

Platform I experience this issue on both a x64_86 based machine as well as on a ARM (RPi 4B) based machine.

I'm going to do some more debugging but I just wanted to share this here.

Hello! Is there any duplicate time stamp in the measurement data you get? Can you tell me the solution? The measured data are as follows [0.09065890312194824, 0.09065890312194824, 0.09197115898132324, 0.09197115898132324, 0.09197115898132324, 0.09197115898132324, 0.0930185317993164, 0.0930185317993164, 0.0930185317993164, 0.0930185317993164, 0.0930185317993164, 0.0930185317993164, 0.0930185317993164, 0.0930185317993164]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants